Skip to content

Commit

Permalink
Generate a cmake config file during install
Browse files Browse the repository at this point in the history
  • Loading branch information
thilinarmtb committed Oct 25, 2024
1 parent c69d058 commit 971446f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
16 changes: 14 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include>
PRIVATE ${PROJECT_SOURCE_DIR}/include ${CMAKE_BINARY_DIR}/include)
target_compile_options(nomp PRIVATE $<$<C_COMPILER_ID:MSVC>:/W4 /WX>
$<$<NOT:$<C_COMPILER_ID:MSVC>>:-Wall -Wextra -Wpedantic>)

Expand Down Expand Up @@ -174,9 +176,19 @@ if (FLAKE8)
COMMENT "Running flake8 ...")
endif()

install(TARGETS nomp LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
install(TARGETS nomp EXPORT nomp-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}/include)

install(EXPORT nomp-targets FILE nomp-targets.cmake NAMESPACE nomp::
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/nomp)
include(CMakePackageConfigHelpers)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/nomp-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/nomp-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/nomp)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/nomp-config.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
Expand Down
5 changes: 5 additions & 0 deletions cmake/nomp-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@PACKAGE_INIT@

include(CMakeFindDependencyMacro)

include("${CMAKE_CURRENT_LIST_DIR}/nompTargets.cmake")
3 changes: 1 addition & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 971446f

Please sign in to comment.