]> Creatis software - gdcm.git/blob - Testing/CMakeLists.txt
BUG: Fix gdcm build on SunOS, where gethostname could not be resolved
[gdcm.git] / Testing / CMakeLists.txt
1 # CMakeLists for Testing purpose
2 # Cxx file that need a file to run should be place aproprietly
3
4 SET(CXX_TEST_PATH ${EXECUTABLE_OUTPUT_PATH})
5
6 SET(GDCM_TESTS ${CXX_TEST_PATH}/gdcmTests)
7
8 # add test that does not require data:
9 # They usally return if no argument is given
10 SET(TEST_SOURCES
11   TestBug.cxx
12   TestHash.cxx
13   TestTS.cxx
14   TestVR.cxx
15   TestUtil.cxx
16   TestDicomString.cxx
17 )
18
19 # add tests that require data
20 IF (GDCM_DATA_ROOT)
21   SET(TEST_SOURCES ${TEST_SOURCES}     
22     TestReadWriteReadCompare.cxx     # includes generated gdcmDataImages.h 
23     PrintAllDocument.cxx             # includes generated gdcmDataImages.h
24     TestAllReadCompareDicom.cxx      # includes generated gdcmDataImages.h
25     TestAllEntryVerify.cxx           # includes generated gdcmDataImages.h
26     PrintDicomDir.cxx
27     #TestChangeHeader.cxx
28     TestDicomDir.cxx                 # require DICOMDIR
29     BuildUpDicomDir.cxx              # writes a file named "NewDICOMDIR"
30     makeDicomDir.cxx                 # writes a file named "NewDICOMDIR"
31     TestCopyDicom.cxx
32     TestCopyRescaleDicom.cxx
33     TestWriteSimple.cxx
34   )
35   # add test that require VTK:
36   IF(GDCM_VTK)
37     # Include the VTK library
38     INCLUDE(${VTK_USE_FILE})
39
40     INCLUDE_DIRECTORIES(
41       ${GDCM_SOURCE_DIR}/vtk/
42       )
43     SET(TEST_SOURCES ${TEST_SOURCES}
44       ShowDicom.cxx
45       ShowDicomSeq.cxx
46       TestWriteWithVTK.cxx
47       )
48   ENDIF(GDCM_VTK)
49 ENDIF (GDCM_DATA_ROOT)
50
51
52
53 # include stuff
54 INCLUDE_DIRECTORIES(
55   ${GDCM_SOURCE_DIR}/src/
56   ${GDCM_BINARY_DIR}/
57 )
58
59 CREATE_TEST_SOURCELIST(Tests gdcmTests.cxx ${TEST_SOURCES})
60 ADD_EXECUTABLE(gdcmTests ${Tests})
61 IF(GDCM_VTK)
62   TARGET_LINK_LIBRARIES(gdcmTests vtkgdcm vtkRendering)
63 ELSE(GDCM_VTK)
64   TARGET_LINK_LIBRARIES(gdcmTests gdcm)
65 ENDIF(GDCM_VTK)
66
67 SET (TestsToRun ${Tests})
68 REMOVE (TestsToRun gdcmTests.cxx)
69
70 # Loop over files and create executables
71 FOREACH(file ${TEST_SOURCES})
72   GET_FILENAME_COMPONENT(name ${file} NAME_WE)
73 #  IF (GDCM_DATA_ROOT)
74 #    ADD_TEST(${name} ${GDCM_TESTS} ${name}
75 #        -D ${GDCM_DATA_ROOT}
76 #        -T ${GDCM_BINARY_DIR}/Testing/Temporary
77 #        -V Baseline/gdcm/${name}.png)
78 #  ELSE (GDCM_DATA_ROOT)
79     ADD_TEST(${name} ${GDCM_TESTS} ${name})
80 #  ENDIF (GDCM_DATA_ROOT)
81 ENDFOREACH(file ${TEST_SOURCES})
82
83 #-----------------------------------------------------------------------------
84
85 # We need to test the reading of all dicom images in the gdcmData directory
86 # First parse this directory and extract all images
87
88 IF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)
89   FILE(GLOB GDCM_DATA_IMAGES_GLOB
90     "${GDCM_DATA_ROOT}/*.acr"
91     "${GDCM_DATA_ROOT}/*.dcm"
92     "${GDCM_DATA_ROOT}/*.nema"
93     "${GDCM_DATA_ROOT}/*.ima"
94     )
95   FILE(GLOB GDCM_DATA_SEQ_IMAGES_GLOB
96     "${GDCM_DATA_ROOT}/*FileSeq0.acr"
97     "${GDCM_DATA_ROOT}/*FileSeq0.dcm"
98     "${GDCM_DATA_ROOT}/*FileSeq0.nema"
99     "${GDCM_DATA_ROOT}/*FileSeq0.ima"
100     )
101 ELSE(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)   
102   # Since there is a bug in cmake 1.8.3, I'll have to do two separate globs
103   FILE(GLOB GDCM_DATA_IMAGES_GLOB_ACR
104     "${GDCM_DATA_ROOT}/*.acr"
105     )
106   FILE(GLOB GDCM_DATA_IMAGES_GLOB_DCM
107     "${GDCM_DATA_ROOT}/*.dcm"
108     )
109   FILE(GLOB GDCM_DATA_IMAGES_GLOB_NEMA
110     "${GDCM_DATA_ROOT}/*.nema"
111     )
112   FILE(GLOB GDCM_DATA_IMAGES_GLOB_IMA
113     "${GDCM_DATA_ROOT}/*.ima"
114     )
115   SET(GDCM_DATA_IMAGES_GLOB 
116     ${GDCM_DATA_IMAGES_GLOB_DCM} ${GDCM_DATA_IMAGES_GLOB_ACR}
117     ${GDCM_DATA_IMAGES_GLOB_NEMA} ${GDCM_DATA_IMAGES_GLOB_IMA})
118
119   FILE(GLOB GDCM_DATA_SEQ_IMAGES_GLOB_ACR
120     "${GDCM_DATA_ROOT}/*FileSeq0.acr"
121     )
122   FILE(GLOB GDCM_DATA_SEQ_IMAGES_GLOB_DCM
123     "${GDCM_DATA_ROOT}/*FileSeq0.dcm"
124     )
125   FILE(GLOB GDCM_DATA_SEQ_IMAGES_GLOB_NEMA
126     "${GDCM_DATA_ROOT}/*FileSeq0.nema"
127     )
128   FILE(GLOB GDCM_DATA_SEQ_IMAGES_GLOB_IMA
129     "${GDCM_DATA_ROOT}/*FileSeq0.ima"
130     )
131   SET(GDCM_DATA_SEQ_IMAGES_GLOB 
132     ${GDCM_DATA_SEQ_IMAGES_GLOB_DCM} ${GDCM_DATA_SEQ_IMAGES_GLOB_ACR}
133     ${GDCM_DATA_SEQ_IMAGES_GLOB_NEMA} ${GDCM_DATA_SEQ_IMAGES_GLOB_IMA})
134 ENDIF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9)   
135
136 # Black list of images known to break lots of readers (efilm, xmedcon ...):
137 SET(BLACK_LIST
138   # serial killer (also segfaults vtkgdcmViewer, but NOT PrintFile)
139   "gdcm-JPEG-LossLessThoravision.dcm"
140
141   # Mathieu: temporarily remove as it kills my gnome session (but not kde)
142   # JPR: also breaks TestReadWriteReadCompare : Pixel differ (as expanded
143   #      in memory)  
144   "KODAK-12-MONO1-Odd_Terminated_Sequence.dcm"
145   )
146
147 # This is a GLOB expression, change it into a list separated with a comma and \n
148 SET(GDCM_DATA_IMAGES)
149 FOREACH(filename ${GDCM_DATA_IMAGES_GLOB})
150   GET_FILENAME_COMPONENT(filename_temp ${filename} NAME)
151   STRING(REGEX MATCH ${filename_temp} bad_dicom ${BLACK_LIST})
152   IF(NOT bad_dicom)
153     SET(GDCM_DATA_IMAGES "${GDCM_DATA_IMAGES}\n\"${filename_temp}\",")
154   ENDIF(NOT bad_dicom)
155 ENDFOREACH(filename)
156
157 SET(GDCM_DATA_SEQ_IMAGES)
158 FOREACH(filename ${GDCM_DATA_SEQ_IMAGES_GLOB})
159   GET_FILENAME_COMPONENT(filename_temp ${filename} NAME)
160   STRING(REGEX MATCH ${filename_temp} bad_dicom ${BLACK_LIST})
161   IF(NOT bad_dicom)
162     STRING(REGEX REPLACE "(.*)FileSeq0(.*)" "\\1FileSeq%d\\2" filename_temp2 ${filename_temp})
163
164     SET(GDCM_DATA_SEQ_IMAGES "${GDCM_DATA_SEQ_IMAGES}\n\"${filename_temp2}\",")
165   ENDIF(NOT bad_dicom)
166 ENDFOREACH(filename)
167
168 # Populate GDCM_DATA_IMAGES:
169 FILE(WRITE "${GDCM_BINARY_DIR}/gdcmDataImages.h"
170   "const char * const gdcmDataImages[] = { ${GDCM_DATA_IMAGES}\n0 };\n" 
171   )
172
173 # Populate GDCM_DATA_SEQ_IMAGES:
174 FILE(WRITE "${GDCM_BINARY_DIR}/gdcmDataSeqImages.h"
175   "const char * const gdcmDataSeqImages[] = { ${GDCM_DATA_SEQ_IMAGES}\n0 };\n" 
176   )