From c55d6639b2c98e37f15ede538351726cb24c165b Mon Sep 17 00:00:00 2001 From: Cary Phillips Date: Wed, 13 Mar 2024 16:50:58 -0700 Subject: [PATCH] Add IMATH_INSTALL cmake option This part of #366, backported for the 3.1 branch. Signed-off-by: Cary Phillips --- CMakeLists.txt | 1 + config/CMakeLists.txt | 52 ++++++++++++++++++++------------------ config/LibraryDefine.cmake | 46 ++++++++++++++++++--------------- 3 files changed, 54 insertions(+), 45 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9770a90e..4420a51f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,6 +51,7 @@ include(config/ImathSetup.cmake) message(STATUS "Configure ${IMATH_PACKAGE_NAME}, library API version: ${IMATH_LIB_VERSION}") +option(IMATH_INSTALL "Install Imath library" ON) # Config headers and package config files add_subdirectory(config) diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt index f6a70280..8c1c3604 100644 --- a/config/CMakeLists.txt +++ b/config/CMakeLists.txt @@ -19,14 +19,16 @@ target_include_directories(ImathConfig INTERFACE $ $) -install( - FILES - ${CMAKE_CURRENT_BINARY_DIR}/ImathConfig.h - DESTINATION - ${CMAKE_INSTALL_INCLUDEDIR}/${IMATH_OUTPUT_SUBDIR} -) - -install(TARGETS ImathConfig EXPORT ${PROJECT_NAME}) +if (IMATH_INSTALL) + install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/ImathConfig.h + DESTINATION + ${CMAKE_INSTALL_INCLUDEDIR}/${IMATH_OUTPUT_SUBDIR} + ) + + install(TARGETS ImathConfig EXPORT ${PROJECT_NAME}) +endif() add_library(Imath::Config ALIAS ImathConfig) @@ -80,19 +82,21 @@ write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Con COMPATIBILITY SameMajorVersion ) -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake - ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} -) - -install(EXPORT ${PROJECT_NAME} - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} - FILE ${PROJECT_NAME}Targets.cmake - NAMESPACE ${PROJECT_NAME}:: - EXPORT_LINK_INTERFACE_LIBRARIES -) - -export(EXPORT ${PROJECT_NAME} - FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake" - NAMESPACE ${PROJECT_NAME}:: -) +if (IMATH_INSTALL) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} + ) + + install(EXPORT ${PROJECT_NAME} + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} + FILE ${PROJECT_NAME}Targets.cmake + NAMESPACE ${PROJECT_NAME}:: + EXPORT_LINK_INTERFACE_LIBRARIES + ) + + export(EXPORT ${PROJECT_NAME} + FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake" + NAMESPACE ${PROJECT_NAME}:: + ) +endif() diff --git a/config/LibraryDefine.cmake b/config/LibraryDefine.cmake index 48689547..ff5c935c 100644 --- a/config/LibraryDefine.cmake +++ b/config/LibraryDefine.cmake @@ -84,27 +84,31 @@ function(IMATH_DEFINE_LIBRARY libname) ) add_library(${PROJECT_NAME}::${libname} ALIAS ${libname}) - install(TARGETS ${libname} - EXPORT ${PROJECT_NAME} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - PUBLIC_HEADER - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${IMATH_OUTPUT_SUBDIR} - ) - if(BUILD_SHARED_LIBS AND (NOT "${IMATH_LIB_SUFFIX}" STREQUAL "") AND IMATH_INSTALL_SYM_LINK) - string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) - set(verlibname ${CMAKE_SHARED_LIBRARY_PREFIX}${libname}${IMATH_LIB_SUFFIX}${CMAKE_${uppercase_CMAKE_BUILD_TYPE}_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}) - set(baselibname ${CMAKE_SHARED_LIBRARY_PREFIX}${libname}${CMAKE_${uppercase_CMAKE_BUILD_TYPE}_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}) - if(WIN32) - install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E chdir \"\$ENV\{DESTDIR\}${CMAKE_INSTALL_FULL_BINDIR}\" ${CMAKE_COMMAND} -E create_symlink ${verlibname} ${baselibname})") - install(CODE "message(STATUS \"Creating symlink ${CMAKE_INSTALL_FULL_BINDIR}/${baselibname} -> ${verlibname}\")") - else() - install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E chdir \"\$ENV\{DESTDIR\}${CMAKE_INSTALL_FULL_LIBDIR}\" ${CMAKE_COMMAND} -E create_symlink ${verlibname} ${baselibname})") - install(CODE "message(STATUS \"Creating symlink ${CMAKE_INSTALL_FULL_LIBDIR}/${baselibname} -> ${verlibname}\")") + if (IMATH_INSTALL) + + install(TARGETS ${libname} + EXPORT ${PROJECT_NAME} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + PUBLIC_HEADER + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${IMATH_OUTPUT_SUBDIR} + ) + if(BUILD_SHARED_LIBS AND (NOT "${IMATH_LIB_SUFFIX}" STREQUAL "") AND IMATH_INSTALL_SYM_LINK) + string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) + set(verlibname ${CMAKE_SHARED_LIBRARY_PREFIX}${libname}${IMATH_LIB_SUFFIX}${CMAKE_${uppercase_CMAKE_BUILD_TYPE}_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}) + set(baselibname ${CMAKE_SHARED_LIBRARY_PREFIX}${libname}${CMAKE_${uppercase_CMAKE_BUILD_TYPE}_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}) + if(WIN32) + install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E chdir \"\$ENV\{DESTDIR\}${CMAKE_INSTALL_FULL_BINDIR}\" ${CMAKE_COMMAND} -E create_symlink ${verlibname} ${baselibname})") + install(CODE "message(STATUS \"Creating symlink ${CMAKE_INSTALL_FULL_BINDIR}/${baselibname} -> ${verlibname}\")") + else() + install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E chdir \"\$ENV\{DESTDIR\}${CMAKE_INSTALL_FULL_LIBDIR}\" ${CMAKE_COMMAND} -E create_symlink ${verlibname} ${baselibname})") + install(CODE "message(STATUS \"Creating symlink ${CMAKE_INSTALL_FULL_LIBDIR}/${baselibname} -> ${verlibname}\")") + endif() + set(verlibname) + set(baselibname) endif() - set(verlibname) - set(baselibname) + endif() endfunction()