-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
304 lines (273 loc) · 11.5 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
cmake_minimum_required(VERSION 3.14)
project(gdcmjs)
include(cmake/get_cpm.cmake)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
CPMAddPackage(
NAME gdcm
URL "https://github.com/malaterre/GDCM/archive/refs/tags/v3.0.20.zip"
OPTIONS
"GDCM_BUILD_DOCBOOK_MANPAGES 0"
"BUILD_APPLICATIONS 1"
"GDCM_BUILD_APPLICATIONS 1"
"GDCM_BUILD_EXAMPLES 1"
)
if(gdcm_ADDED)
message(STATUS "GDCM ADDED")
message(STATUS "GDCM_BINARY_DIR: ${GDCM_BINARY_DIR}")
message(STATUS "GDCM_SOURCE_DIR: ${GDCM_SOURCE_DIR}")
else()
message(FATAL_ERROR "GDCM NOT ADDED")
endif()
####################################################################
if(WIN32 AND NOT CYGWIN AND NOT MINGW)
include_directories(
"${GDCM_SOURCE_DIR}/Utilities/getopt"
)
endif()
# Add the include paths
include_directories(
"${GDCM_BINARY_DIR}/Source/Common"
"${GDCM_SOURCE_DIR}/Source/Common"
"${GDCM_SOURCE_DIR}/Source/DataStructureAndEncodingDefinition"
"${GDCM_SOURCE_DIR}/Source/MediaStorageAndFileFormat"
"${GDCM_SOURCE_DIR}/Source/InformationObjectDefinition"
"${GDCM_SOURCE_DIR}/Source/MessageExchangeDefinition"
# FIXME:
"${GDCM_SOURCE_DIR}/Source/DataDictionary"
"${GDCM_SOURCE_DIR}/Utilities"
)
if(NOT GDCM_USE_SYSTEM_SOCKETXX)
include_directories(
"${GDCM_SOURCE_DIR}/Utilities/socketxx"
"${GDCM_SOURCE_DIR}/Utilities/socketxx/socket++" # local.h
"${GDCM_BINARY_DIR}/Utilities/socketxx/socket++" # config.h
)
endif()
if(WIN32)
if (BUILD_SHARED_LIBS)
add_definitions(-DGETOPT_DLL)
endif ()
endif()
set(GDCM_EXECUTABLE_NAME
# gdcmdump
# gdcmdiff
# gdcmraw
# gdcmscanner
# gdcmanon
# gdcmclean
# gdcmgendir
# #gdcmoverlay
# gdcmimg
# #deflate
# gdcmconv
# #gdcmstream
# gdcmtar
# gdcminfo
# gdcmscu
# gdcmxml
# gdcmpap3
gdcmconvmod
)
# poppler people have the worse API backward compatibility I know of.
# there is absolutely no way to check the version of poppler
# they change the API during a minor change of the version
if(GDCM_USE_SYSTEM_POPPLER)
include(CheckCXXSourceCompiles)
set(CMAKE_REQUIRED_INCLUDES ${POPPLER_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${POPPLER_LIBRARIES})
CHECK_CXX_SOURCE_COMPILES(
"\#include <poppler/GlobalParams.h>\nint main() { globalParams = new GlobalParams(0); return 0;}"
LIBPOPPLER_GLOBALPARAMS_CSTOR_HAS_PARAM)
set(libpoppler_flags)
if(LIBPOPPLER_GLOBALPARAMS_CSTOR_HAS_PARAM)
list(APPEND libpoppler_flags -DLIBPOPPLER_GLOBALPARAMS_CSTOR_HAS_PARAM)
endif()
CHECK_CXX_SOURCE_COMPILES(
"\#include <poppler/GlobalParams.h>\nint main() { globalParams.reset( new GlobalParams()); return 0;}"
LIBPOPPLER_GLOBALPARAMS_HAS_RESET)
set(libpoppler_flags)
if(LIBPOPPLER_GLOBALPARAMS_HAS_RESET)
list(APPEND libpoppler_flags -DLIBPOPPLER_GLOBALPARAMS_HAS_RESET)
endif()
CHECK_CXX_SOURCE_COMPILES(
"\#include <poppler/PDFDoc.h>\nint main() { PDFDoc d((GooString*)NULL,(GooString*)NULL,(GooString*)NULL); d.getPDFVersion(); return 0;}"
LIBPOPPLER_PDFDOC_HAS_PDFVERSION)
if(LIBPOPPLER_PDFDOC_HAS_PDFVERSION)
list(APPEND libpoppler_flags -DLIBPOPPLER_PDFDOC_HAS_PDFVERSION)
endif()
CHECK_CXX_SOURCE_COMPILES(
"\#include <poppler/PDFDoc.h>\n#include <poppler/StructTreeRoot.h>\nint main() { Catalog c(NULL); c.getStructTreeRoot()->getDoc(); return 0;}"
LIBPOPPLER_CATALOG_HAS_STRUCTTREEROOT)
if(LIBPOPPLER_CATALOG_HAS_STRUCTTREEROOT)
list(APPEND libpoppler_flags -DLIBPOPPLER_CATALOG_HAS_STRUCTTREEROOT)
endif()
CHECK_CXX_SOURCE_COMPILES(
"\#include <poppler/Object.h>\nint main() { Object o(42); }"
LIBPOPPLER_NEW_OBJECT_API)
if(LIBPOPPLER_NEW_OBJECT_API)
list(APPEND libpoppler_flags -DLIBPOPPLER_NEW_OBJECT_API)
endif()
CHECK_CXX_SOURCE_COMPILES(
"\#include <poppler/goo/GooString.h>\nint main() { const GooString gs; gs.getChar(0); return 0; }"
LIBPOPPLER_GOOSTRING_HAS_CONSTGETCHAR)
if(LIBPOPPLER_GOOSTRING_HAS_CONSTGETCHAR)
list(APPEND libpoppler_flags -DLIBPOPPLER_GOOSTRING_HAS_CONSTGETCHAR)
endif()
CHECK_CXX_SOURCE_COMPILES(
"\#include <poppler/goo/GooString.h>\nint main() { GooString gs; gs.getCString(); return 0; }"
LIBPOPPLER_GOOSTRING_HAS_GETCSTRING)
if(LIBPOPPLER_GOOSTRING_HAS_GETCSTRING)
list(APPEND libpoppler_flags -DLIBPOPPLER_GOOSTRING_HAS_GETCSTRING)
endif()
CHECK_CXX_SOURCE_COMPILES(
"\#include <poppler/UnicodeMap.h>\nint main() { Unicode u; char buf[8]; const UnicodeMap *uMap; uMap->mapUnicode(u, buf, sizeof(buf)); return 0; }"
LIBPOPPLER_UNICODEMAP_HAS_CONSTMAPUNICODE)
if(LIBPOPPLER_UNICODEMAP_HAS_CONSTMAPUNICODE)
list(APPEND libpoppler_flags -DLIBPOPPLER_UNICODEMAP_HAS_CONSTMAPUNICODE)
endif()
CHECK_CXX_SOURCE_COMPILES(
"\#include <poppler/PDFDoc.h>\nint main() { std::optional<GooString> ownerPW, userPW; PDFDoc d((BaseStream*)nullptr,ownerPW,userPW); return 0;}"
LIBPOPPLER_PDFDOC_HAS_OPTIONAL)
if(LIBPOPPLER_PDFDOC_HAS_OPTIONAL)
list(APPEND libpoppler_flags -DLIBPOPPLER_PDFDOC_HAS_OPTIONAL)
endif()
if(libpoppler_flags)
string(REPLACE ";" " " libpoppler_flags_string "${libpoppler_flags}")
set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/gdcminfo.cxx
PROPERTIES COMPILE_FLAGS "${libpoppler_flags_string}")
set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/gdcmpdf.cxx
PROPERTIES COMPILE_FLAGS "${libpoppler_flags_string}")
endif()
include_directories(${POPPLER_INCLUDE_DIRS})
set(GDCM_EXECUTABLE_NAME
${GDCM_EXECUTABLE_NAME}
gdcmpdf
)
endif()
if(GDCM_USE_SYSTEM_LIBXML2)
include_directories(${LIBXML2_INCLUDE_DIR})
endif()
if(GDCM_USE_SYSTEM_OPENJPEG)
include_directories(${OPENJPEG_INCLUDE_DIRS} )
else()
include_directories(
"${GDCM_BINARY_DIR}/Utilities/gdcmopenjpeg"
)
endif()
if(NOT BUILD_SHARED_LIBS)
set_source_files_properties(gdcmstream.cxx
PROPERTIES
COMPILE_FLAGS -DOPJ_STATIC
)
endif()
if(GDCM_USE_SYSTEM_PAPYRUS3)
include_directories(
${PAPYRUS3_INCLUDE_DIRS}
)
endif()
if(NOT GDCM_USE_SYSTEM_ZLIB)
include_directories(
"${GDCM_BINARY_DIR}/Utilities/gdcmzlib"
)
endif()
foreach(exename ${GDCM_EXECUTABLE_NAME})
if(${exename} STREQUAL "gdcminfo")
add_executable(${exename} ${exename}.cxx puff.c)
else()
add_executable(${exename} ${exename}.cxx)
endif()
target_link_libraries(${exename} gdcmMSFF)
if(${exename} STREQUAL "gdcmpdf")
target_link_libraries(${exename} ${POPPLER_LIBRARIES})
elseif(${exename} STREQUAL "gdcmxml")
target_link_libraries(${exename} ${LIBXML2_LIBRARIES})
elseif(${exename} STREQUAL "gdcmscu")
if(NOT GDCM_USE_SYSTEM_SOCKETXX)
target_link_libraries(${exename} gdcmMEXD socketxx)
else()
target_link_libraries(${exename} gdcmMEXD socket++)
endif()
elseif(${exename} STREQUAL "gdcmstream")
target_link_libraries(${exename} ${GDCM_OPENJPEG_LIBRARIES})
elseif(${exename} STREQUAL "gdcmdump")
target_link_libraries(${exename} ${GDCM_ZLIB_LIBRARIES})
elseif(${exename} STREQUAL "gdcminfo")
if(GDCM_USE_SYSTEM_POPPLER)
target_link_libraries(${exename} ${POPPLER_LIBRARIES})
endif()
endif()
if(GDCM_EXECUTABLE_PROPERTIES)
set_target_properties(${exename} PROPERTIES ${GDCM_EXECUTABLE_PROPERTIES})
endif()
if(WIN32 AND NOT CYGWIN AND NOT MINGW)
target_link_libraries(${exename} gdcmgetopt)
endif()
if(NOT GDCM_INSTALL_NO_RUNTIME)
install(TARGETS ${exename}
EXPORT ${GDCM_TARGETS_NAME}
RUNTIME DESTINATION ${GDCM_INSTALL_BIN_DIR} COMPONENT Applications
)
endif()
endforeach()
if(GDCM_USE_SYSTEM_PAPYRUS3)
target_link_libraries(gdcmpap3 ${PAPYRUS3_LIBRARIES})
endif()
#if(BUILD_TESTING)
# if(GDCM_DATA_ROOT)
# file(MAKE_DIRECTORY ${GDCM_TEMP_DIRECTORY}/gdcmanon-gdcmdata)
# add_test(NAME gdcmanon-gdcmdata COMMAND gdcmanon
# --continue # skip LIBIDO-16-ACR_NEMA-Volume.dcm
# --certificate ${GDCM_SOURCE_DIR}/Testing/Source/Data/certificate.pem
# ${GDCM_DATA_ROOT}
# ${GDCM_TEMP_DIRECTORY}/gdcmanon-gdcmdata
# )
# endif()
#endif()
if(BUILD_TESTING)
# http://www.na-mic.org/Wiki/index.php/CTSC:ARRA:Mockup
# http://www.dicomserver.co.uk/
# the NAMIC server is offline, Steve Pieper has volunteered his servers, but they are intermittent
# IP Address: common.bwh.harvard.edu (155.52.248.49)
# Port: 11112
# AE Title: CTK_AE
# and
# IP Address: joe.bwh.harvard.edu (155.52.248.50)
# Port: 5678
# AE Title: CONQUESTSRV1
#since these servers have no guaranteed uptime, these tests should be changed to some other, known-to-be-up server
#add_test(NAME gdcmscu-echo-CONQUEST COMMAND gdcmscu --echo --call CONQUESTSRV1 joe.bwh.harvard.edu 5678)
add_test(NAME gdcmscu-echo-dicomserver COMMAND gdcmscu --echo www.dicomserver.co.uk 11112)
if(GDCM_DATA_ROOT)
# CR-MONO1-10-chest.dcm gets rejected by www.dicomserver.co.uk:
# Tag 0x0,0x902 reported as Incorrect VM (1) - Minimum value is 2 : 'Array of N Elements' (error 42752)
# CR-MONO1-10-chest.dcm gets rejected by mi2b2.slicer.org
# Tag 0x0,0x902 reported as Acceptance of objects without Patient ID is disabled (error 43264)
#add_test(NAME gdcmscu-store-CONQUEST COMMAND gdcmscu --store --call CONQUESTSRV1 joe.bwh.harvard.edu 11112 ${GDCM_DATA_ROOT}/SIEMENS_MAGNETOM-12-MONO2-FileSeq1.dcm)
add_test(NAME gdcmscu-store-dicomserver COMMAND gdcmscu --store www.dicomserver.co.uk 11112 ${GDCM_DATA_ROOT}/SIEMENS_MAGNETOM-12-MONO2-FileSeq1.dcm)
endif()
#add_test(NAME gdcmscu-find-CONQUEST COMMAND gdcmscu --find --patient --call CONQUESTSRV1 joe.bwh.harvard.edu 11112 --patientroot -k 10,10=X*)
add_test(NAME gdcmscu-find-dicomserver COMMAND gdcmscu --find --patient www.dicomserver.co.uk 11112 --patientroot -k 10,20=*)
if(GDCM_DICOM_SERVER_AETITLE)
if(GDCM_DATA_ROOT)
# Let's C-STORE a limited subset of gdcmData for now:
set(CSTORE_DATA_FILES
CR-MONO1-10-chest.dcm # Implicit VR Little Endian: Default Transfer Syntax for DICOM
012345.002.050.dcm # JPEG Lossless, Non-Hierarchical, First-Order Prediction
)
foreach(cstorefile ${CSTORE_DATA_FILES})
add_test(NAME gdcmscu-echo-${cstorefile} COMMAND gdcmscu --echo --aetitle ${GDCM_DICOM_CLIENT_AETITLE} --call ${GDCM_DICOM_SERVER_AETITLE} ${GDCM_DICOM_SERVER_PEER} ${GDCM_DICOM_SERVER_PORT})
add_test(NAME gdcmscu-store-${cstorefile} COMMAND gdcmscu --store --aetitle ${GDCM_DICOM_CLIENT_AETITLE} --call ${GDCM_DICOM_SERVER_AETITLE} ${GDCM_DICOM_SERVER_PEER} ${GDCM_DICOM_SERVER_PORT} ${GDCM_DATA_ROOT}/${cstorefile})
add_test(NAME gdcmscu-find-${cstorefile} COMMAND gdcmscu --find --patient --aetitle ${GDCM_DICOM_CLIENT_AETITLE} --call ${GDCM_DICOM_SERVER_AETITLE} ${GDCM_DICOM_SERVER_PEER} ${GDCM_DICOM_SERVER_PORT} --patientroot -k 10,10=A* -k 10,20)
add_test(NAME gdcmscu-move1-${cstorefile} COMMAND gdcmscu --move --patient --aetitle ${GDCM_DICOM_CLIENT_AETITLE} --call ${GDCM_DICOM_SERVER_AETITLE} ${GDCM_DICOM_SERVER_PEER} ${GDCM_DICOM_SERVER_PORT} -o ${CMAKE_CURRENT_BINARY_DIR} --patientroot -k 10,10=Anonymized --port-scp ${GDCM_DICOM_CLIENT_PORT})
add_test(NAME gdcmscu-move2-${cstorefile} COMMAND gdcmscu --move --patient --aetitle ${GDCM_DICOM_CLIENT_AETITLE} --call ${GDCM_DICOM_SERVER_AETITLE} ${GDCM_DICOM_SERVER_PEER} ${GDCM_DICOM_SERVER_PORT} -o ${CMAKE_CURRENT_BINARY_DIR} --patientroot -k 10,10=X* --port-scp ${GDCM_DICOM_CLIENT_PORT})
endforeach()
endif()
endif()
endif()
####################################################################
add_library(gdcmconvmodlib gdcmconvmod.cxx)
#target_link_libraries(gdcmconvmod gdcmMSFF)