diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b8b6b0..6c89c9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,8 @@ find_package(FontConfig QUIET) find_package(FreeImage QUIET) find_package(Freetype REQUIRED) find_package(Sphinx QUIET) +find_package(glad CONFIG QUIET) +find_package(glm CONFIG QUIET) if(UNIX) dependency_check(FontConfig_FOUND @@ -59,28 +61,44 @@ fg_deprecate(WITH_FREEIMAGE FG_WITH_FREEIMAGE) fg_deprecate(USE_STATIC_FREEIMAGE FG_USE_STATIC_FREEIMAGE) fg_deprecate(WITH_TOOLKIT FG_USE_WINDOW_TOOLKIT) -message(STATUS "FreeImage Support turned ON") - if(Boost_FOUND AND NOT TARGET Boost::boost) add_library(Boost::boost INTERFACE IMPORTED) set_property(TARGET Boost::boost PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIRS}) endif(Boost_FOUND AND NOT TARGET Boost::boost) -FetchContent_Declare( - ${glad_prefix} - GIT_REPOSITORY https://github.com/arrayfire/glad.git - GIT_TAG obj_lib -) -FetchContent_Populate(${glad_prefix}) -FetchContent_Declare( - ${glm_prefix} - GIT_REPOSITORY https://github.com/g-truc/glm.git - GIT_TAG 0.9.9.8 -) -FetchContent_Populate(${glm_prefix}) +if(NOT TARGET glad::glad) # find_package(glad) failed + FetchContent_Declare( + ${glad_prefix} + GIT_REPOSITORY https://github.com/arrayfire/glad.git + GIT_TAG obj_lib + ) + fg_check_and_populate(${glad_prefix}) + add_subdirectory(${${glad_prefix}_SOURCE_DIR} ${${glad_prefix}_BINARY_DIR}) + + add_library(forge_glad STATIC $) + target_link_libraries(forge_glad PUBLIC ${CMAKE_DL_LIBS}) + target_include_directories(forge_glad + PUBLIC + $> + ) +else() + add_library(forge_glad ALIAS glad::glad) +endif() + +if(NOT TARGET glm::glm AND NOT TARGET glm) # find_package(glm) failed + FetchContent_Declare( + ${glm_prefix} + GIT_REPOSITORY https://github.com/g-truc/glm.git + GIT_TAG 0.9.9.8 + ) + fg_check_and_populate(${glm_prefix}) + add_library(glm INTERFACE IMPORTED) + set_target_properties(glm PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${${glm_prefix}_SOURCE_DIR}" + ) +endif() -add_subdirectory(${${glad_prefix}_SOURCE_DIR} ${${glad_prefix}_BINARY_DIR}) add_subdirectory(src/backend/common) add_subdirectory(src/backend/glsl_shaders) add_subdirectory(src/api/c) @@ -175,6 +193,8 @@ mark_as_advanced( Z_VCPKG_PWSH_PATH Z_VCPKG_CL _VCPKG_INSTALLED_DIR + glm_DIR + glad_DIR ) include(ForgeCPackConfig) diff --git a/CMakeModules/ForgeConfigureDepsVars.cmake b/CMakeModules/ForgeConfigureDepsVars.cmake index 5e6ae17..4b64ebd 100644 --- a/CMakeModules/ForgeConfigureDepsVars.cmake +++ b/CMakeModules/ForgeConfigureDepsVars.cmake @@ -43,3 +43,10 @@ if(FG_BUILD_OFFLINE) set_fetchcontent_src_dir(assets_prefix "glad") set_fetchcontent_src_dir(testdata_prefix "glm") endif() + +macro(fg_check_and_populate prefix) + FetchContent_GetProperties(${prefix}) + if(NOT ${prefix}_POPULATED) + FetchContent_Populate(${prefix}) + endif() +endmacro() diff --git a/CMakeModules/ForgeInternalUtils.cmake b/CMakeModules/ForgeInternalUtils.cmake index 50897e4..595e1f0 100644 --- a/CMakeModules/ForgeInternalUtils.cmake +++ b/CMakeModules/ForgeInternalUtils.cmake @@ -91,10 +91,26 @@ function(fg_set_target_compilation_props target) target_include_directories(${target} SYSTEM PRIVATE - ${${glm_prefix}_SOURCE_DIR} $ - $ + $ ) + # As imported targets can't be aliased until CMake 3.11, below is a temporary + # work around until we move to a CMake version >= 3.11 + if(TARGET glm::glm) + target_include_directories(${target} + SYSTEM PRIVATE + $ + ) + elseif(TARGET glm) + target_include_directories(${target} + SYSTEM PRIVATE + $ + ) + else() + # Ideally it wouldn't reach here, just in case of corner case + # I couldn't think of or someother cmake bug + message(FATAL_ERROR "Please install glm dependency") + endif() target_include_directories(${target} PUBLIC $ diff --git a/src/backend/CMakeLists.txt b/src/backend/CMakeLists.txt index c639389..ed63af2 100644 --- a/src/backend/CMakeLists.txt +++ b/src/backend/CMakeLists.txt @@ -34,7 +34,6 @@ add_dependencies(${BkndTargetName} ${glsl_shader_targets}) target_sources(${BkndTargetName} PRIVATE - $ $ $ $ @@ -51,7 +50,7 @@ target_include_directories(${BkndTargetName} if(FG_WITH_FREEIMAGE) target_compile_definitions(${BkndTargetName} PRIVATE USE_FREEIMAGE) if(FG_USE_STATIC_FREEIMAGE) - target_link_libraries(${BkndTargetName} PRIVATE FreeImage::FreeImage_STATIC) + target_link_libraries(${BkndTargetName} PUBLIC FreeImage::FreeImage_STATIC) else() target_link_libraries(${BkndTargetName} PRIVATE FreeImage::FreeImage) endif() @@ -61,6 +60,7 @@ endif() target_link_libraries(${BkndTargetName} PRIVATE Boost::boost + forge_glad ${FREETYPE_LIBRARIES} ${CMAKE_DL_LIBS} ) diff --git a/vcpkg/vcpkg.json b/vcpkg/vcpkg.json index 664b771..e9322b6 100644 --- a/vcpkg/vcpkg.json +++ b/vcpkg/vcpkg.json @@ -1,6 +1,6 @@ { "name": "forge", - "version-string": "1.1.0", + "version": "1.1.0", "supports": "x64", "dependencies": [ "boost-functional", @@ -10,7 +10,9 @@ "name": "fontconfig", "platform": "!windows" }, + "glad", "glfw3", + "glm", "sdl2" ] }