15
15
cmake_minimum_required (VERSION 3.14)
16
16
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /cmake" )
17
17
18
- option (SPINER_USE_HDF "Pull in hdf5" OFF )
18
+ option (SPINER_USE_HDF
19
+ "Pull in hdf5" OFF )
19
20
option (SPINER_USE_KOKKOS "Pull in Kokkos" OFF )
20
21
option (SPINER_USE_CUDA "Use the Kokkos cuda backend" OFF )
22
+ option (SPINER_FORCE_INTERNAL_PORTS "Force use of internal ports of call" OFF )
21
23
22
24
if (SPINER_USE_CUDA AND NOT SPINER_USE_KOKKOS)
23
25
message (FATAL_ERROR "Currently cuda requires Kokkos" )
@@ -26,7 +28,14 @@ endif()
26
28
set (CMAKE_CXX_STANDARD 11)
27
29
set (CMAKE_EXPORT_COMPILE_COMMANDS On )
28
30
29
- project (spiner VERSION 1.4.0)
31
+ set (SPINER_VERSION 1.4.0)
32
+ project (spiner VERSION ${SPINER_VERSION} )
33
+
34
+ # bring in some helpful CMake scripts
35
+ # make cache variables for install destinations
36
+ include (GNUInstallDirs)
37
+ # package config file
38
+ include (CMakePackageConfigHelpers)
30
39
31
40
# Don't allow in-source builds
32
41
file (TO_CMAKE_PATH "${PROJECT_BINARY_DIR} /CMakeLists.txt" LOC_PATH)
@@ -54,16 +63,9 @@ include(CTest)
54
63
include (cmake/Format.cmake)
55
64
56
65
# Add a library
57
- # mostly includes
58
- add_library (spiner::flags INTERFACE IMPORTED GLOBAL )
59
- # mostly just contains automated linker connections
60
- add_library (spiner::libs INTERFACE IMPORTED )
61
-
62
- # xl fix
63
- target_compile_options (spiner::flags INTERFACE
64
- $<$<COMPILE_LANG_AND_ID:CXX,XL>:-std=c++1y;-qxflag=disable__cplusplusOverride>)
65
- target_link_options (spiner::flags INTERFACE
66
- $<$<COMPILE_LANG_AND_ID:CXX,XL>:-std=c++1y;-qxflag=disable__cplusplusOverride>)
66
+ set (SPLIB "spiner" )
67
+ add_library (${SPLIB} INTERFACE )
68
+ add_library (${SPLIB} ::${SPLIB} ALIAS ${SPLIB} )
67
69
68
70
# HDF5
69
71
if (SPINER_USE_HDF)
@@ -72,22 +74,16 @@ if(SPINER_USE_HDF)
72
74
endif ()
73
75
find_package (HDF5 COMPONENTS C HL)
74
76
if (HDF5_FOUND)
75
- add_library (spiner::hdf5 INTERFACE IMPORTED GLOBAL )
76
- target_compile_definitions (spiner::flags
77
- INTERFACE
78
- SPINER_USE_HDF)
79
- set_target_properties (spiner::hdf5 PROPERTIES
80
- INTERFACE_LINK_LIBRARIES "${HDF5_LIBRARIES} ;${HDF5_HL_LIBRARIES} "
81
- INTERFACE_COMPILE_DEFINITIONS "SPINER_USE_HDF"
82
- INTERFACE_INCLUDE_DIRECTORIES "${HDF5_INCLUDE_DIRS} " )
77
+ target_compile_definitions (${SPLIB} INTERFACE SPINER_USE_HDF)
78
+ target_link_libraries (${SPLIB} INTERFACE ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES} )
79
+ target_include_directories (${SPLIB} INTERFACE ${HDF5_INCLUDE_DIRS} )
83
80
else ()
84
81
message (FATAL_ERROR "HDF5 was requested but not found. Can be disabled with -SPINER_USE_HDF=OFF" )
85
82
endif ()
86
- target_link_libraries (spiner::libs INTERFACE spiner::hdf5)
87
83
endif ()
88
84
89
85
if (SPINER_USE_KOKKOS)
90
- target_compile_definitions (spiner:: flags INTERFACE
86
+ target_compile_definitions (${SPLIB} INTERFACE
91
87
PORTABILITY_STRATEGY_KOKKOS)
92
88
# Import Kokkos if not already available as a build target
93
89
if (NOT TARGET Kokkos::kokkos)
@@ -102,38 +98,88 @@ if (SPINER_USE_KOKKOS)
102
98
endif ()
103
99
if (SPINER_USE_CUDA)
104
100
target_compile_options (
105
- spiner:: flags
101
+ ${SPLIB}
106
102
INTERFACE # Generator expression shamelessly copied from EAP
107
103
"$<$<COMPILE_LANGUAGE:CXX>:--expt-relaxed-constexpr;>"
108
104
)
109
105
endif ()
110
- target_link_libraries (spiner::libs INTERFACE Kokkos::kokkos)
106
+ target_link_libraries (${SPLIB} INTERFACE Kokkos::kokkos)
111
107
endif ()
112
108
113
109
# ports of call
114
110
# TODO: Integrate with find-package
115
111
if (NOT TARGET ports-of-call::ports-of-call)
116
- add_subdirectory (ports-of-call)
112
+ message (STATUS "Looking for ports-of-call" )
113
+ if (SPINER_FORCE_INTERNAL_PORTS)
114
+ message (STATUS "Using in-system ports-of-call" )
115
+ add_subdirectory (ports-of-call)
116
+ else ()
117
+ find_package (ports-of-call CONFIG)
118
+ if (NOT ports-of-call_FOUND)
119
+ message (STATUS "Ports of call not available in-system. Using submodule." )
120
+ add_subdirectory (ports-of-call)
121
+ else ()
122
+ message (STATUS "Ports of call is available. Using in-system installation." )
123
+ endif ()
124
+ endif ()
125
+ else ()
126
+ message (STATUS "Ports of call already in environment" )
117
127
endif ()
118
- target_link_libraries (spiner::flags INTERFACE ports-of-call::ports-of-call)
119
-
120
- # parent library
121
- # so the user can just import `spiner::spiner` rather than flags or libs.
122
- add_library (spiner::spiner INTERFACE IMPORTED GLOBAL )
123
- target_link_libraries (spiner::spiner INTERFACE spiner::flags spiner::libs)
128
+ target_link_libraries (${SPLIB} INTERFACE ports-of-call::ports-of-call)
124
129
125
130
# Enables
126
131
# #include <spiner>
127
- target_include_directories (spiner:: flags
132
+ target_include_directories (${SPLIB}
128
133
INTERFACE
129
134
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR} >)
130
135
131
- # Enables includes
136
+ # Coordinate external CMAKE export with targets
137
+ install (TARGETS ${SPLIB}
138
+ EXPORT ${SPLIB} Targets
139
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
140
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
141
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
142
+ INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
143
+ )
144
+
145
+ configure_package_config_file(${SPLIB} Config.cmake.in
146
+ ${CMAKE_CURRENT_BINARY_DIR} /${SPLIB} Config.cmake
147
+ INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/${SPLIB}
148
+ )
149
+
150
+ # ...and the version file
151
+ write_basic_package_version_file(
152
+ ${CMAKE_CURRENT_BINARY_DIR} /${SPLIB} ConfigVersion.cmake
153
+ VERSION ${SPINER_VERSION}
154
+ COMPATIBILITY SameMajorVersion )
155
+
156
+ # Install the cmake configuration files
157
+ install (FILES ${CMAKE_CURRENT_BINARY_DIR} /${SPLIB} Config.cmake
158
+ ${CMAKE_CURRENT_BINARY_DIR} /${SPLIB} ConfigVersion.cmake
159
+ DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/${SPLIB} )
160
+
161
+ # Install header files
132
162
install (DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR} /spiner"
133
- DESTINATION "include"
163
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
134
164
FILES_MATCHING PATTERN "*.hpp"
135
165
)
136
166
167
+ # Install the export target. This will define the CMake target
168
+ # for external projects when used with `find_package`
169
+ install (EXPORT ${SPLIB} Targets
170
+ NAMESPACE ${SPLIB} ::
171
+ FILE "${SPLIB} Targets.cmake"
172
+ DESTINATION "${CMAKE_INSTALL_LIBDIR} /cmake/${SPLIB} "
173
+ COMPONENT dev)
174
+
175
+ # Export configuration for external projects that reference
176
+ # just our build-tree; e.g. for submodules. To use, ensure
177
+ # `CMAKE_PREFIX_PATH` points to this source directory.
178
+ # NOTE: This config will not be relocatable!
179
+ export (TARGETS ${SPLIB} NAMESPACE ${SPLIB} ::
180
+ FILE "${CMAKE_CURRENT_BINARY_DIR} /${SPLIB} Targets.cmake" )
181
+ export (PACKAGE ${SPLIB} )
182
+
137
183
# Option imported from `CTest`
138
184
if (BUILD_TESTING)
139
185
message ("\n Configuring tests" )
0 commit comments