From 0274d40018ec68b916f603c04b6ca0d94ebc1b90 Mon Sep 17 00:00:00 2001 From: Alexander Vieth Date: Wed, 28 Aug 2024 16:05:37 +0200 Subject: [PATCH] Add disable install option (#41) * CMake: Add disable install option * CMake: rename options, add prefix * CMake: OS independent flann linking --- CMakeLists.txt | 31 +++-- conanfile.py | 5 +- hdi/data/CMakeLists.txt | 38 +++--- hdi/dimensionality_reduction/CMakeLists.txt | 144 ++++++++++---------- hdi/utils/CMakeLists.txt | 65 ++++----- 5 files changed, 149 insertions(+), 134 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a632ff20..6e86fc69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,21 +6,22 @@ PROJECT(${PROJECT}) # ----------------------------------------------------------------------------- # User Options # ----------------------------------------------------------------------------- -option(ENABLE_AVX "Enable AVX support" OFF) -option(ENABLE_CODE_ANALYSIS "Use Static Code Analysis on build with MSVC" OFF) -option(ENABLE_PID "Set POSITION_INDEPENDENT_CODE property for all targets" OFF) -set(OPTIMIZATION_LEVEL "2" CACHE STRING "Optimization level for all targets in release builds, e.g. 0, 1, 2") +option(HDILib_ENABLE_AVX "Enable AVX support" OFF) +option(HDILib_ENABLE_CODE_ANALYSIS "Use Static Code Analysis on build with MSVC" OFF) +option(HDILib_ENABLE_PID "Set POSITION_INDEPENDENT_CODE property for all targets" OFF) +option(HDILib_INSTALL "Enable installation of the HDILib" ON) +set(HDILib_OPTIMIZATION_LEVEL "2" CACHE STRING "Optimization level for all targets in release builds, e.g. 0, 1, 2") set(HDILib_VERSION "undefined" CACHE STRING "HDILib Library version") -if (ENABLE_AVX) +if (HDILib_ENABLE_AVX) message("ENABLE_AVX is ON") endif() -if (ENABLE_CODE_ANALYSIS AND WIN32) +if (HDILib_ENABLE_CODE_ANALYSIS AND WIN32) message("Code Analysis ENABLED") endif() -if (ENABLE_PID) +if (HDILib_ENABLE_PID) message(STATUS "Position independent code compilation ON") endif() @@ -121,9 +122,13 @@ configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/HDILibConfig.cmake.in ) # install the package files files -install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/HDILibConfig.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/HDILibConfigVersion.cmake" - DESTINATION lib/cmake/HDILib - COMPONENT HDI_PACKAGE -) + +if(${HDILib_INSTALL}) + install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/HDILibConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/HDILibConfigVersion.cmake" + DESTINATION lib/cmake/HDILib + COMPONENT HDI_PACKAGE + ) +endif() + diff --git a/conanfile.py b/conanfile.py index dbe82b6b..c58d6c60 100644 --- a/conanfile.py +++ b/conanfile.py @@ -88,10 +88,11 @@ def generate(self): ) else: tc.variables["CMAKE_INSTALL_PREFIX"] = "${CMAKE_BINARY_DIR}" - tc.variables["ENABLE_CODE_ANALYSIS"] = "ON" tc.variables["CMAKE_VERBOSE_MAKEFILE"] = "ON" if os.getenv("Analysis", None) is None: - tc.variables["ENABLE_CODE_ANALYSIS"] = "OFF" + tc.variables["HDILib_ENABLE_CODE_ANALYSIS"] = "OFF" + else: + tc.variables["HDILib_ENABLE_CODE_ANALYSIS"] = "ON" tc.variables[ "CMAKE_MSVC_RUNTIME_LIBRARY" ] = "MultiThreaded$<$:Debug>DLL" diff --git a/hdi/data/CMakeLists.txt b/hdi/data/CMakeLists.txt index daa53d49..833776da 100644 --- a/hdi/data/CMakeLists.txt +++ b/hdi/data/CMakeLists.txt @@ -16,31 +16,33 @@ if(OpenMP_CXX_FOUND) target_link_libraries(${PROJECT} PRIVATE OpenMP::OpenMP_CXX) endif() -if(ENABLE_PID) +if(HDILib_ENABLE_PID) set_target_properties(${PROJECT} PROPERTIES POSITION_INDEPENDENT_CODE ON) endif() -if(ENABLE_CODE_ANALYSIS) +if(HDILib_ENABLE_CODE_ANALYSIS) if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") target_compile_options(${PROJECT} PRIVATE /analyze) endif() endif() -set_optimization_level(${PROJECT} ${OPTIMIZATION_LEVEL}) -check_and_set_AVX(${PROJECT} ${ENABLE_AVX}) +set_optimization_level(${PROJECT} ${HDILib_OPTIMIZATION_LEVEL}) +check_and_set_AVX(${PROJECT} ${HDILib_ENABLE_AVX}) ########### INSTALL ############## -install(TARGETS ${PROJECT} - EXPORT ${PROJECT}Targets - LIBRARY DESTINATION lib/$> - ARCHIVE DESTINATION lib/$ - PUBLIC_HEADER DESTINATION include/hdi/data - COMPONENT hdidata -) - -install(EXPORT ${PROJECT}Targets - FILE ${PROJECT}Targets.cmake - NAMESPACE HDI:: - DESTINATION lib/cmake/HDILib - COMPONENT HDIDATA_TARGET -) +if(${HDILib_INSTALL}) + install(TARGETS ${PROJECT} + EXPORT ${PROJECT}Targets + LIBRARY DESTINATION lib/$> + ARCHIVE DESTINATION lib/$ + PUBLIC_HEADER DESTINATION include/hdi/data + COMPONENT hdidata + ) + + install(EXPORT ${PROJECT}Targets + FILE ${PROJECT}Targets.cmake + NAMESPACE HDI:: + DESTINATION lib/cmake/HDILib + COMPONENT HDIDATA_TARGET + ) +endif() diff --git a/hdi/dimensionality_reduction/CMakeLists.txt b/hdi/dimensionality_reduction/CMakeLists.txt index 3dc4668d..d410ba0b 100644 --- a/hdi/dimensionality_reduction/CMakeLists.txt +++ b/hdi/dimensionality_reduction/CMakeLists.txt @@ -26,29 +26,33 @@ if(DEFINED ENV{CI}) target_include_directories(${PROJECT} PRIVATE ${flann_INCLUDE_DIR} ${lz4_INCLUDE_DIR}) else() message (STATUS "Flann path: " ${flann_DIR}) - if(WIN32) - target_link_libraries(${PROJECT} PRIVATE flann::flann_cpp_s) - else() - target_link_libraries(${PROJECT} PRIVATE flann::flann) + + if(TARGET flann::flann_cpp_s) + set(FLANN_TARGET flann::flann_cpp_s) + elseif(TARGET flann::flann) + set(FLANN_TARGET flann::flann) endif() + + message (STATUS "Flann link library: " ${FLANN_TARGET}) + target_link_libraries(${PROJECT} PRIVATE ${FLANN_TARGET}) endif() if(OpenMP_CXX_FOUND) target_link_libraries(${PROJECT} PRIVATE OpenMP::OpenMP_CXX) endif() -if(ENABLE_PID) +if(HDILib_ENABLE_PID) set_target_properties(${PROJECT} PROPERTIES POSITION_INDEPENDENT_CODE ON) endif() -if(ENABLE_CODE_ANALYSIS) +if(HDILib_ENABLE_CODE_ANALYSIS) if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") target_compile_options(${PROJECT} PRIVATE /analyze) endif() endif() -set_optimization_level(${PROJECT} ${OPTIMIZATION_LEVEL}) -check_and_set_AVX(${PROJECT} ${ENABLE_AVX}) +set_optimization_level(${PROJECT} ${HDILib_OPTIMIZATION_LEVEL}) +check_and_set_AVX(${PROJECT} ${HDILib_ENABLE_AVX}) if(UNIX) set(THREADS_PREFER_PTHREAD_FLAG ON) @@ -57,68 +61,68 @@ if(UNIX) endif(UNIX) ########### INSTALL ############## -#set_target_properties(${PROJECT} PROPERTIES PUBLIC_HEADER "${HeaderFiles}") - -install(TARGETS ${PROJECT} - EXPORT ${PROJECT}Targets - LIBRARY DESTINATION lib/$ - ARCHIVE DESTINATION lib/$ - COMPONENT hdidimensionalityreduction -) - -# Preserve the header hierarchy by explicit install -# the CMake PUBLIC_HEADER target property flattens it if used. -install(CODE "foreach(DR_HEADER ${HeaderFiles}) - message(STATUS \"Installing: \${DR_HEADER} to \${CMAKE_INSTALL_PREFIX}/include/hdi/dimensionality_reduction\") - execute_process( - COMMAND \"${CMAKE_COMMAND}\" -E copy_if_different - \"${CMAKE_CURRENT_SOURCE_DIR}/\${DR_HEADER}\" - \"${CMAKE_INSTALL_PREFIX}/include/hdi/dimensionality_reduction/\${DR_HEADER}\" - ) - - endforeach()" - COMPONENT PUBLIC_HEADERS -) - -# Install dependency headers -if(NOT DEFINED ENV{CI}) - if(DEFINED flann_INCLUDE_DIR) - install(DIRECTORY "${flann_INCLUDE_DIR}/" DESTINATION "${CMAKE_INSTALL_PREFIX}/include" COMPONENT FLANN_HEADERS) +if(${HDILib_INSTALL}) + install(TARGETS ${PROJECT} + EXPORT ${PROJECT}Targets + LIBRARY DESTINATION lib/$ + ARCHIVE DESTINATION lib/$ + COMPONENT hdidimensionalityreduction + ) + + # Preserve the header hierarchy by explicit install + # the CMake PUBLIC_HEADER target property flattens it if used. + install(CODE "foreach(DR_HEADER ${HeaderFiles}) + message(STATUS \"Installing: \${DR_HEADER} to \${CMAKE_INSTALL_PREFIX}/include/hdi/dimensionality_reduction\") + execute_process( + COMMAND \"${CMAKE_COMMAND}\" -E copy_if_different + \"${CMAKE_CURRENT_SOURCE_DIR}/\${DR_HEADER}\" + \"${CMAKE_INSTALL_PREFIX}/include/hdi/dimensionality_reduction/\${DR_HEADER}\" + ) + + endforeach()" + COMPONENT PUBLIC_HEADERS + ) + + # Install dependency headers + if(NOT DEFINED ENV{CI}) + if(DEFINED flann_INCLUDE_DIR) + install(DIRECTORY "${flann_INCLUDE_DIR}/" DESTINATION "${CMAKE_INSTALL_PREFIX}/include" COMPONENT FLANN_HEADERS) + endif() + + if(DEFINED lz4_INCLUDE_DIR) + install(DIRECTORY "${lz4_INCLUDE_DIR}/" DESTINATION "${CMAKE_INSTALL_PREFIX}/include" COMPONENT LZ4_HEADERS) + endif() + + if(DEFINED VCPKG_INSTALLED_DIR) + install(DIRECTORY "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include/flann/" DESTINATION "${CMAKE_INSTALL_PREFIX}/include/flann/" COMPONENT FLANN_HEADERS) + install(CODE "foreach(LZ4_HEADER lz4.h lz4file.h lz4frame.h lz4frame_static.h lz4hc.h) + execute_process( + COMMAND \"${CMAKE_COMMAND}\" -E copy_if_different + \"${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include/\${LZ4_HEADER}\" + \"${CMAKE_INSTALL_PREFIX}/include/\${LZ4_HEADER}\" + ) + endforeach()" + COMPONENT ANNOY_HEADERS + ) + endif() endif() - if(DEFINED lz4_INCLUDE_DIR) - install(DIRECTORY "${lz4_INCLUDE_DIR}/" DESTINATION "${CMAKE_INSTALL_PREFIX}/include" COMPONENT LZ4_HEADERS) - endif() - - if(DEFINED VCPKG_INSTALLED_DIR) - install(DIRECTORY "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include/flann/" DESTINATION "${CMAKE_INSTALL_PREFIX}/include/flann/" COMPONENT FLANN_HEADERS) - install(CODE "foreach(LZ4_HEADER lz4.h lz4file.h lz4frame.h lz4frame_static.h lz4hc.h) - execute_process( - COMMAND \"${CMAKE_COMMAND}\" -E copy_if_different - \"${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include/\${LZ4_HEADER}\" - \"${CMAKE_INSTALL_PREFIX}/include/\${LZ4_HEADER}\" - ) - endforeach()" - COMPONENT ANNOY_HEADERS - ) - endif() + install(DIRECTORY "${HNSWLIB_INCLUDE_DIR}/hnswlib/" DESTINATION "${CMAKE_INSTALL_PREFIX}/include/hnswlib" COMPONENT HNSW_HEADERS) + install(CODE "foreach(ANNOY_HEADER annoylib.h kissrandom.h mman.h) + execute_process( + COMMAND \"${CMAKE_COMMAND}\" -E copy_if_different + \"${ANNOY_INCLUDE_DIR}/\${ANNOY_HEADER}\" + \"${CMAKE_INSTALL_PREFIX}/include/\${ANNOY_HEADER}\" + ) + endforeach()" + COMPONENT ANNOY_HEADERS + ) + + # Install cmake targets file + install(EXPORT ${PROJECT}Targets + FILE ${PROJECT}Targets.cmake + NAMESPACE HDI:: + DESTINATION lib/cmake/HDILib + COMPONENT HDIDIMENSIONALITYREDUCTION_TARGET + ) endif() - -install(DIRECTORY "${HNSWLIB_INCLUDE_DIR}/hnswlib/" DESTINATION "${CMAKE_INSTALL_PREFIX}/include/hnswlib" COMPONENT HNSW_HEADERS) -install(CODE "foreach(ANNOY_HEADER annoylib.h kissrandom.h mman.h) - execute_process( - COMMAND \"${CMAKE_COMMAND}\" -E copy_if_different - \"${ANNOY_INCLUDE_DIR}/\${ANNOY_HEADER}\" - \"${CMAKE_INSTALL_PREFIX}/include/\${ANNOY_HEADER}\" - ) - endforeach()" - COMPONENT ANNOY_HEADERS -) - -# Install cmake targets file -install(EXPORT ${PROJECT}Targets - FILE ${PROJECT}Targets.cmake - NAMESPACE HDI:: - DESTINATION lib/cmake/HDILib - COMPONENT HDIDIMENSIONALITYREDUCTION_TARGET -) diff --git a/hdi/utils/CMakeLists.txt b/hdi/utils/CMakeLists.txt index 1c5b6227..baf17bdf 100644 --- a/hdi/utils/CMakeLists.txt +++ b/hdi/utils/CMakeLists.txt @@ -14,48 +14,51 @@ if(OpenMP_CXX_FOUND) target_link_libraries(${PROJECT} PRIVATE OpenMP::OpenMP_CXX) endif() -if(ENABLE_PID) +if(HDILib_ENABLE_PID) set_target_properties(${PROJECT} PROPERTIES POSITION_INDEPENDENT_CODE ON) endif() -if(ENABLE_CODE_ANALYSIS) +if(HDILib_ENABLE_CODE_ANALYSIS) if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") target_compile_options(${PROJECT} PRIVATE /analyze) endif() endif() -set_optimization_level(${PROJECT} ${OPTIMIZATION_LEVEL}) -check_and_set_AVX(${PROJECT} ${ENABLE_AVX}) +set_optimization_level(${PROJECT} ${HDILib_OPTIMIZATION_LEVEL}) +check_and_set_AVX(${PROJECT} ${HDILib_ENABLE_AVX}) if (UNIX) target_link_libraries (hdiutils PRIVATE ${CMAKE_DL_LIBS}) # glad.cpp requires -ldl endif (UNIX) ########### INSTALL ############## -install(TARGETS ${PROJECT} - EXPORT ${PROJECT}Targets - LIBRARY DESTINATION lib/$ - ARCHIVE DESTINATION lib/$ - COMPONENT hdiutils -) - -# Preserve the header hierarchy by explicit install -# the CMake PUBLIC_HEADER target property flattens it if used. -install(CODE "foreach(HEADER ${HeaderFiles}) - message(STATUS \"Installing: \${HEADER} to \${CMAKE_INSTALL_PREFIX}/include/hdi/utils\") - execute_process( - COMMAND \"${CMAKE_COMMAND}\" -E copy_if_different - \"${CMAKE_CURRENT_SOURCE_DIR}/\${HEADER}\" - \"${CMAKE_INSTALL_PREFIX}/include/hdi/utils/\${HEADER}\" - ) - - endforeach()" - COMPONENT PUBLIC_HEADERS -) - -install(EXPORT ${PROJECT}Targets - FILE ${PROJECT}Targets.cmake - NAMESPACE HDI:: - DESTINATION lib/cmake/HDILib - COMPONENT HDIUTILS_TARGET -) +if(${HDILib_INSTALL}) + install(TARGETS ${PROJECT} + EXPORT ${PROJECT}Targets + LIBRARY DESTINATION lib/$ + ARCHIVE DESTINATION lib/$ + COMPONENT hdiutils + ) + + # Preserve the header hierarchy by explicit install + # the CMake PUBLIC_HEADER target property flattens it if used. + install(CODE "foreach(HEADER ${HeaderFiles}) + message(STATUS \"Installing: \${HEADER} to \${CMAKE_INSTALL_PREFIX}/include/hdi/utils\") + execute_process( + COMMAND \"${CMAKE_COMMAND}\" -E copy_if_different + \"${CMAKE_CURRENT_SOURCE_DIR}/\${HEADER}\" + \"${CMAKE_INSTALL_PREFIX}/include/hdi/utils/\${HEADER}\" + ) + + endforeach()" + COMPONENT PUBLIC_HEADERS + ) + + install(EXPORT ${PROJECT}Targets + FILE ${PROJECT}Targets.cmake + NAMESPACE HDI:: + DESTINATION lib/cmake/HDILib + COMPONENT HDIUTILS_TARGET + ) +endif() +