]> Creatis software - gdcm.git/blob - CMakeLists.txt
Fix comments
[gdcm.git] / CMakeLists.txt
1 PROJECT(GDCM)
2 CMAKE_MINIMUM_REQUIRED(VERSION 2.0)
3 # okay in fact you need at least cmake 2.0.4 to get swig working properly
4 # and you cannot use cmake 2.0.6 out of the box due to a bug (patched in debian package)
5
6 #-----------------------------------------------------------------------------
7 # GDCM version number, usefull for packaging and doxygen doc:
8 SET(GDCM_MAJOR_VERSION 1)
9 SET(GDCM_MINOR_VERSION 3)
10 SET(GDCM_BUILD_VERSION 2)
11 SET(GDCM_VERSION
12     "${GDCM_MAJOR_VERSION}.${GDCM_MINOR_VERSION}.${GDCM_BUILD_VERSION}")
13
14 #-----------------------------------------------------------------------------
15 # Provide compatibility options.
16 OPTION(GDCM_LEGACY_REMOVE "Remove all legacy code completely." OFF)
17 OPTION(GDCM_LEGACY_SILENT "Silence all legacy code messages." OFF)
18 MARK_AS_ADVANCED(GDCM_LEGACY_REMOVE GDCM_LEGACY_SILENT)
19
20 # VS 2005 declared that some C functions were deprecated...
21 IF(CMAKE_COMPILER_2005)
22   ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
23   ADD_DEFINITIONS(-D_SCL_SECURE_NO_DEPRECATE)
24 ENDIF(CMAKE_COMPILER_2005) 
25
26 #-----------------------------------------------------------------------------
27 # Build shared lib by default
28 OPTION(BUILD_SHARED_LIBS "Build GDCM with shared libraries." ON)
29
30 SET(GDCM_CMAKE_DIR "${GDCM_SOURCE_DIR}/Utilities/CMake")
31 SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${GDCM_CMAKE_DIR}")
32
33 SET(GDCM_CONFIGURATION_TYPES ${CMAKE_CONFIGURATION_TYPES})
34
35 OPTION(GDCM_DEBUG "Turn verbosity of some statement ON." OFF)
36 MARK_AS_ADVANCED(GDCM_DEBUG)
37
38 # --------------------------------------------------------------------------
39 SET (GDCM_NAME_SPACE gdcm    CACHE STRING "name space")
40
41 # --------------------------------------------------------------------------
42 # Install directories
43 STRING(TOLOWER ${PROJECT_NAME} project_name)
44
45 IF(NOT GDCM_INSTALL_BIN_DIR)
46   SET(GDCM_INSTALL_BIN_DIR "/bin")
47 ENDIF(NOT GDCM_INSTALL_BIN_DIR)
48
49 IF(NOT GDCM_INSTALL_LIB_DIR)
50   SET(GDCM_INSTALL_LIB_DIR "/lib/${project_name}")
51 ENDIF(NOT GDCM_INSTALL_LIB_DIR)
52
53 IF(NOT GDCM_INSTALL_DATA_DIR)
54   SET(GDCM_INSTALL_DATA_DIR "/share/${project_name}")
55 ENDIF(NOT GDCM_INSTALL_DATA_DIR)
56
57 IF(NOT GDCM_INSTALL_INCLUDE_DIR)
58   SET(GDCM_INSTALL_INCLUDE_DIR "/include/${project_name}")
59 ENDIF(NOT GDCM_INSTALL_INCLUDE_DIR)
60
61 IF(NOT GDCM_INSTALL_PACKAGE_DIR)
62   SET(GDCM_INSTALL_PACKAGE_DIR ${GDCM_INSTALL_LIB_DIR})
63 ENDIF(NOT GDCM_INSTALL_PACKAGE_DIR)
64
65 IF(NOT GDCM_VTK_INSTALL_PACKAGE_DIR)
66   SET(GDCM_VTK_INSTALL_PACKAGE_DIR ${VTK_INSTALL_PACKAGE_DIR})
67 ENDIF(NOT GDCM_VTK_INSTALL_PACKAGE_DIR)
68
69 IF(NOT GDCM_INSTALL_NO_DEVELOPMENT)
70   SET(GDCM_INSTALL_NO_DEVELOPMENT 0)
71 ENDIF(NOT GDCM_INSTALL_NO_DEVELOPMENT)
72
73 IF(NOT GDCM_INSTALL_NO_RUNTIME)
74   SET(GDCM_INSTALL_NO_RUNTIME 0)
75 ENDIF(NOT GDCM_INSTALL_NO_RUNTIME)
76
77 IF(NOT GDCM_INSTALL_NO_DOCUMENTATION)
78   SET(GDCM_INSTALL_NO_DOCUMENTATION 0)
79 ENDIF(NOT GDCM_INSTALL_NO_DOCUMENTATION)
80
81 SET(GDCM_INSTALL_NO_LIBRARIES)
82 IF(GDCM_BUILD_SHARED_LIBS)
83   IF(GDCM_INSTALL_NO_RUNTIME AND GDCM_INSTALL_NO_DEVELOPMENT)
84     SET(GDCM_INSTALL_NO_LIBRARIES 1)
85   ENDIF(GDCM_INSTALL_NO_RUNTIME AND GDCM_INSTALL_NO_DEVELOPMENT)
86 ELSE(GDCM_BUILD_SHARED_LIBS)
87   IF(GDCM_INSTALL_NO_DEVELOPMENT)
88     SET(GDCM_INSTALL_NO_LIBRARIES 1)
89   ENDIF(GDCM_INSTALL_NO_DEVELOPMENT)
90 ENDIF(GDCM_BUILD_SHARED_LIBS)
91
92 #-----------------------------------------------------------------------------
93 SET (EXECUTABLE_OUTPUT_PATH ${GDCM_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.")
94 SET (LIBRARY_OUTPUT_PATH ${GDCM_BINARY_DIR}/bin    CACHE PATH "Single output directory for building all libraries.")
95 MARK_AS_ADVANCED(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
96
97
98 #-----------------------------------------------------------------------------
99 # Test if compiler defines the pseudo-macro __FUNCTION__
100 IF("GDCM_COMPILER_HAS_FUNCTION" MATCHES "^GDCM_COMPILER_HAS_FUNCTION$")
101   MESSAGE(STATUS "Checking support for __FUNCTION__ in compiler")
102   TRY_COMPILE(GDCM_COMPILER_HAS_FUNCTION
103               ${GDCM_BINARY_DIR}/CMakeTmp/Function
104               ${GDCM_SOURCE_DIR}/CMake/gdcmTestFUNCTION.cxx
105               OUTPUT_VARIABLE OUTPUT)
106   IF(GDCM_COMPILER_HAS_FUNCTION)
107     MESSAGE(STATUS "Checking support for __FUNCTION__ -- yes")
108     SET(GDCM_COMPILER_HAS_FUNCTION 1 CACHE INTERNAL "Support for extension C __FUNCTION__")
109     WRITE_FILE(${CMAKE_BINARY_DIR}/CMakeOutput.log
110       "Determining if the C compiler supports __FUNCTION__ "
111       "passed with the following output:\n"
112       "${OUTPUT}\n" APPEND)
113   ELSE(GDCM_COMPILER_HAS_FUNCTION)
114     MESSAGE(STATUS "Checking support for __FUNCTION__ -- no")
115     SET(GDCM_COMPILER_HAS_FUNCTION 0 CACHE INTERNAL "Support for extension C __FUNCTION__")
116     WRITE_FILE(${CMAKE_BINARY_DIR}/CMakeError.log
117       "Determining if the C compiler supports __FUNCTION__ "
118       "failed with the following output:\n"
119       "${OUTPUT}\n" APPEND)
120   ENDIF(GDCM_COMPILER_HAS_FUNCTION)
121 ENDIF("GDCM_COMPILER_HAS_FUNCTION" MATCHES "^GDCM_COMPILER_HAS_FUNCTION$")
122
123 #-----------------------------------------------------------------------------
124 # Test is compiler support istringstream
125 IF("GDCM_TEST_ISTRINGSTREAM" MATCHES "^GDCM_TEST_ISTRINGSTREAM$")
126   MESSAGE(STATUS "Checking istringstream")
127   TRY_RUN(GDCM_TEST_ISTRINGSTREAM GDCM_TEST_ISTRINGSTREAM_COMPILED
128           ${GDCM_BINARY_DIR}/CMakeTmp/
129           ${GDCM_SOURCE_DIR}/CMake/gdcmTestIstringStream.cxx)
130   IF(GDCM_TEST_ISTRINGSTREAM_COMPILED)
131     IF(GDCM_TEST_ISTRINGSTREAM)
132       MESSAGE(STATUS "Checking istringstream works -- yes")
133       SET(GDCM_TEST_ISTRINGSTREAM 1 CACHE INTERNAL "Whether istringstream works.")
134     ELSE(GDCM_TEST_ISTRINGSTREAM)
135       MESSAGE(STATUS "Checking istringstream works -- no")
136       SET(GDCM_TEST_ISTRINGSTREAM 0 CACHE INTERNAL "Whether istringstream works.")
137     ENDIF(GDCM_TEST_ISTRINGSTREAM)
138   ELSE(GDCM_TEST_ISTRINGSTREAM_COMPILED)
139     MESSAGE(STATUS "Checking istringstream -- failed")
140   ENDIF(GDCM_TEST_ISTRINGSTREAM_COMPILED)
141 ENDIF("GDCM_TEST_ISTRINGSTREAM" MATCHES "^GDCM_TEST_ISTRINGSTREAM$")
142
143 #-----------------------------------------------------------------------------
144 # Build directory on which many applications depend
145 SUBDIRS(
146   Dicts
147   src
148 )
149 #-----------------------------------------------------------------------------
150 # Example subdir:
151
152 OPTION(BUILD_EXAMPLES "Build GDCM examples." ON)
153 IF(BUILD_EXAMPLES)
154   SUBDIRS(Example)
155 ENDIF(BUILD_EXAMPLES)
156
157 #-----------------------------------------------------------------------------
158 # Adding GDCM_DATA_ROOT
159 FIND_PATH(GDCM_DATA_ROOT gdcm-ACR-LibIDO.acr
160   ${GDCM_SOURCE_DIR}/../gdcmData 
161   $ENV{GDCM_DATA}
162   $ENV{PUB_DICT_PATH}/../../gdcmData
163 )
164 # Adding GDCM_DATA_ROOT
165 FIND_PATH(GDCM_DATA_EXTRA_ROOT gdcmData.tar.gz
166   ${GDCM_SOURCE_DIR}/../gdcmDataExtra
167 )
168
169 # Set the place for the public dictionary, must be set before gdcmConfigure.h
170 FIND_PATH(GDCM_PUB_DICT_PATH dicomV3.dic
171   ${GDCM_SOURCE_DIR}/Dicts
172   $ENV{PUB_DICT_PATH}
173 )
174
175 #-----------------------------------------------------------------------------
176 # SunOS + old gcc fixes:
177 INCLUDE (${CMAKE_ROOT}/Modules/CMakeBackwardCompatibilityCXX.cmake)
178 IF(CMAKE_NO_ANSI_STRING_STREAM)
179   SET(GDCM_NO_ANSI_STRING_STREAM 1)
180 ENDIF(CMAKE_NO_ANSI_STRING_STREAM)
181
182 # Big endian thing:
183 INCLUDE (${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
184 TEST_BIG_ENDIAN(GDCM_WORDS_BIGENDIAN)
185
186 INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
187 CHECK_INCLUDE_FILE("stdint.h"       CMAKE_HAVE_STDINT_H)
188 IF(UNIX) #Avoid polluting Win32 cmakecache
189   CHECK_INCLUDE_FILE("inttypes.h"     CMAKE_HAVE_INTTYPES_H)
190 ENDIF(UNIX)
191 # Special Time support, two convention: *NIX vs Win32
192 CHECK_INCLUDE_FILE("sys/times.h"     CMAKE_HAVE_SYS_TIMES_H)
193 CHECK_INCLUDE_FILE("sys/timeb.h"     CMAKE_HAVE_SYS_TIMEB_H)
194
195 # Check if header file exists and add it to the list.
196 INCLUDE (${CMAKE_ROOT}/Modules/CheckIncludeFiles.cmake)
197 MACRO(CHECK_INCLUDE_FILE_CONCAT FILE VARIABLE)
198   CHECK_INCLUDE_FILES("${GDCM_INCLUDES};${FILE}" ${VARIABLE})
199   IF(${VARIABLE})
200     SET(GDCM_INCLUDES ${GDCM_INCLUDES} ${FILE})
201   ENDIF(${VARIABLE})
202 ENDMACRO(CHECK_INCLUDE_FILE_CONCAT)
203
204 # Need those header for GetMacAddress in Util
205 # This is tricky as you need to figure out the proper order to
206 # test the inclusion of files
207 CHECK_INCLUDE_FILE_CONCAT("unistd.h"       CMAKE_HAVE_UNISTD_H)
208 CHECK_INCLUDE_FILE_CONCAT("stdlib.h"       CMAKE_HAVE_STDLIB_H)
209 IF(UNIX) #Avoid polluting Win32 cmakecache
210   CHECK_INCLUDE_FILE_CONCAT("sys/ioctl.h"    CMAKE_HAVE_SYS_IOCTL_H)
211   CHECK_INCLUDE_FILE_CONCAT("sys/socket.h"   CMAKE_HAVE_SYS_SOCKET_H)
212   CHECK_INCLUDE_FILE_CONCAT("sys/sockio.h"   CMAKE_HAVE_SYS_SOCKIO_H)
213   CHECK_INCLUDE_FILE_CONCAT("net/if.h"       CMAKE_HAVE_NET_IF_H)
214   CHECK_INCLUDE_FILE_CONCAT("netinet/in.h"   CMAKE_HAVE_NETINET_IN_H)
215   CHECK_INCLUDE_FILE_CONCAT("net/if_dl.h"    CMAKE_HAVE_NET_IF_DL_H)
216   CHECK_INCLUDE_FILE_CONCAT("net/if_arp.h"   CMAKE_HAVE_NET_IF_ARP_H)
217 ENDIF(UNIX)
218
219 #-----------------------------------------------------------------------------
220 # Test if os defines a length for sockaddr
221 # only doing the test when we have sys/socket
222 IF( ${CMAKE_HAVE_SYS_SOCKET_H} )
223   IF("HAVE_SA_LEN" MATCHES "^HAVE_SA_LEN$")
224     STRING(ASCII 35 POUND)
225     FILE(WRITE ${GDCM_BINARY_DIR}/CMakeTmp/gdcmTestHAVESALEN.c
226       "${POUND}include <sys/types.h>\n"
227       "${POUND}include <sys/socket.h>\n"
228       "int main() { struct sockaddr sa; sa.sa_len = 0; }\n")
229     MESSAGE(STATUS "Checking if ifreq has a sa_len")
230     TRY_COMPILE(HAVE_SA_LEN
231       ${GDCM_BINARY_DIR}
232       ${GDCM_BINARY_DIR}/CMakeTmp/gdcmTestHAVESALEN.c
233       OUTPUT_VARIABLE OUTPUT)
234     IF(HAVE_SA_LEN)
235       MESSAGE(STATUS "Checking if ifreq has a sa_len -- yes")
236       SET(HAVE_SA_LEN 1 CACHE INTERNAL "Support if ifreq has a sa_len")
237       WRITE_FILE(${CMAKE_BINARY_DIR}/CMakeOutput.log
238         "Determining if ifreq has a sa_len"
239         "passed with the following output:\n"
240         "${OUTPUT}\n" APPEND)
241     ELSE(HAVE_SA_LEN)
242       MESSAGE(STATUS "Checking if ifreq has a sa_len -- no")
243       SET(HAVE_SA_LEN 0 CACHE INTERNAL "Support if ifreq has a sa_len")
244       WRITE_FILE(${CMAKE_BINARY_DIR}/CMakeError.log
245         "Determining if ifreq has a sa_len"
246         "failed with the following output:\n"
247         "${OUTPUT}\n" APPEND)
248     ENDIF(HAVE_SA_LEN)
249   ENDIF("HAVE_SA_LEN" MATCHES "^HAVE_SA_LEN$")
250 ENDIF( ${CMAKE_HAVE_SYS_SOCKET_H} )
251
252 #-----------------------------------------------------------------------------
253 # Force Big Endian emulation on little endian:
254 OPTION(GDCM_FORCE_BIGENDIAN_EMULATION "Force Big Endian Emulation. Don't use if you don't know what you are doing." OFF)
255
256 CONFIGURE_FILE(${GDCM_SOURCE_DIR}/gdcmConfigure.h.in
257                ${GDCM_BINARY_DIR}/gdcmConfigure.h @ONLY IMMEDIATE
258                )
259
260 IF(NOT GDCM_INSTALL_NO_DEVELOPMENT)
261   INSTALL_FILES(${GDCM_INSTALL_INCLUDE_DIR} FILES gdcmConfigure.h)
262 ENDIF(NOT GDCM_INSTALL_NO_DEVELOPMENT)
263
264 #-----------------------------------------------------------------------------
265 # Add the testing directories
266 OPTION(BUILD_TESTING "Build testing." ON)
267
268 IF(BUILD_TESTING)
269   CONFIGURE_FILE(${GDCM_SOURCE_DIR}/CMake/CTestCustom.ctest.in
270       ${GDCM_BINARY_DIR}/CMake/CTestCustom.ctest @ONLY)
271   FILE(WRITE ${GDCM_BINARY_DIR}/CTestCustom.cmake
272     "INCLUDE(\"${GDCM_BINARY_DIR}/CMake/CTestCustom.ctest\")\n")
273   ENABLE_TESTING()
274   INCLUDE(CTest)
275   SUBDIRS(Testing)
276 ENDIF(BUILD_TESTING)
277
278
279 #-----------------------------------------------------------------------------
280 OPTION(GDCM_VTK "Build VTK-GDCM Lib." OFF)
281 IF(GDCM_VTK)
282   # Search VTK
283   FIND_PACKAGE(VTK)
284   # If vtk found
285   IF(VTK_FOUND)
286     #INCLUDE(${VTK_USE_FILE})
287     SUBDIRS(vtk)
288   ENDIF(VTK_FOUND)
289 ENDIF(GDCM_VTK)
290
291 #-----------------------------------------------------------------------------
292 OPTION(GDCM_WRAP_PYTHON "Wrap GDCM classes into the Python language." OFF)
293 #if wrapping enable
294 IF(GDCM_WRAP_PYTHON)
295   # Search Python libs:
296   FIND_PACKAGE(PythonLibs)
297   # If PythonLibs found
298   IF(PYTHON_LIBRARY)
299     SUBDIRS(gdcmPython)
300   ENDIF(PYTHON_LIBRARY)
301 ENDIF(GDCM_WRAP_PYTHON)
302
303 #-----------------------------------------------------------------------------
304 OPTION(GDCM_DOCUMENTATION "Build source documentation using doxygen." OFF)
305 # if doxygen enable
306 IF(GDCM_DOCUMENTATION)
307   # Search Doxygen:
308   FIND_PACKAGE(Doxygen)
309   IF(DOXYGEN)
310     SUBDIRS(Doc)
311   ENDIF(DOXYGEN)
312 ENDIF(GDCM_DOCUMENTATION)
313
314 #-----------------------------------------------------------------------------
315 IF(WIN32)
316   OPTION(GDCM_INSTALLER "Build the install setup using InnoSetup." OFF)
317 ENDIF(WIN32)
318 IF(UNIX)
319   OPTION(GDCM_INSTALLER "Prepare the rpmBuild use." OFF)
320 ENDIF(UNIX)
321 IF(GDCM_INSTALLER)
322   SUBDIRS(Builder)
323 ENDIF(GDCM_INSTALLER)
324
325 # --------------------------------------------------------------------------
326 # Configure the export configuration
327
328 SUBDIRS(CMake)
329