]> Creatis software - crea.git/blob - cmake/CREAMacro_FindAndUseLibraries.cmake
9af88a16b989113eb383999e3746f3039d1b8232
[crea.git] / cmake / CREAMacro_FindAndUseLibraries.cmake
1
2
3 MACRO(CREA_FIND_AND_USE_LIBRARIES)
4
5 IF(INCLUDE_CTEST)
6         include(CTest) 
7 ENDIF(INCLUDE_CTEST)
8
9
10 set(USE_DEBUG_LIB "" CACHE BOOL "Use Debug Libraries" )
11
12 #-----------------------------------------------------------------------------
13 # If one can invoke this macro then crea has already been found !!
14 # However if one whishes to link against crea and crea was built 
15 # with wx or vtk then we have to find them.
16 # This USE_CREA var is made to resolve this dependency.
17 IF(USE_CREA)
18   IF(CREA_BUILT_WITH_WX)
19     SET(USE_WXWIDGETS ON)
20   ENDIF(CREA_BUILT_WITH_WX)
21   IF(CREA_BUILT_WITH_VTK)
22     SET(USE_VTK ON)
23   ENDIF(CREA_BUILT_WITH_VTK)
24 ENDIF(USE_CREA)
25 #-----------------------------------------------------------------------------
26
27
28 #-----------------------------------------------------------------------------
29
30 IF(USE_QT4)
31   IF(NOT QT_FOUND)      
32   
33         INCLUDE(${CREA_CMAKE_DIR}/CREAMacro_FindAndUseQt.cmake)
34         #FIND_PACKAGE(Qt4 REQUIRED)     
35         
36     IF(QT_FOUND)
37       MESSAGE ( STATUS "=======================================")
38       MESSAGE ( STATUS "Looking for QT4... found")
39       MESSAGE ( STATUS "* Inc Dir = ${QT_INCLUDE_DIR}")
40       MESSAGE ( STATUS "* Version = ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH}")
41       INCLUDE(${QT_USE_FILE})
42          
43       CREA_DEFINE( USE_QT )
44
45    ENDIF(QT_FOUND)
46   ENDIF(NOT QT_FOUND)
47 ENDIF(USE_QT4)
48
49
50 #JFGA Pruebas WT
51 #MESSAGE (  "======================================= SET CMAKE USE_WT JFGA CREAMacro_FindAndUseLibraries.cmake")   
52 #SET(USE_WT OFF)
53
54
55 #-----------------------------------------------------------------------------
56
57 #-----------------------------------------------------------------------------
58 IF(USE_VTK)
59   INCLUDE(${CREA_CMAKE_DIR}/CREAMacro_FindAndUseVTK.cmake)
60   CREA_FIND_AND_USE_VTK()  
61 ENDIF(USE_VTK)
62 #-----------------------------------------------------------------------------
63
64 #-----------------------------------------------------------------------------
65 IF(USE_KWWIDGETS)
66   IF(NOT KWWidgets_FOUND)
67     # Search KWWidgets
68     FIND_PACKAGE(KWWidgets)
69     # If found
70     IF(KWWidgets_FOUND)
71       MESSAGE ( STATUS "=======================================")
72       MESSAGE ( STATUS "Looking for KWWidgets... found")
73       MESSAGE ( STATUS "* Dir     = ${KWWidgets_DIR}")
74       MESSAGE ( STATUS "* Version = ${KWWidgets_MAJOR_VERSION}.${KWWidgets_MINOR_VERSION}.${KWWidgets_BUILD_VERSION}")
75       IF (USE_VTK)
76          # KWWidgets must not search again for vtk !
77         SET(KWWidgets_NO_USE_VTK ON)
78       ENDIF (USE_VTK)
79
80       INCLUDE(${KWWidgets_USE_FILE})
81       CREA_DEFINE( USE_KWWIDGETS )
82       SET(KWWIDGETS_LIBRARIES
83         ${KWWidgets_LIBRARIES}
84         ) 
85       MARK_AS_ADVANCED(KWWidgets_DIR)
86     ELSE(KWWidgets_FOUND)
87       message(FATAL_ERROR "KWWidgets_DIR not found")
88     ENDIF(KWWidgets_FOUND)
89   ENDIF(NOT KWWidgets_FOUND)
90 ENDIF(USE_KWWIDGETS)
91 #-----------------------------------------------------------------------------
92
93 #  --- W A R N I N G :
94 #  Always let ITK *BEFORE* GDCM
95 #  It allows to use 'system installed gdcm' instead of 'itk embedded gdcm'
96 #
97
98 #-----------------------------------------------------------------------------
99 IF(USE_ITK)
100   IF(NOT ITK_FOUND)
101     # Search ITK
102     FIND_PACKAGE(ITK)
103     # If itk found
104     IF(ITK_FOUND)
105       MESSAGE ( STATUS "=======================================")
106       MESSAGE ( STATUS "Looking for ITK... found")
107       MESSAGE ( STATUS "* Dir     = ${ITK_DIR}")
108       MESSAGE ( STATUS "* Version = ${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR}.${ITK_VERSION_PATCH}")
109       SET(SKIP_ITK_BUILD_SETTINGS_FILE ON)
110       INCLUDE(${ITK_USE_FILE})
111       CREA_DEFINE( USE_ITK )
112       CREA_DEFINE( _USE_ITK_ )
113           If (${ITK_VERSION_MAJOR} MATCHES "4")
114            MESSAGE ( STATUS "* Version = ${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR}.${ITK_VERSION_PATCH}")
115                 SET(ITK_LIBRARIES
116                 ${ITK_LIBRARIES}) 
117                  MESSAGE ( STATUS "${ITK_LIBRARIES}")
118                 ELSEIF()
119                 SET(ITK_LIBRARIES
120                         ITKCommon ITKIO ITKBasicFilters ITKAlgorithms)
121                 ENDIF()
122       MARK_AS_ADVANCED(ITK_DIR)
123     ELSE(ITK_FOUND)
124       message(FATAL_ERROR "ITK_DIR not found")
125     ENDIF(ITK_FOUND)
126   ENDIF(NOT ITK_FOUND)
127 ENDIF(USE_ITK)
128 #-----------------------------------------------------------------------------
129
130
131 #-----------------------------------------------------------------------------
132
133 IF(USE_GDCM)
134   IF (USE_GDCM2)
135     MESSAGE(ERROR "CANNOT USE BOTH gdcm AND gdcm2 !")
136   ENDIF (USE_GDCM2)
137
138   IF(NOT GDCM_FOUND)
139     # Search GDCM
140     FIND_PACKAGE(GDCM)
141     # If gdcm found
142     IF(GDCM_FOUND)
143       INCLUDE(${GDCM_USE_FILE})
144       CREA_DEFINE( USE_GDCM )
145
146       MESSAGE ( STATUS "=======================================")
147       MESSAGE ( STATUS "Looking for GDCM... found")
148       MESSAGE ( STATUS "* Dir       = ${GDCM_DIR}")
149       MESSAGE ( STATUS "* Version   = ${GDCM_MAJOR_VERSION}.${GDCM_MINOR_VERSION}.${GDCM_BUILD_VERSION}")
150       MESSAGE ( STATUS "* Namespace = ${GDCM_NAME_SPACE}")
151
152       # Test that GDCM_NAME_SPACE is **NOT** "gdcm" or will conflict with 
153       # embedded gdcm in ITK and will result in hard seg faults !
154       IF(USE_ITK)
155         IF (GDCM_NAME_SPACE STREQUAL "gdcm")
156           MESSAGE(FATAL_ERROR "GDCM_NAME_SPACE value is 'gdcm' which conflicts with ITK embededd gdcm namespace : rebuild gdcm with another GDCM_NAME_SPACE value")
157         ENDIF (GDCM_NAME_SPACE STREQUAL "gdcm")
158       ENDIF(USE_ITK)
159
160       MARK_AS_ADVANCED(GDCM_DIR)
161
162       SET(GDCM_LIBRARIES
163         ${GDCM_LIBRARIES} 
164         )
165
166       # TODO : Test that GDCM was built with option "vtkgdcm"
167       IF(USE_GDCM_VTK)
168         IF(USE_VTK)
169           SET(GDCM_LIBRARIES
170             ${GDCM_LIBRARIES}
171             vtkgdcm  
172             )
173         ENDIF(USE_VTK)
174       ENDIF(USE_GDCM_VTK)
175
176     ELSE(GDCM_FOUND)     
177           MESSAGE(FATAL_ERROR "GDCM not found....")
178     ENDIF(GDCM_FOUND)
179
180   ENDIF(NOT GDCM_FOUND)
181 ENDIF(USE_GDCM)
182
183 #-----------------------------------------------------------------------------
184
185 IF(USE_GDCM2)
186   IF (USE_GDCM)
187     MESSAGE(ERROR "CANNOT USE BOTH gdcm AND gdcm2 !")
188   ENDIF (USE_GDCM)
189
190 #  IF(NOT USE_ITK) # JPR : ITK vs GDCM (avoid cmake break)
191     # Search GDCM2
192
193     FIND_PACKAGE(GDCM REQUIRED)
194     INCLUDE(${GDCM_USE_FILE})
195
196       IF(NOT ${GDCM_MAJOR_VERSION} EQUAL 2)
197         MESSAGE(FATAL_ERROR "gdcm version 2 needed. found ${GDCM_MAJOR_VERSION}.${GDCM_MINOR_VERSION}.${GDCM_BUILD_VERSION}. Set GDCM_DIR to the gdcm version 2 directory")
198       ENDIF(NOT ${GDCM_MAJOR_VERSION} EQUAL 2)
199       
200       CREA_DEFINE( USE_GDCM2 )
201           MARK_AS_ADVANCED(GDCM_DIR)
202       CREA_DEFINE_WITH_VAL( GDCM_NAME_SPACE gdcm )
203       
204       MESSAGE ( STATUS "=======================================")
205       MESSAGE ( STATUS "Looking for GDCM2... found")
206       MESSAGE ( STATUS "* Dir       = ${GDCM_DIR}")
207       MESSAGE ( STATUS "* Version   = ${GDCM_MAJOR_VERSION}.${GDCM_MINOR_VERSION}.${GDCM_BUILD_VERSION}")
208       MESSAGE ( STATUS "* Namespace = ${GDCM_NAME_SPACE}")
209       
210       # Test that GDCM_NAME_SPACE is **NOT** "gdcm" or will conflict with 
211       # embedded gdcm in ITK and will result in hard seg faults !
212                    INCLUDE_DIRECTORIES(${GDCM_INCLUDE_DIRS})     
213                         LINK_DIRECTORIES( ${GDCM_LIBRARY_DIRS}) 
214                         
215       SET(GDCM2_LIBRARIES
216         ${GDCM_LIBRARIES} 
217         )
218
219       IF(USE_GDCM_VTK)
220         IF(USE_VTK)
221                 IF(WIN32)
222                   SET(GDCM_LIBRARIES
223                         ${GDCM_LIBRARIES}
224                         vtkgdcm
225                         gdcmIOD
226                         gdcmMSFF
227                         gdcmexpat
228                         gdcmCommon
229                         gdcmMEXD
230                         gdcmexpat
231                         gdcmDSED
232                         gdcmDICT
233                         gdcmjpeg8
234                         gdcmjpeg12
235                         gdcmjpeg16
236                         socketxx
237                         gdcmopenjpeg
238                         gdcmcharls
239                      )
240                 ELSE(WIN32)
241                     SET(GDCM_LIBRARIES
242                         ${GDCM_LIBRARIES}
243                         vtkgdcm
244                         gdcmIOD
245                         )
246                 ENDIF(WIN32)
247                 
248         ENDIF(USE_VTK)
249       ENDIF(USE_GDCM_VTK)
250  # ENDIF(NOT USE_ITK) # JPR : ITK vs GDCM (avoid cmake break)
251
252 ENDIF(USE_GDCM2)
253
254 #-----------------------------------------------------------------------------
255
256 #-----------------------------------------------------------------------------
257
258 #-------------------- JFGA ---
259 IF(USE_WT)
260         MESSAGE (  "======================================= JFGA ------------USE WT CREAMacro_FindAndUseLibraries.cmake")
261         INCLUDE(${CREA_CMAKE_DIR}/CREAMacro_FindAndUseWt.cmake)
262         CREA_FINDANDUSEWT()
263 ENDIF(USE_WT)
264
265 #-----------------------------------------------------------------------------
266 IF(USE_WXWIDGETS)
267   IF(NOT wxWidgets_FOUND)
268         
269     INCLUDE(${CREA_CMAKE_DIR}/CREAMacro_FindAndUseWxWidgets.cmake)
270     CREA_FIND_WXWIDGETS(${USE_DEBUG_LIB})
271     CREA_USE_WXWIDGETS()
272         
273                 
274  
275   ENDIF(NOT wxWidgets_FOUND)
276 ENDIF(USE_WXWIDGETS)
277 #-----------------------------------------------------------------------------
278
279
280
281 #-----------------------------------------------------------------------------
282 IF(USE_DOXYGEN) 
283   IF(NOT DOXYGEN)
284     MESSAGE ( STATUS "=======================================")
285     FIND_PACKAGE(Doxygen REQUIRED)
286     #  MESSAGE(STATUS "Looking for doxygen... - found ${DOXYGEN}")
287     #  IF(DOXYGEN)
288     #    
289     #  ELSE(DOXYGEN)
290     #    MESSAGE(FATAL_ERROR "Doxygen not found. Required to build the doxygen documentation")
291   ENDIF(NOT DOXYGEN)
292 ENDIF(USE_DOXYGEN)
293 #-----------------------------------------------------------------------------
294
295
296 #-----------------------------------------------------------------------------
297 IF(USE_LATEX)
298         IF (NOT LATEX_COMPILER)
299                 FIND_PACKAGE(LATEX REQUIRED)
300                 MESSAGE ( STATUS "=======================================")
301                 MESSAGE(STATUS "Looking for latex... - found ${LATEX_COMPILER}")
302                 IF (NOT LATEX_FOUND)
303                    MESSAGE(FATAL_ERROR "LATEX_COMPILER NOT FOUND. Example:latex  (MacOS:/opt/local/bin/latex)")
304                 ENDIF (NOT LATEX_FOUND)
305         ENDIF (NOT LATEX_COMPILER)
306   
307 ENDIF(USE_LATEX) 
308 #-----------------------------------------------------------------------------
309
310 #-----------------------------------------------------------------------------
311 IF(USE_TTH) 
312   IF (NOT TTH_EXECUTABLE)
313     FIND_FILE( TTH_EXECUTABLE NAME tth tth.exe PATHS . $ENV{CREATIS}/tth_exe/ ~/Creatis/tth ~/Creatis/tth_linux $ENV{TTH}) 
314
315     IF (NOT TTH_EXECUTABLE)
316       MESSAGE(FATAL_ERROR "TTH not found (LATEX_tth_CONVERTER). Required to build the HTML documentation from tex source")
317     ELSE (NOT  TTH_EXECUTABLE)
318       MESSAGE ( STATUS "=======================================")
319       MESSAGE ( STATUS "Looking for tth... - found ${TTH_EXECUTABLE}")
320     ENDIF(NOT TTH_EXECUTABLE)
321     MARK_AS_ADVANCED( TTH_EXECUTABLE )
322   ENDIF(NOT TTH_EXECUTABLE)
323 ENDIF(USE_TTH)
324 #-----------------------------------------------------------------------------
325 #-----------------------------------------------------------------------------
326 IF(USE_BOOST)
327   IF(NOT Boost_FOUND)
328         add_definitions( -DBOOST_ALL_NO_LIB )
329         add_definitions( -DBOOST_ALL_DYN_LINK )
330         IF (MINGW)
331                 FIND_PACKAGE(Boost COMPONENTS filesystem-mgw71 system-mgw71 signals-mgw71 date_time-mgw71 thread-mgw71 regex-mgw71 program_options-mgw71 REQUIRED)
332         ELSE (MINGW)
333 #               FIND_PACKAGE(Boost COMPONENTS filesystem system signals date_time thread regex program_options REQUIRED)
334                 FIND_PACKAGE(Boost COMPONENTS filesystem system  date_time thread regex program_options REQUIRED)
335         ENDIF(MINGW)
336     IF(Boost_FOUND) 
337           ADD_DEFINITIONS(-DBOOST_FILESYSTEM_VERSION=3)
338           ADD_DEFINITIONS(-DBOOST_MAYOR_VERSION=${Boost_MAJOR_VERSION})
339           ADD_DEFINITIONS(-DBOOST_MINOR_VERSION=${Boost_MINOR_VERSION})
340       MESSAGE ( STATUS "=======================================")
341       MESSAGE ( STATUS "Looking for boost C++ library... - found in ${Boost_INCLUDE_DIR}")
342       INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})         
343           LINK_DIRECTORIES( ${Boost_LIBRARY_DIRS})
344           IF(WIN32)
345                 CREA_DEFINE( USE_BOOST )
346                 ADD_DEFINITIONS(-DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED)
347                 SET(BOOST_LIBRARIES
348                         ${Boost_LIBRARIES}
349                         )
350                         
351 # FCY with cmake boost, it's useless. 
352 # But if it is not working, uncomment   
353 #
354 #       IF(USE_DEBUG_LIB)
355 #                       SET(BOOST_LIBRARIES
356 #                               boost_signals-vc90-mt-gd-1_40
357 #                               boost_filesystem-vc90-mt-gd-1_40
358 #                               boost_date_time-vc90-mt-gd-1_40                    
359 #                          #what about boost_thread? JPR
360 #                       )
361 #               ELSE(NOT USE_DEBUG_LIB)
362 #                       SET(BOOST_LIBRARIES
363 #                               boost_signals-vc90-mt-1_40
364 #                               boost_filesystem-vc90-mt-1_40
365 #                               boost_date_time-vc90-mt-1_40
366 #                       )
367 #               ENDIF(USE_DEBUG_LIB)    
368           ENDIF(WIN32)
369       IF(NOT WIN32)
370
371                   SET(BOOST_LIBRARIES
372
373                         ${Boost_LIBRARIES}
374 #EED 10 Fev 2014
375 #EED                    boost_system-mt
376 #EED                    boost_thread-mt     
377 #EED                    boost_program_options-mt
378
379 #EED 03 mars 2011
380 #EED                    boost_signals-mt
381 #EED                    boost_filesystem-mt
382 #EED                    boost_date_time-mt
383 #EED                    boost_system-mt
384 #EED                    boost_program_options-mt
385 #EED                    boost_regex-mt
386 #EED                    boost_thread-mt     
387
388                         )
389       ENDIF(NOT WIN32)
390
391           MARK_AS_ADVANCED(Boost_INCLUDE_DIR)
392           MARK_AS_ADVANCED(Boost_LIBRARY_DIRS)
393      
394     ELSE(Boost_FOUND)
395       MESSAGE( STATUS "boost C++ library not found - Set Boost_INCLUDE_DIR to the directory containing boost headers")
396     ENDIF(Boost_FOUND)
397   ENDIF(NOT Boost_FOUND)
398  
399
400 ENDIF(USE_BOOST)
401 #-----------------------------------------------------------
402
403 IF(USE_XERCES)
404
405         # FIND xerces
406         IF(WIN32)
407         
408                 SET(XERCES_LIB_DIR $ENV{XERCES_DIR})
409         
410                 IF(NOT XERCES_LIB_DIR)  
411                   MESSAGE(FATAL_ERROR "XERCES_DIR not found")  
412                 ELSE(NOT XERCES_LIB_DIR)
413                   
414                 INCLUDE_DIRECTORIES( ${XERCES_LIB_DIR}/include )                
415                 LINK_DIRECTORIES(  ${XERCES_LIB_DIR}/lib )
416                   
417                 ENDIF(NOT XERCES_LIB_DIR)       
418                 
419                 IF(USE_DEBUG_LIB)
420 #EED 2019-07-03                 set(XERCES_LIBRARIES  xerces-c_3D)
421                         set(XERCES_LIBRARIES  xerces-c)
422                 ELSE(USE_DEBUG_LIB)
423 #EED 2019-07-03                 set(XERCES_LIBRARIES  xerces-c_3)
424                         set(XERCES_LIBRARIES  xerces-c)
425                 ENDIF(USE_DEBUG_LIB)
426                 
427                 MARK_AS_ADVANCED(XERCES_LIB_DIR)
428         ENDIF(WIN32)
429
430
431         IF(UNIX)
432                 IF(APPLE)
433                         SET(XERCES_LIBRARIES xerces-c )
434                          INCLUDE_DIRECTORIES( /opt/local/include )
435                          LINK_DIRECTORIES(  /opt/local/lib ) 
436 #JCP 10/01/11                    
437                 ELSE(NOT APPLE) 
438                         SET(XERCES_LIBRARIES xerces-c )
439                          INCLUDE_DIRECTORIES( /usr/local/include )
440                          LINK_DIRECTORIES(  /usr/local/lib /usr/lib) 
441                         #FIND_PACKAGE(Xerces)
442                         # Use if found
443                         #IF(Xerces_FOUND)
444                          #  INCLUDE_DIRECTORIES( ${XERCES_INCLUDE_DIR} ) 
445                         #ENDIF(Xerces_FOUND)            
446                 ENDIF(APPLE)
447         ENDIF(UNIX)     
448   
449 ENDIF(USE_XERCES)
450
451
452 ENDMACRO(CREA_FIND_AND_USE_LIBRARIES)