]> Creatis software - gdcm.git/blob - Dicts/CMakeLists.txt
ENH: Adding an option (hidden) to not install the gdcm dicts
[gdcm.git] / Dicts / CMakeLists.txt
1 #-----------------------------------------------------------------------------
2 # DICOM dictionary stuff
3
4 #-----------------------------------------------------------------------------
5 # Generate our own 'DICOM' dictionary, based on the following dictionaries:
6 SET(ALL_DICTS
7   dicomV3.dic
8   #Papyrus.dic
9   #NIH.dic     #the forbidden one...
10   #  SPI.dic
11   #  PHILIPS-Intera.dic # uncomment me if you want
12   #GEMS.dic #Commented out to avoid polluting 'non GEMS' images
13   #GEMS-HiSpeed.dic
14   #  GEMS-Advance.dic
15   )
16
17 # Better solution
18 SET(TEST_DICT_BODY)
19 FOREACH(dict ${ALL_DICTS})
20   # Properly set dependencies, therefore `touch Philips-Intera.dic` does not rebuild
21   # but adding/removing a line in Philips-Intera.dic rebuild as expected
22   CONFIGURE_FILE("${GDCM_SOURCE_DIR}/Dicts/${dict}"
23        "${GDCM_BINARY_DIR}/Dicts/${dict}" COPYONLY IMMEDIATE)
24   FILE(READ "${GDCM_SOURCE_DIR}/Dicts/${dict}" dict_append)
25   SET(TEST_DICT_BODY "${TEST_DICT_BODY}\n${dict_append}")
26 ENDFOREACH(dict)
27 CONFIGURE_FILE("${GDCM_SOURCE_DIR}/Dicts/gdcm.dic.in"
28   "${GDCM_BINARY_DIR}/Dicts/gdcm.dic" @ONLY IMMEDIATE)
29
30 #-----------------------------------------------------------------------------
31 # Nice trick to avoid creating a .h file each time we compile gdcm
32 # Since CONFIGURE_FILE do a 'copy if different'
33 # We have to write the file here since is contains 'DICOM_DICTIONARY'
34 # Which is a variable afterward...
35
36 # Following code contributing by Andy Cedilnik (Kitware)
37 FILE(READ "${GDCM_BINARY_DIR}/Dicts/gdcm.dic" ENT)
38 STRING(REGEX REPLACE "\r?\n" ";" ENT "${ENT}")
39 SET(DICOM_DATA_DICTIONARY "")
40
41 FOREACH(line ${ENT})
42   STRING(REGEX REPLACE
43     "^([0-9a-f][0-9a-f][0-9a-f][0-9a-f]) ([0-9a-f][0-9a-f][0-9a-f][0-9a-f]) ([A-Z]+) ([1-9n-]+) (.*)$"
44     "   {0x\\1, 0x\\2, \"\\3\" , \"\\4\" , \"\\5\"}, " nline "${line}")
45   SET(DICOM_DATA_DICTIONARY "${DICOM_DATA_DICTIONARY}\n${nline}")
46 ENDFOREACH(line)
47
48 SET(DICOM_DATA_DICTIONARY "${DICOM_DATA_DICTIONARY} \n {0,0,0,0,0}")
49
50 #-----------------------------------------------------------------------------
51 # ... for DicomTS file
52 FILE(READ "dicomTS.dic" ENT_TS)
53 STRING(REGEX REPLACE "\r?\n" ";" ENT_TS "${ENT_TS}")
54 SET(DICOM_TS_DICTIONARY "")
55
56 FOREACH(line ${ENT_TS})
57   STRING(REGEX REPLACE
58     "^([0-9.]+) +(.*)$"
59     "  ts[\"\\1\"] = \"\\2\"; " nline "${line}")
60   SET(DICOM_TS_DICTIONARY "${DICOM_TS_DICTIONARY}\n${nline}")
61 ENDFOREACH(line)
62
63 #-----------------------------------------------------------------------------
64 # ... for DicomVR file
65 FILE(READ "dicomVR.dic" ENT_VR)
66 STRING(REGEX REPLACE ";" "/" ENT_VR "${ENT_VR}") # CMake doesn't like ';'
67 STRING(REGEX REPLACE "\r?\n" ";" ENT_VR "${ENT_VR}")
68 SET(DICOM_VR_DICTIONARY "")
69
70 FOREACH(line ${ENT_VR})
71   STRING(REGEX REPLACE
72     "^([A-Z][A-Z]) (.*)/ +//.*$"
73     "  vr[\"\\1\"] = \"\\2\"; " nline "${line}")
74   SET(DICOM_VR_DICTIONARY "${DICOM_VR_DICTIONARY}\n${nline}")
75 ENDFOREACH(line)
76
77 #-----------------------------------------------------------------------------
78 # ... for DictGroupName file
79 FILE(READ "DictGroupName.dic" ENT_TS)
80 STRING(REGEX REPLACE "\r?\n" ";" ENT_TS "${ENT_TS}")
81 SET(DICT_GROUP_NAME_DICTIONARY "")
82
83 FOREACH(line ${ENT_TS})
84   STRING(REGEX REPLACE
85     "^([0-9a-f]+) +(.*)$"
86     "  groupName[0x\\1] = \\2; " nline "${line}")
87   SET(DICT_GROUP_NAME_DICTIONARY "${DICT_GROUP_NAME_DICTIONARY}\n${nline}")
88 ENDFOREACH(line)
89
90 #-----------------------------------------------------------------------------
91 # ... for DicomDir file
92 FILE(READ "DicomDir.dic" ENT_DIR)
93 STRING(REGEX REPLACE "\\\\" "\\\\\\\\" ENT_DIR "${ENT_DIR}")
94 STRING(REGEX REPLACE ";" "/" ENT_DIR "${ENT_DIR}") # CMake doesn't like ';'
95 STRING(REGEX REPLACE "\r?\n" ";" ENT_DIR "${ENT_DIR}")
96 SET(DICOM_DIR_DICTIONARY "")
97
98 FOREACH(line ${ENT_DIR})
99   STRING(REGEX REPLACE
100     "^(metaElem|patientElem|studyElem|serieElem|imageElem) *([a-f0-9]+) ([a-f0-9]+) [\"](.*)[\"] [\"](.*)[\"] (.*)$"
101     "  {\"\\1\" , 0x\\2 , 0x\\3 , \"\\4\", \"\\5\"}, \\6" nline "${line}")
102   SET(DICOM_DIR_DICTIONARY "${DICOM_DIR_DICTIONARY}\n${nline}")
103 ENDFOREACH(line)
104
105 #-----------------------------------------------------------------------------
106 # ... Set the dictionnary
107 SET(DICOM_DIR_DICTIONARY "${DICOM_DIR_DICTIONARY} \n {0,0,0,0,0}")
108
109 CONFIGURE_FILE("${GDCM_SOURCE_DIR}/src/gdcmDefaultDicts.cxx.in"
110   "${GDCM_BINARY_DIR}/src/gdcmDefaultDicts.cxx" IMMEDIATE)
111
112 #-----------------------------------------------------------------------------
113 # For now GDCM_INSTALL_NO_DICTIONARY is a hidden variables
114 IF(NOT GDCM_INSTALL_NO_DICTIONARY)
115   INSTALL_FILES(${GDCM_INSTALL_DATA_DIR} .dic
116     dicomV3
117     dicomVR
118     dicomTS
119     DicomDir
120     DictGroupName
121     gdcm
122     )
123 ENDIF(NOT GDCM_INSTALL_NO_DICTIONARY)
124