Debian Codegraph @

CMakeLists.txt

raw ◀ ▶
Source reconstructed at patch state 0 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 cmake_minimum_required(VERSION 3.21)
2 foreach(p
3 CMP0025 # CMake 3.0 Compiler id for Apple Clang is now ``AppleClang``.
4 CMP0042 # CMake 3.0 ``MACOSX_RPATH`` is enabled by default.
5 CMP0046 # CMake 3.0 Error on non-existent dependency in add_dependencies.
6 CMP0054 # CMake 3.1 Only interpret ``if()`` arguments as variables or keywords when unquoted.
7 CMP0056 # CMake 3.2 Honor link flags in ``try_compile()`` source-file signature.
8 CMP0058 # CMake 3.3 Ninja requires custom command byproducts to be explicit.
9 )
10 if(POLICY ${p})
11 cmake_policy(SET ${p} NEW)
12 endif()
13 endforeach()
14 project(ISMRMRD)
15
16 # set project specific cmake module path
17 set (ISMRMRD_CMAKE_DIR ${PROJECT_SOURCE_DIR}/cmake CACHE PATH
18 "Location of CMake scripts")
19
20 # command line options
21 option(USE_HDF5_DATASET_SUPPORT "Compile with support for reading and writing datasets to HDF5 files" ON)
22 option(BUILD_STATIC "Build static library" OFF)
23 option(BUILD_TESTS "Build unit tests " ON)
24 option(BUILD_UTILITIES "Build utilities tests " ON)
25 option(BUILD_EXAMPLES "Build examples tests " ON)
26 # If defined, this will modify the build environment to use General Electric's Libraries,
27 # which are needed to link against and use their SDK to open and process their raw data.
28 option(build4GE FALSE OFF)
29
30 # and include it to the search list
31 list(APPEND CMAKE_MODULE_PATH ${ISMRMRD_CMAKE_DIR})
32
33
34 # set the build type to Release if not specified
35 if(NOT CMAKE_BUILD_TYPE)
36 set(CMAKE_BUILD_TYPE Release CACHE STRING
37 "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
38 FORCE)
39 endif()
40
41 # compiler flags
42 if(NOT "${CMAKE_CXX_STANDARD}")
43 set(CMAKE_CXX_STANDARD 17)
44 message(STATUS "CMAKE_CXX_STANDARD not set, defaulting to ${CMAKE_CXX_STANDARD}")
45 else()
46 message(STATUS "CMAKE_CXX_STANDARD set externally to ${CMAKE_CXX_STANDARD}")
47 endif()
48
49 set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY true)
50
51 if (WIN32)
52 add_definitions(-DWIN32 -D_WIN32 -D_WINDOWS -DBOOST_UUID_FORCE_AUTO_LINK)
53 add_definitions(-DUNICODE -D_UNICODE)
54 add_definitions(-D_CRT_SECURE_NO_WARNINGS)
55 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
56
57 # https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
58 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus")
59
60 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /WX")
61 set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/debug /INCREMENTAL:NO")
62 set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "/debug /INCREMENTAL:NO")
63 set(CMAKE_STATIC_LINKER_FLAGS_DEBUG "/debug /INCREMENTAL:NO")
64 set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "/debug /INCREMENTAL:NO")
65 add_definitions(-D__func__=__FUNCTION__)
66 elseif (build4GE)
67 message (STATUS, " Setting up ISMRMRD build to use GE SDK HDF5 and Boost components for GE converter.")
68 if(DEFINED ENV{SDKTOP})
69 cmake_policy (SET CMP0074 OLD)
70 set(HDF5_ROOT "$ENV{SDKTOP}/3p")
71 set(BOOST_ROOT "$ENV{SDKTOP}/3p")
72 else ()
73 message (FATAL_ERROR, " SDKTOP not defined - cannot configure ISMRMRD build for GE properly.")
74 endif ()
75 set(Boost_USE_STATIC_LIBS "ON")
76 set(Boost_NO_SYSTEM_PATHS "TRUE")
77 set(HDF5_USE_STATIC_LIBRARIES "yes")
78 else ()
79 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -Werror")
80 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
81 endif ()
82
83 # --- VERSIONING (begin) ----
84 #The ISMRMRD convention is to use version numbers with the format:
85 # XX.YY.ZZ (major, minor, patch)
86 #
87 #The major number increments when the binary compatibility of
88 #the fixed memory layout struts (e.g. AcquisitionHeader) is broken.
89 #The minor number changes when there are changes to the XML schema for
90 #the flexible header. The micro number changes when there are small changes
91 #in the utility libraries, that don't affect the data format itself.
92 # For more information see http://semver.org/
93 set(ISMRMRD_VERSION_MAJOR 1)
94 set(ISMRMRD_VERSION_MINOR 15)
95 set(ISMRMRD_VERSION_PATCH 0)
96
97 set(ISMRMRD_VERSION_STRING ${ISMRMRD_VERSION_MAJOR}.${ISMRMRD_VERSION_MINOR}.${ISMRMRD_VERSION_PATCH})
98 set(ISMRMRD_SOVERSION ${ISMRMRD_VERSION_MAJOR}.${ISMRMRD_VERSION_MINOR})
99
100 if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.19)
101 file(READ ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg.json VCPKG_JSON)
102 string(JSON VCPKG_VERSION_STRING GET ${VCPKG_JSON} version)
103
104 if (NOT VCPKG_VERSION_STRING STREQUAL ISMRMRD_VERSION_STRING)
105 message("")
106 message("-----------------------------------------------")
107 message(" !! VCPKG VERSION ERROR!! ")
108 message(" Vcpkg version in vcpkg.json must match ISMRMRD")
109 message(" version in CMakeLists.txt ")
110 message("-----------------------------------------------")
111 message("")
112 message(FATAL_ERROR " FATAL VCPKG VERSION ERROR")
113 endif ()
114
115 endif()
116
117 set(ISMRMRD_XML_SCHEMA_SHA1 "40036f175a77542b50acbcfb0f019094c90b5e18")
118
119 #Remove line breaks and white space that does not change the meaning of the schema
120 file(STRINGS ${CMAKE_SOURCE_DIR}/schema/ismrmrd.xsd SCHEMA_STRINGS) #Read all strings from file
121 string(REPLACE ";" "" SCHEMA_NO_BREAKS ${SCHEMA_STRINGS}) #Concatenate the list of strings
122 string(REGEX REPLACE ">[ \t]+<" "><" SCHEMA_NO_SPACE ${SCHEMA_NO_BREAKS}) #Remove spaces and tabs
123 string(STRIP ${SCHEMA_NO_SPACE} SCHEMA_NO_SPACE) #Strip any leading/trailing whitespace
124 set(ISMRMRD_SCHEMA_DIR ${CMAKE_CURRENT_BINARY_DIR})
125 file(WRITE ${ISMRMRD_SCHEMA_DIR}/ismrmrd_no_white_space.xsd ${SCHEMA_NO_SPACE}) #Write to file
126
127 #Now hash the cleaned up file
128 file(SHA1 ${CMAKE_CURRENT_BINARY_DIR}/ismrmrd_no_white_space.xsd ISMRMRD_CURRENT_XML_SCHEMA_SHA1)
129
130 #Compare to last known hash
131 if (NOT (${ISMRMRD_XML_SCHEMA_SHA1} STREQUAL ${ISMRMRD_CURRENT_XML_SCHEMA_SHA1}))
132 message("")
133 message("-----------------------------------------------")
134 message(" !!VERSION ERROR!! ")
135 message(" ")
136 message(" Expected SHA1 hash: ")
137 message(" ${ISMRMRD_XML_SCHEMA_SHA1}")
138 message(" Actual SHA1 hash: ")
139 message(" ${ISMRMRD_CURRENT_XML_SCHEMA_SHA1}")
140 message(" ")
141 message(" The XML Schema (ismrmrmd.xsd) has changed and ")
142 message(" the MINOR version number should be increased ")
143 message(" and the SHA1 has should be updated in the ")
144 message(" CMakelists.txt file. ")
145 message(" ")
146 message(" If you don't know what this message means, you")
147 message(" probably shouldn't be changing anything ")
148 message("-----------------------------------------------")
149 message("")
150 message(FATAL_ERROR " FATAL XML VERSION ERROR")
151 endif()
152
153 # Find static libraries only if linking statically
154 if (BUILD_STATIC)
155 set(Boost_USE_STATIC_LIBS On)
156 set(HDF5_USE_STATIC_LIBRARIES TRUE)
157 set(FFTW_USE_STATIC_LIBS TRUE)
158 message(STATUS "Building ISMRMRD as static library")
159 else()
160 add_definitions(-DBOOST_TEST_DYN_LINK)
161 message(STATUS "Building ISMRMRD as shared library")
162 endif()
163
164 # Find Boost for tests and utilities
165 find_package(Boost CONFIG COMPONENTS filesystem random program_options unit_test_framework)
166 find_package(pugixml CONFIG REQUIRED)
167 find_package(FFTW COMPONENTS FLOAT_LIB)
168
169 # Find HDF5 for dataset support
170 if (USE_HDF5_DATASET_SUPPORT)
171 if (VCPKG_TARGET_TRIPLET) #VCPKG HDF5 is packaged differently.
172 find_package(HDF5 CONFIG COMPONENTS C REQUIRED)
173 if (BUILD_STATIC)
174 set(ISMRMRD_DATASET_LIBRARIES hdf5::hdf5-static)
175 else()
176 set(ISMRMRD_DATASET_LIBRARIES hdf5::hdf5-shared)
177 endif()
178 else ()
179 find_package(HDF5 COMPONENTS C REQUIRED)
180 set(ISMRMRD_DATASET_LIBRARIES HDF5::HDF5)
181 endif ()
182 set(ISMRMRD_DATASET_SUPPORT true)
183 set(ISMRMRD_DATASET_SOURCES libsrc/dataset.c libsrc/dataset.cpp)
184 message(STATUS "HDF5 include found at: ${HDF5_INCLUDE_DIRS}")
185 message(STATUS "HDF5 libs found at: ${HDF5_C_LIBRARIES}")
186 else ()
187 set(ISMRMRD_DATASET_SUPPORT false)
188 message(WARNING " Dataset and file support unavailable!")
189 endif ()
190
191 # Generate the version.h header file
192 find_package(Git)
193 if (GIT_FOUND)
194 execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD WORKING_DIRECTORY
195 ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE ISMRMRD_GIT_SHA1 ERROR_VARIABLE ISMRMRD_GIT_STDERR)
196 string(STRIP "${ISMRMRD_GIT_SHA1}" ISMRMRD_GIT_SHA1)
197 string(LENGTH "${ISMRMRD_GIT_SHA1}" ISMRMRD_GIT_SHA1_LEN)
198 if (${ISMRMRD_GIT_SHA1_LEN} LESS 40)
199 message(WARNING "Could not determine SHA-1 hash: ${ISMRMRD_GIT_STDERR}")
200 set(ISMRMRD_GIT_SHA1 "NA")
201 endif ()
202 else()
203 set(ISMRMRD_GIT_SHA1 "NA")
204 endif()
205 configure_file(include/version.in ${CMAKE_BINARY_DIR}/include/ismrmrd/version.h)
206 install(FILES ${CMAKE_BINARY_DIR}/include/ismrmrd/version.h DESTINATION include/ismrmrd COMPONENT Devel)
207 # note: for the utilities in this project that need ismrmrd/version.h
208 # remember to add ${CMAKE_BINARY_DIR}/include to the include path
209
210 # --- VERSIONING (end) ----
211
212 # --- Main Library (begin) ----
213
214 # include directories for main library
215 set(ISMRMRD_TARGET_INCLUDE_DIRS
216 $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
217 $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
218 $<INSTALL_INTERFACE:include>
219 ${ISMRMRD_DATASET_INCLUDE_DIR}
220 )
221
222 set(ISMRMRD_TARGET_SOURCES
223 libsrc/ismrmrd.c
224 libsrc/ismrmrd.cpp
225 libsrc/xml.cpp
226 libsrc/meta.cpp
227 libsrc/serialization.cpp
228 libsrc/waveform.cpp
229 libsrc/waveform.c
230 ${ISMRMRD_DATASET_SOURCES}
231 )
232
233 set(ISMRMRD_TARGET_LINK_LIBS ${ISMRMRD_DATASET_LIBRARIES})
234
235 if (build4GE)
236 list(APPEND ISMRMRD_TARGET_LINK_LIBS pthread z dl)
237 endif ()
238
239
240 # main library
241 if (BUILD_STATIC)
242 if (WIN32)
243 set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
244 endif()
245 set(ISMRMRD_PUGIXML_LIBRARIES pugixml::static)
246 add_library(ismrmrd STATIC ${ISMRMRD_TARGET_SOURCES})
247 else()
248 set(ISMRMRD_PUGIXML_LIBRARIES pugixml::shared)
249 add_library(ismrmrd SHARED ${ISMRMRD_TARGET_SOURCES})
250 endif()
251
252 list(APPEND ISMRMRD_TARGET_LINK_LIBS ${ISMRMRD_PUGIXML_LIBRARIES})
253
254 target_include_directories(ismrmrd PUBLIC ${ISMRMRD_TARGET_INCLUDE_DIRS})
255 if (USE_HDF5_DATASET_SUPPORT)
256 target_compile_options(ismrmrd PUBLIC ${HDF5_DEFINITIONS})
257 endif()
258
259 add_library(ismrmrd::ismrmrd ALIAS ismrmrd)
260
261 target_compile_definitions(
262 ismrmrd
263 PUBLIC $<$<CONFIG:Debug>:ISMRMRD_DEBUG>
264 INTERFACE $<$<NOT:$<BOOL:${BUILD_STATIC}>>:ISMRMRD_IMPORT>
265 PRIVATE $<$<CXX_COMPILER_ID:MSVC>:_CRT_SECURE_NO_WARNINGS>
266 )
267
268 set_target_properties(ismrmrd
269 PROPERTIES
270 DEFINE_SYMBOL ISMRMRD_EXPORT
271 EXPORT_NAME ISMRMRD
272 VERSION ${ISMRMRD_VERSION_STRING}
273 SOVERSION ${ISMRMRD_SOVERSION})
274
275 target_link_libraries(ismrmrd PUBLIC ${ISMRMRD_TARGET_LINK_LIBS})
276 list(APPEND ISMRMRD_LIBRARIES ismrmrd) # Add to list of libraries to be found
277 list(APPEND ISMRMRD_LIBRARY_DIRS ${CMAKE_BINARY_DIR} ) # Add to list of directories to find libraries
278
279 include(GNUInstallDirs)
280
281 # install the main library
282 install(TARGETS ismrmrd EXPORT ISMRMRDTargets
283 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
284 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
285 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
286 COMPONENT Devel
287 )
288
289 # install the headers
290 install(DIRECTORY include/ismrmrd DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT Devel)
291
292 # install the schema file
293 install(FILES schema/ismrmrd.xsd DESTINATION share/ismrmrd/schema COMPONENT Devel)
294
295 # --- Main Library (end) ----
296
297 # process subdirectories
298 add_subdirectory(doc)
299
300 if (BUILD_UTILITIES)
301 add_subdirectory(utilities)
302 endif()
303
304 if (HDF5_FOUND AND BUILD_EXAMPLES)
305 add_subdirectory(examples/c)
306 endif ()
307
308 # TODO: make this work on Windows
309 if (BUILD_TESTS)
310 if (NOT build4GE)
311 enable_testing()
312 add_subdirectory(tests)
313 endif ()
314 endif ()
315
316 # install the matlab api
317 install(DIRECTORY matlab DESTINATION share/ismrmrd )
318
319 #--- Create cmake package for downstream projects
320 #
321
322 include(CMakePackageConfigHelpers)
323 set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/ISMRMRD)
324
325 set(CONFIG_ISMRMRD_SCHEMA_DIR ${ISMRMRD_SCHEMA_DIR})
326 set(CONFIG_ISMRMRD_TARGET_INCLUDE_DIRS ${ISMRMRD_TARGET_INCLUDE_DIRS})
327 set(CONFIG_ISMRMRD_LIBRARY_DIRS ${ISMRMRD_LIBRARY_DIRS})
328 configure_file(cmake/ISMRMRDConfig.cmake.in
329 "${CMAKE_CURRENT_BINARY_DIR}/ISMRMRDConfig.cmake"
330 @ONLY
331 )
332
333 set(CONFIG_ISMRMRD_SCHEMA_DIR ${CMAKE_INSTALL_PREFIX}/share/ismrmrd/schema)
334 set(CONFIG_ISMRMRD_TARGET_INCLUDE_DIRS ${CMAKE_INSTALL_PREFIX}/include)
335 set(CONFIG_ISMRMRD_LIBRARY_DIRS ${CMAKE_INSTALL_PREFIX}/lib)
336 if (ISMRMRD_DATASET_SUPPORT)
337 list(APPEND CONFIG_ISMRMRD_TARGET_INCLUDE_DIRS ${HDF5_INCLUDE_DIRS})
338 endif ()
339
340 configure_package_config_file(cmake/ISMRMRDConfig.cmake.in
341 "${CMAKE_CURRENT_BINARY_DIR}/InstallFiles/ISMRMRDConfig.cmake"
342 INSTALL_DESTINATION ${INSTALL_CONFIGDIR})
343
344 write_basic_package_version_file(
345 "${CMAKE_CURRENT_BINARY_DIR}/ISMRMRDConfigVersion.cmake"
346 VERSION ${ISMRMRD_VERSION_STRING}
347 COMPATIBILITY SameMajorVersion
348 )
349
350 # Write a CMake file with all the targets information
351 # (not for installing, but for external project to import targets from the
352 # current build tree)
353 if(CMAKE_VERSION VERSION_LESS 3.0)
354 export(TARGETS ismrmrd
355 FILE ${CMAKE_CURRENT_BINARY_DIR}/ISMRMRDTargets.cmake
356 NAMESPACE ISMRMRD::
357 )
358 else()
359 export(EXPORT ISMRMRDTargets
360 FILE ${CMAKE_CURRENT_BINARY_DIR}/ISMRMRDTargets.cmake
361 NAMESPACE ISMRMRD::
362 )
363 endif()
364
365 install(EXPORT ISMRMRDTargets
366 FILE ISMRMRDTargets.cmake
367 NAMESPACE ISMRMRD::
368 DESTINATION ${INSTALL_CONFIGDIR}
369 )
370
371 install(FILES
372 "${CMAKE_CURRENT_BINARY_DIR}/ISMRMRDConfigVersion.cmake"
373 "${CMAKE_CURRENT_BINARY_DIR}/InstallFiles/ISMRMRDConfig.cmake"
374 DESTINATION ${INSTALL_CONFIGDIR}
375 COMPONENT Devel)
376
377 export(PACKAGE ISMRMRD)
378
379 # Create package
380 string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER)
381 include(${ISMRMRD_CMAKE_DIR}/ismrmrd_cpack.cmake)
382 if(CPACK_GENERATOR)
383 message(STATUS "Found CPack generators: ${CPACK_GENERATOR}")
384 configure_file("${ISMRMRD_CMAKE_DIR}/cpack_options.cmake.in" ${ISMRMRD_CPACK_CFG_FILE} @ONLY)
385 set(CPACK_PROJECT_CONFIG_FILE ${ISMRMRD_CPACK_CFG_FILE})
386 include(CPack)
387 endif()