Skip to content

Commit fb90671

Browse files
authored
Merge pull request #8 from SCOREC/cws/cmakeConfig
CMake header only lib and package files
2 parents 638f93d + 7ee5d55 commit fb90671

File tree

2 files changed

+59
-8
lines changed

2 files changed

+59
-8
lines changed

CMakeLists.txt

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,71 @@ 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+
17+
#create header only library
18+
add_library(meshFields INTERFACE)
19+
target_include_directories(meshFields
20+
INTERFACE
21+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
22+
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
23+
target_link_libraries(meshFields INTERFACE Omega_h::omega_h)
24+
target_link_libraries(meshFields INTERFACE Cabana::cabanacore)
25+
target_compile_definitions(meshFields INTERFACE ENABLE_CABANA)
26+
1227
#Settings options for testing
1328
enable_testing()
1429
include(CTest)
1530

1631
option(IS_TESTING "Build for CTest" OFF)
1732
message(STATUS "IS_TESTING: ${IS_TESTING}")
1833

34+
#tests
1935
add_executable(SliceWrapper test/testSliceWrapper.cpp)
20-
target_include_directories(SliceWrapper PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src) #hack - this should be a header-only library
21-
target_link_libraries(SliceWrapper Omega_h::omega_h)
22-
target_link_libraries(SliceWrapper Cabana::cabanacore)
23-
target_compile_definitions(SliceWrapper PUBLIC ENABLE_CABANA)
36+
target_link_libraries(SliceWrapper PRIVATE meshFields)
2437

2538
add_executable(MeshField test/testMeshField.cpp)
26-
target_include_directories(MeshField PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src) #hack - this should be a header-only library
27-
target_link_libraries(MeshField Omega_h::omega_h)
28-
target_link_libraries(MeshField Cabana::cabanacore)
29-
target_compile_definitions(MeshField PUBLIC ENABLE_CABANA)
39+
target_link_libraries(MeshField PRIVATE meshFields)
3040

3141
add_test(sliceWrapper50 ./SliceWrapper 50)
3242
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)