]> Creatis software - gdcm.git/blob - Dicts/CMakeLists.txt
f0f600d51e0fcc215d709fd648719a28d3a3a4d3
[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   )
11
12 # The following line make sure we are not appending on an already existing file
13 FILE(WRITE "${GDCM_BINARY_DIR}/Dicts/gdcm.dic" "")
14 FOREACH(dict ${ALL_DICTS})
15   FILE(READ "${GDCM_SOURCE_DIR}/Dicts/${dict}" dict_append)
16   FILE(APPEND "${GDCM_BINARY_DIR}/Dicts/gdcm.dic" ${dict_append})
17 ENDFOREACH(dict)
18
19 FOREACH(test 1.dic 2.dic 3.dic)
20   FILE(READ "${GDCM_SOURCE_DIR}/Dicts/${test}" test_append)
21   FILE(APPEND "${GDCM_BINARY_DIR}/Dicts/test.dic" ${test_append})
22 ENDFOREACH(test)
23
24 #-----------------------------------------------------------------------------
25 # Nice trick to avoid creating a .h file each time we compile gdcm
26 # Since CONFIGURE_FILE do a 'copy if different'
27 # We have to write the file here since is contains 'DICOM_DICTIONARY'
28 # Which is a variable afterward...
29
30 # Following code contributing by Andy Cedilnik (Kitware)
31 FILE(READ "gdcm.dic" ENT)
32 STRING(REGEX REPLACE "\r?\n" ";" ENT "${ENT}")
33 SET(DICOM_DATA_DICTIONARY "")
34
35 FOREACH(line ${ENT})
36   STRING(REGEX REPLACE
37     "^([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-]+) (.*)$"
38     "   {0x\\1, 0x\\2, \"\\3\" , \"\\4\" , \"\\5\"}, " nline "${line}")
39   SET(DICOM_DATA_DICTIONARY "${DICOM_DATA_DICTIONARY}\n${nline}")
40 ENDFOREACH(line)
41
42 SET(DICOM_DATA_DICTIONARY "${DICOM_DATA_DICTIONARY} \n {0,0,0,0,0}")
43
44 #-----------------------------------------------------------------------------
45 # ... for DicomTS file
46 FILE(READ "dicomTS.dic" ENT_TS)
47 STRING(REGEX REPLACE "\r?\n" ";" ENT_TS "${ENT_TS}")
48 SET(DICOM_TS_DICTIONARY "")
49
50 FOREACH(line ${ENT_TS})
51   STRING(REGEX REPLACE
52     "^([0-9.]+) +(.*)$"
53     "  ts[\"\\1\"] = \"\\2\"; " nline "${line}")
54   SET(DICOM_TS_DICTIONARY "${DICOM_TS_DICTIONARY}\n${nline}")
55 ENDFOREACH(line)
56
57 #-----------------------------------------------------------------------------
58 # ... for DicomVR file
59 FILE(READ "dicomVR.dic" ENT_VR)
60 STRING(REGEX REPLACE ";" "/" ENT_VR "${ENT_VR}") # CMake doesn't like ';'
61 STRING(REGEX REPLACE "\r?\n" ";" ENT_VR "${ENT_VR}")
62 SET(DICOM_VR_DICTIONARY "")
63
64 FOREACH(line ${ENT_VR})
65   STRING(REGEX REPLACE
66     "^([A-Z][A-Z]) (.*)/ +//.*$"
67     "  vr[\"\\1\"] = \"\\2\"; " nline "${line}")
68   SET(DICOM_VR_DICTIONARY "${DICOM_VR_DICTIONARY}\n${nline}")
69 ENDFOREACH(line)
70
71 #-----------------------------------------------------------------------------
72 # ... for DictGroupName file
73 FILE(READ "DictGroupName.dic" ENT_TS)
74 STRING(REGEX REPLACE "\r?\n" ";" ENT_TS "${ENT_TS}")
75 SET(DICT_GROUP_NAME_DICTIONARY "")
76
77 FOREACH(line ${ENT_TS})
78   STRING(REGEX REPLACE
79     "^([0-9a-f]+) +(.*)$"
80     "  groupName[0x\\1] = \\2; " nline "${line}")
81   SET(DICT_GROUP_NAME_DICTIONARY "${DICT_GROUP_NAME_DICTIONARY}\n${nline}")
82 ENDFOREACH(line)
83
84 #-----------------------------------------------------------------------------
85 # ... for DicomDir file
86 FILE(READ "DicomDir.dic" ENT_DIR)
87 STRING(REGEX REPLACE "\\\\" "\\\\\\\\" ENT_DIR "${ENT_DIR}")
88 STRING(REGEX REPLACE ";" "/" ENT_DIR "${ENT_DIR}") # CMake doesn't like ';'
89 STRING(REGEX REPLACE "\r?\n" ";" ENT_DIR "${ENT_DIR}")
90 SET(DICOM_DIR_DICTIONARY "")
91
92 FOREACH(line ${ENT_DIR})
93   STRING(REGEX REPLACE
94     "^(metaElem|patientElem|studyElem|serieElem|imageElem) *([a-f0-9]+) ([a-f0-9]+) [\"](.*)[\"](.*)$"
95     "  {\"\\1\" , 0x\\2 , 0x\\3 , \"\\4\"}, \\5" nline "${line}")
96   SET(DICOM_DIR_DICTIONARY "${DICOM_DIR_DICTIONARY}\n${nline}")
97 ENDFOREACH(line)
98
99 #-----------------------------------------------------------------------------
100 # ... Set the dictionnary
101 SET(DICOM_DIR_DICTIONARY "${DICOM_DIR_DICTIONARY} \n {0,0,0,0}")
102
103 #FOREACH(file dicomV3.dic dicomTS.dic dicomVR.dic DicomDir.dic DictGroupName.dic)
104 #  CONFIGURE_FILE("${GDCM_SOURCE_DIR}/Dicts/${file}"
105 #    "${GDCM_BINARY_DIR}/Dicts/${file}.out")
106 #ENDFOREACH(file)
107
108 CONFIGURE_FILE("${GDCM_SOURCE_DIR}/src/gdcmDefaultDicts.cxx.in" 
109   "${GDCM_BINARY_DIR}/src/gdcmDefaultDicts.cxx" IMMEDIATE)
110
111 #-----------------------------------------------------------------------------
112 INSTALL_FILES(${GDCM_DATA_DIR} .dic
113   dicomV3
114   dicomVR
115   dicomTS
116   DicomDir
117   DictGroupName
118   gdcm
119 )
120