Skip to content

Commit 2e2d68c

Browse files
committed
Generate a cmake config file during install
1 parent c69d058 commit 2e2d68c

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

CMakeLists.txt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,10 @@ if (ENABLE_HIP)
6767
endif()
6868

6969
add_library(nomp SHARED ${SOURCES})
70-
set_target_properties(nomp PROPERTIES
71-
VERSION ${PROJECT_VERSION}
72-
SOVERSION 1
73-
PUBLIC_HEADER include/nomp.h)
74-
target_include_directories(nomp PRIVATE include ${CMAKE_BINARY_DIR}/include)
70+
set_target_properties(nomp PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION 1)
71+
target_include_directories(nomp
72+
PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>
73+
PRIVATE ${PROJECT_SOURCE_DIR}/include ${CMAKE_BINARY_DIR}/include)
7574
target_compile_options(nomp PRIVATE $<$<C_COMPILER_ID:MSVC>:/W4 /WX>
7675
$<$<NOT:$<C_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic>)
7776

@@ -174,9 +173,19 @@ if (FLAKE8)
174173
COMMENT "Running flake8 ...")
175174
endif()
176175

177-
install(TARGETS nomp LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
176+
install(TARGETS nomp EXPORT nomp-targets
177+
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
178178
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
179179

180+
install(EXPORT nomp-targets FILE nomp-targets.cmake NAMESPACE nomp::
181+
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/nomp)
182+
include(CMakePackageConfigHelpers)
183+
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nomp-config.cmake.in
184+
${CMAKE_CURRENT_BINARY_DIR}/nomp-config.cmake
185+
INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/nomp)
186+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/nomp-config.cmake
187+
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/nomp)
188+
180189
install(DIRECTORY ${CMAKE_SOURCE_DIR}/python DESTINATION ${CMAKE_INSTALL_PREFIX})
181190

182191
install(DIRECTORY scripts/ DESTINATION ${CMAKE_INSTALL_PREFIX}/bin

cmake/nomp-config.cmake.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@PACKAGE_INIT@
2+
3+
include(CMakeFindDependencyMacro)
4+
5+
include("${CMAKE_CURRENT_LIST_DIR}/nomp-targets.cmake")

tests/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ foreach(test_src ${TESTS})
1212
target_compile_options(${test_exe} PRIVATE -fsanitize=address)
1313
target_link_options(${test_exe} PRIVATE -fsanitize=address)
1414
endif()
15-
install (TARGETS ${test_exe} RUNTIME DESTINATION
16-
${CMAKE_INSTALL_PREFIX}/tests)
15+
install(TARGETS ${test_exe} RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/tests)
1716
endforeach()
1817

1918
install(DIRECTORY ${CMAKE_SOURCE_DIR}/tests/ DESTINATION

0 commit comments

Comments
 (0)