Optimize cmake targets

This commit is contained in:
xiaozhuai 2023-12-22 20:01:49 +08:00 committed by Christophe
parent e4dd44d584
commit 46b796dd79
2 changed files with 75 additions and 59 deletions

View File

@ -16,30 +16,58 @@ set(GLM_VERSION ${GLM_VERSION_MAJOR}.${GLM_VERSION_MINOR}.${GLM_VERSION_PATCH}.$
project(glm VERSION ${GLM_VERSION} LANGUAGES CXX)
message(STATUS "GLM: Version " ${GLM_VERSION})
add_subdirectory(glm)
add_library(glm::glm ALIAS glm)
set(GLM_IS_MASTER_PROJECT OFF)
if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
set(GLM_IS_MASTER_PROJECT ON)
endif()
include(CPack)
install(DIRECTORY glm DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} PATTERN "CMakeLists.txt" EXCLUDE)
install(EXPORT glm FILE glmConfig.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/glm NAMESPACE glm::)
include(CMakePackageConfigHelpers)
write_basic_package_version_file("glmConfigVersion.cmake" COMPATIBILITY AnyNewerVersion)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/glmConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/glm)
option(GLM_BUILD_LIBRARY "Build dynamic/static library" ON)
option(GLM_BUILD_TESTS "Build the test programs" ${GLM_IS_MASTER_PROJECT})
option(GLM_BUILD_INSTALL "Generate the install target" ${GLM_IS_MASTER_PROJECT})
include(GNUInstallDirs)
add_subdirectory(glm)
if (GLM_BUILD_TESTS)
include(CTest)
if(BUILD_TESTING)
add_subdirectory(test)
endif()
endif(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
if (GLM_BUILD_INSTALL)
include(CPack)
if (NOT TARGET uninstall)
configure_file(cmake/cmake_uninstall.cmake.in
cmake_uninstall.cmake IMMEDIATE @ONLY)
install(TARGETS glm-header-only glm EXPORT glm)
install(
DIRECTORY glm
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
PATTERN "CMakeLists.txt" EXCLUDE
)
install(
EXPORT glm
NAMESPACE glm::
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/glm"
FILE glmConfig.cmake
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/glmConfigVersion.cmake"
COMPATIBILITY AnyNewerVersion
)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/glmConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/glm"
)
add_custom_target(uninstall
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY
)
add_custom_target(
uninstall
"${CMAKE_COMMAND}" -P
"${CMAKE_BINARY_DIR}/cmake_uninstall.cmake")
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
)
endif()

View File

@ -1,6 +1,3 @@
option(BUILD_SHARED_LIBS "Build shared library" ON)
option(BUILD_STATIC_LIBS "Build static library" ON)
file(GLOB ROOT_SOURCE *.cpp)
file(GLOB ROOT_INLINE *.inl)
file(GLOB ROOT_HEADER *.hpp)
@ -45,37 +42,28 @@ source_group("SIMD Files" FILES ${SIMD_SOURCE})
source_group("SIMD Files" FILES ${SIMD_INLINE})
source_group("SIMD Files" FILES ${SIMD_HEADER})
add_library(glm INTERFACE)
add_library(glm-header-only INTERFACE)
add_library(glm::glm-header-only ALIAS glm-header-only)
include(GNUInstallDirs)
target_include_directories(glm INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
target_include_directories(glm-header-only INTERFACE
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)
install(TARGETS glm EXPORT glm)
if(BUILD_STATIC_LIBS)
add_library(glm_static STATIC ${ROOT_TEXT} ${ROOT_MD} ${ROOT_NAT}
if (GLM_BUILD_LIBRARY)
add_library(glm
${ROOT_TEXT} ${ROOT_MD} ${ROOT_NAT}
${ROOT_SOURCE} ${ROOT_INLINE} ${ROOT_HEADER}
${CORE_SOURCE} ${CORE_INLINE} ${CORE_HEADER}
${EXT_SOURCE} ${EXT_INLINE} ${EXT_HEADER}
${GTC_SOURCE} ${GTC_INLINE} ${GTC_HEADER}
${GTX_SOURCE} ${GTX_INLINE} ${GTX_HEADER}
${SIMD_SOURCE} ${SIMD_INLINE} ${SIMD_HEADER})
target_link_libraries(glm_static PUBLIC glm)
add_library(glm::glm_static ALIAS glm_static)
endif()
if(BUILD_SHARED_LIBS)
add_library(glm_shared SHARED ${ROOT_TEXT} ${ROOT_MD} ${ROOT_NAT}
${ROOT_SOURCE} ${ROOT_INLINE} ${ROOT_HEADER}
${CORE_SOURCE} ${CORE_INLINE} ${CORE_HEADER}
${EXT_SOURCE} ${EXT_INLINE} ${EXT_HEADER}
${GTC_SOURCE} ${GTC_INLINE} ${GTC_HEADER}
${GTX_SOURCE} ${GTX_INLINE} ${GTX_HEADER}
${SIMD_SOURCE} ${SIMD_INLINE} ${SIMD_HEADER})
target_link_libraries(glm_shared PUBLIC glm)
add_library(glm::glm_shared ALIAS glm_shared)
${SIMD_SOURCE} ${SIMD_INLINE} ${SIMD_HEADER}
)
add_library(glm::glm ALIAS glm)
target_link_libraries(glm PUBLIC glm-header-only)
else()
add_library(glm INTERFACE)
add_library(glm::glm ALIAS glm)
target_link_libraries(glm INTERFACE glm-header-only)
endif()