Skip to content

Commit

Permalink
Add disable install option (#41)
Browse files Browse the repository at this point in the history
* CMake: Add disable install option

* CMake: rename options, add prefix

* CMake: OS independent flann linking
  • Loading branch information
alxvth authored Aug 28, 2024
1 parent 05a9182 commit 0274d40
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 134 deletions.
31 changes: 18 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()

5 changes: 3 additions & 2 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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$<$<CONFIG:Debug>:Debug>DLL"
Expand Down
38 changes: 20 additions & 18 deletions hdi/data/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/$<CONFIGURATION>>
ARCHIVE DESTINATION lib/$<CONFIGURATION>
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/$<CONFIGURATION>>
ARCHIVE DESTINATION lib/$<CONFIGURATION>
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()
144 changes: 74 additions & 70 deletions hdi/dimensionality_reduction/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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/$<CONFIGURATION>
ARCHIVE DESTINATION lib/$<CONFIGURATION>
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/$<CONFIGURATION>
ARCHIVE DESTINATION lib/$<CONFIGURATION>
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
)
65 changes: 34 additions & 31 deletions hdi/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/$<CONFIGURATION>
ARCHIVE DESTINATION lib/$<CONFIGURATION>
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/$<CONFIGURATION>
ARCHIVE DESTINATION lib/$<CONFIGURATION>
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()

0 comments on commit 0274d40

Please sign in to comment.