Skip to content

Commit 95f2740

Browse files
committed
create and install cmake config package files
1 parent 5cc6d61 commit 95f2740

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

CMakeLists.txt

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,27 @@ cmake_minimum_required(VERSION 3.13.0)
22

33
project(meshFields VERSION 0.1.0 LANGUAGES CXX)
44

5+
include(GNUInstallDirs)
6+
include(CMakePackageConfigHelpers)
7+
58
find_package(Omega_h REQUIRED)
69
#Clear the omegah compilation flags that it passes to cuda. Using the
710
# kokkos target, and nvcc_wrapper, provide sufficient flags.
811
set_property(TARGET Omega_h::omega_h PROPERTY INTERFACE_COMPILE_OPTIONS "")
912

1013
find_package(Cabana REQUIRED)
1114

15+
set(MESHFIELD_HEADERS src/SliceWrapper.hpp src/MeshField.hpp)
16+
1217
#create header only library
1318
add_library(meshFields INTERFACE)
14-
target_include_directories(meshFields INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src)
19+
target_include_directories(meshFields
20+
INTERFACE
21+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
22+
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
1523
target_link_libraries(meshFields INTERFACE Omega_h::omega_h)
1624
target_link_libraries(meshFields INTERFACE Cabana::cabanacore)
17-
target_compile_definitions(meshFields INTERFACE ENABLE_CABANA) #SHOULD THIS BE PUBLIC?
25+
target_compile_definitions(meshFields INTERFACE ENABLE_CABANA)
1826

1927
#Settings options for testing
2028
enable_testing()
@@ -28,10 +36,37 @@ add_executable(SliceWrapper test/SliceWrapper.cpp)
2836
target_link_libraries(SliceWrapper PRIVATE meshFields)
2937

3038
add_executable(MeshField test/MeshField.cpp)
31-
target_include_directories(MeshField PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src) #hack - this should be a header-only library
32-
target_link_libraries(MeshField Omega_h::omega_h)
33-
target_link_libraries(MeshField Cabana::cabanacore)
34-
target_compile_definitions(MeshField PUBLIC ENABLE_CABANA)
39+
target_link_libraries(MeshField meshFields)
3540

3641
add_test(sliceWrapper50 ./SliceWrapper 50)
3742
add_test(meshField ./MeshField)
43+
44+
## export the library
45+
set_target_properties(meshFields PROPERTIES PUBLIC_HEADER "${MESHFIELD_HEADERS}")
46+
install(
47+
TARGETS meshFields
48+
EXPORT meshFields-targets
49+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
50+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
51+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
52+
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
53+
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
54+
55+
configure_package_config_file(
56+
"${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.in"
57+
"${CMAKE_CURRENT_BINARY_DIR}/meshFields-config.cmake"
58+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/meshFields
59+
)
60+
write_basic_package_version_file(
61+
"${PROJECT_BINARY_DIR}/meshFields-config-version.cmake"
62+
COMPATIBILITY AnyNewerVersion)
63+
64+
install(FILES
65+
"${PROJECT_BINARY_DIR}/meshFields-config.cmake"
66+
"${PROJECT_BINARY_DIR}/meshFields-config-version.cmake"
67+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/meshFields)
68+
69+
install(
70+
EXPORT meshFields-targets
71+
NAMESPACE meshFields::
72+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/meshFields)

config.cmake.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@PACKAGE_INIT@
2+
3+
include("${CMAKE_CURRENT_LIST_DIR}/meshFields-targets.cmake")
4+
5+
check_required_components(meshFields)
6+
7+
include(CMakeFindDependencyMacro)
8+
9+
find_dependency(Omega_h)
10+
find_dependency(Cabana)
11+

0 commit comments

Comments
 (0)