From e57f831ba59c75e87946bf2c8fbbef1134495707 Mon Sep 17 00:00:00 2001 From: Thilina Ratnayaka Date: Fri, 25 Oct 2024 15:32:58 -0500 Subject: [PATCH] Generate a cmake config file during install --- CMakeLists.txt | 16 ++++++++++++++-- cmake/nompConfig.cmake.in | 5 +++++ tests/CMakeLists.txt | 3 +-- 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 cmake/nompConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index bbcca086..055550e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,7 +71,9 @@ set_target_properties(nomp PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION 1 PUBLIC_HEADER include/nomp.h) -target_include_directories(nomp PRIVATE include ${CMAKE_BINARY_DIR}/include) +target_include_directories(nomp + PUBLIC $ + PRIVATE ${PROJECT_SOURCE_DIR}/include ${CMAKE_BINARY_DIR}/include) target_compile_options(nomp PRIVATE $<$:/W4 /WX> $<$>:-Wall -Wextra -Wpedantic>) @@ -174,9 +176,19 @@ if (FLAKE8) COMMENT "Running flake8 ...") endif() -install(TARGETS nomp LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib +install(TARGETS nomp EXPORT nompTargets + LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}/include) +install(EXPORT nompTargets FILE nompTargets.cmake NAMESPACE nomp:: + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/nomp) +include(CMakePackageConfigHelpers) +configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nompConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/nompConfig.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/nomp) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/nompConfig.cmake + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/nomp) + install(DIRECTORY ${CMAKE_SOURCE_DIR}/python DESTINATION ${CMAKE_INSTALL_PREFIX}) install(DIRECTORY scripts/ DESTINATION ${CMAKE_INSTALL_PREFIX}/bin diff --git a/cmake/nompConfig.cmake.in b/cmake/nompConfig.cmake.in new file mode 100644 index 00000000..a34f55fb --- /dev/null +++ b/cmake/nompConfig.cmake.in @@ -0,0 +1,5 @@ +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) + +include("${CMAKE_CURRENT_LIST_DIR}/nompTargets.cmake") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 001e27b3..5369d4a0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,8 +12,7 @@ foreach(test_src ${TESTS}) target_compile_options(${test_exe} PRIVATE -fsanitize=address) target_link_options(${test_exe} PRIVATE -fsanitize=address) endif() - install (TARGETS ${test_exe} RUNTIME DESTINATION - ${CMAKE_INSTALL_PREFIX}/tests) + install(TARGETS ${test_exe} RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/tests) endforeach() install(DIRECTORY ${CMAKE_SOURCE_DIR}/tests/ DESTINATION