]> Creatis software - crea.git/blob - cmake/CREAMacro_FindAndUseLibraries.cmake
#3374 creaBug New Normal - vtk8itk5wx3-mingw64
[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
100 IF(USE_ITK)
101   IF(NOT ITK_FOUND)
102     # Search ITK
103     FIND_PACKAGE(ITK)
104     # If itk found
105     IF(ITK_FOUND)
106       MESSAGE ( STATUS "=======================================")
107       MESSAGE ( STATUS "Looking for ITK... found")
108       MESSAGE ( STATUS "* Dir     = ${ITK_DIR}")
109       MESSAGE ( STATUS "* Version = ${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR}.${ITK_VERSION_PATCH}")
110       SET(SKIP_ITK_BUILD_SETTINGS_FILE ON)
111       INCLUDE(${ITK_USE_FILE})
112       CREA_DEFINE( USE_ITK )
113       CREA_DEFINE( _USE_ITK_ )
114                 If (${ITK_VERSION_MAJOR} MATCHES "4"  OR  ${ITK_VERSION_MAJOR} MATCHES "5"  )
115                         MESSAGE ( STATUS "* Version = ${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR}.${ITK_VERSION_PATCH}")
116                         SET(ITK_LIBRARIES ${ITK_LIBRARIES}) 
117                 ELSEIF()
118                         SET(ITK_LIBRARIES ITKCommon ITKIO ITKBasicFilters ITKAlgorithms)
119                 ENDIF()
120       MARK_AS_ADVANCED(ITK_DIR)
121     ELSE(ITK_FOUND)
122       message(FATAL_ERROR "ITK_DIR not found")
123     ENDIF(ITK_FOUND)
124   ENDIF(NOT ITK_FOUND)
125 ENDIF(USE_ITK)
126 #-----------------------------------------------------------------------------
127
128
129 #-----------------------------------------------------------------------------
130
131 IF(USE_GDCM)
132   IF (USE_GDCM2)
133     MESSAGE(ERROR "CANNOT USE BOTH gdcm AND gdcm2 !")
134   ENDIF (USE_GDCM2)
135
136   IF(NOT GDCM_FOUND)
137     # Search GDCM
138     FIND_PACKAGE(GDCM)
139     # If gdcm found
140     IF(GDCM_FOUND)
141       INCLUDE(${GDCM_USE_FILE})
142       CREA_DEFINE( USE_GDCM )
143
144       MESSAGE ( STATUS "=======================================")
145       MESSAGE ( STATUS "Looking for GDCM... found")
146       MESSAGE ( STATUS "* Dir       = ${GDCM_DIR}")
147       MESSAGE ( STATUS "* Version   = ${GDCM_MAJOR_VERSION}.${GDCM_MINOR_VERSION}.${GDCM_BUILD_VERSION}")
148       MESSAGE ( STATUS "* Namespace = ${GDCM_NAME_SPACE}")
149
150       # Test that GDCM_NAME_SPACE is **NOT** "gdcm" or will conflict with 
151       # embedded gdcm in ITK and will result in hard seg faults !
152       IF(USE_ITK)
153         IF (GDCM_NAME_SPACE STREQUAL "gdcm")
154           MESSAGE(FATAL_ERROR "GDCM_NAME_SPACE value is 'gdcm' which conflicts with ITK embededd gdcm namespace : rebuild gdcm with another GDCM_NAME_SPACE value")
155         ENDIF (GDCM_NAME_SPACE STREQUAL "gdcm")
156       ENDIF(USE_ITK)
157
158       MARK_AS_ADVANCED(GDCM_DIR)
159
160       SET(GDCM_LIBRARIES
161         ${GDCM_LIBRARIES} 
162         )
163
164       # TODO : Test that GDCM was built with option "vtkgdcm"
165       IF(USE_GDCM_VTK)
166         IF(USE_VTK)
167           SET(GDCM_LIBRARIES
168             ${GDCM_LIBRARIES}
169             vtkgdcm  
170             )
171         ENDIF(USE_VTK)
172       ENDIF(USE_GDCM_VTK)
173
174     ELSE(GDCM_FOUND)     
175           MESSAGE(FATAL_ERROR "GDCM not found....")
176     ENDIF(GDCM_FOUND)
177
178   ENDIF(NOT GDCM_FOUND)
179 ENDIF(USE_GDCM)
180
181 #-----------------------------------------------------------------------------
182
183 IF(USE_GDCM2)
184   IF (USE_GDCM)
185     MESSAGE(ERROR "CANNOT USE BOTH gdcm AND gdcm2 !")
186   ENDIF (USE_GDCM)
187
188 #  IF(NOT USE_ITK) # JPR : ITK vs GDCM (avoid cmake break)
189     # Search GDCM2
190
191     FIND_PACKAGE(GDCM REQUIRED)
192     INCLUDE(${GDCM_USE_FILE})
193
194       IF(NOT ${GDCM_MAJOR_VERSION} EQUAL 2)
195         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")
196       ENDIF(NOT ${GDCM_MAJOR_VERSION} EQUAL 2)
197       
198       CREA_DEFINE( USE_GDCM2 )
199           MARK_AS_ADVANCED(GDCM_DIR)
200       CREA_DEFINE_WITH_VAL( GDCM_NAME_SPACE gdcm )
201       
202       MESSAGE ( STATUS "=======================================")
203       MESSAGE ( STATUS "Looking for GDCM2... found")
204       MESSAGE ( STATUS "* Dir       = ${GDCM_DIR}")
205       MESSAGE ( STATUS "* Version   = ${GDCM_MAJOR_VERSION}.${GDCM_MINOR_VERSION}.${GDCM_BUILD_VERSION}")
206       MESSAGE ( STATUS "* Namespace = ${GDCM_NAME_SPACE}")
207       
208       # Test that GDCM_NAME_SPACE is **NOT** "gdcm" or will conflict with 
209       # embedded gdcm in ITK and will result in hard seg faults !
210                    INCLUDE_DIRECTORIES(${GDCM_INCLUDE_DIRS})     
211                         LINK_DIRECTORIES( ${GDCM_LIBRARY_DIRS}) 
212                         
213       SET(GDCM2_LIBRARIES
214         ${GDCM_LIBRARIES} 
215         )
216
217       IF(USE_GDCM_VTK)
218         IF(USE_VTK)
219                 IF(WIN32)
220                   SET(GDCM_LIBRARIES
221                         ${GDCM_LIBRARIES}
222                         vtkgdcm
223                         gdcmIOD
224                         gdcmMSFF
225                         gdcmexpat
226                         gdcmCommon
227                         gdcmMEXD
228                         gdcmexpat
229                         gdcmDSED
230                         gdcmDICT
231                         gdcmjpeg8
232                         gdcmjpeg12
233                         gdcmjpeg16
234                         socketxx
235                         gdcmopenjpeg
236                         gdcmcharls
237                      )
238                 ELSE(WIN32)
239                     SET(GDCM_LIBRARIES
240                         ${GDCM_LIBRARIES}
241                         vtkgdcm
242                         gdcmIOD
243                         )
244                 ENDIF(WIN32)
245                 
246         ENDIF(USE_VTK)
247       ENDIF(USE_GDCM_VTK)
248  # ENDIF(NOT USE_ITK) # JPR : ITK vs GDCM (avoid cmake break)
249
250 ENDIF(USE_GDCM2)
251
252 #-----------------------------------------------------------------------------
253
254 #-----------------------------------------------------------------------------
255
256 #-------------------- JFGA ---
257 IF(USE_WT)
258         MESSAGE (  "======================================= JFGA ------------USE WT CREAMacro_FindAndUseLibraries.cmake")
259         INCLUDE(${CREA_CMAKE_DIR}/CREAMacro_FindAndUseWt.cmake)
260         CREA_FINDANDUSEWT()
261 ENDIF(USE_WT)
262
263 #-----------------------------------------------------------------------------
264 IF(USE_WXWIDGETS)
265   IF(NOT wxWidgets_FOUND)
266         
267     INCLUDE(${CREA_CMAKE_DIR}/CREAMacro_FindAndUseWxWidgets.cmake)
268     CREA_FIND_WXWIDGETS(${USE_DEBUG_LIB})
269     CREA_USE_WXWIDGETS()
270         
271                 
272  
273   ENDIF(NOT wxWidgets_FOUND)
274 ENDIF(USE_WXWIDGETS)
275 #-----------------------------------------------------------------------------
276
277
278
279 #-----------------------------------------------------------------------------
280 IF(USE_DOXYGEN) 
281   IF(NOT DOXYGEN)
282     MESSAGE ( STATUS "=======================================")
283     FIND_PACKAGE(Doxygen REQUIRED)
284     #  MESSAGE(STATUS "Looking for doxygen... - found ${DOXYGEN}")
285     #  IF(DOXYGEN)
286     #    
287     #  ELSE(DOXYGEN)
288     #    MESSAGE(FATAL_ERROR "Doxygen not found. Required to build the doxygen documentation")
289   ENDIF(NOT DOXYGEN)
290 ENDIF(USE_DOXYGEN)
291 #-----------------------------------------------------------------------------
292
293
294 #-----------------------------------------------------------------------------
295 IF(USE_LATEX)
296         IF (NOT LATEX_COMPILER)
297                 FIND_PACKAGE(LATEX REQUIRED)
298                 MESSAGE ( STATUS "=======================================")
299                 MESSAGE(STATUS "Looking for latex... - found ${LATEX_COMPILER}")
300                 IF (NOT LATEX_FOUND)
301                    MESSAGE(FATAL_ERROR "LATEX_COMPILER NOT FOUND. Example:latex  (MacOS:/opt/local/bin/latex)")
302                 ENDIF (NOT LATEX_FOUND)
303         ENDIF (NOT LATEX_COMPILER)
304   
305 ENDIF(USE_LATEX) 
306 #-----------------------------------------------------------------------------
307
308 #-----------------------------------------------------------------------------
309 IF(USE_TTH) 
310   IF (NOT TTH_EXECUTABLE)
311     FIND_FILE( TTH_EXECUTABLE NAME tth tth.exe PATHS . $ENV{CREATIS}/tth_exe/ ~/Creatis/tth ~/Creatis/tth_linux $ENV{TTH}) 
312
313     IF (NOT TTH_EXECUTABLE)
314       MESSAGE(FATAL_ERROR "TTH not found (LATEX_tth_CONVERTER). Required to build the HTML documentation from tex source")
315     ELSE (NOT  TTH_EXECUTABLE)
316       MESSAGE ( STATUS "=======================================")
317       MESSAGE ( STATUS "Looking for tth... - found ${TTH_EXECUTABLE}")
318     ENDIF(NOT TTH_EXECUTABLE)
319     MARK_AS_ADVANCED( TTH_EXECUTABLE )
320   ENDIF(NOT TTH_EXECUTABLE)
321 ENDIF(USE_TTH)
322 #-----------------------------------------------------------------------------
323 #-----------------------------------------------------------------------------
324 IF(USE_BOOST)
325   IF(NOT Boost_FOUND)
326         add_definitions( -DBOOST_ALL_NO_LIB )
327         add_definitions( -DBOOST_ALL_DYN_LINK )
328         IF (MINGW)
329                 FIND_PACKAGE(Boost COMPONENTS filesystem-mgw71 system-mgw71 signals-mgw71 date_time-mgw71 thread-mgw71 regex-mgw71 program_options-mgw71 REQUIRED)
330         ELSE (MINGW)
331 #               FIND_PACKAGE(Boost COMPONENTS filesystem system signals date_time thread regex program_options REQUIRED)
332                 FIND_PACKAGE(Boost COMPONENTS filesystem system  date_time thread regex program_options REQUIRED)
333         ENDIF(MINGW)
334     IF(Boost_FOUND) 
335           ADD_DEFINITIONS(-DBOOST_FILESYSTEM_VERSION=3)
336           ADD_DEFINITIONS(-DBOOST_MAYOR_VERSION=${Boost_MAJOR_VERSION})
337           ADD_DEFINITIONS(-DBOOST_MINOR_VERSION=${Boost_MINOR_VERSION})
338       MESSAGE ( STATUS "=======================================")
339       MESSAGE ( STATUS "Looking for boost C++ library... - found in ${Boost_INCLUDE_DIR}")
340       INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})         
341           LINK_DIRECTORIES( ${Boost_LIBRARY_DIRS})
342           IF(WIN32)
343                 CREA_DEFINE( USE_BOOST )
344                 ADD_DEFINITIONS(-DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED)
345                 SET(BOOST_LIBRARIES
346                         ${Boost_LIBRARIES}
347                         )
348                         
349 # FCY with cmake boost, it's useless. 
350 # But if it is not working, uncomment   
351 #
352 #       IF(USE_DEBUG_LIB)
353 #                       SET(BOOST_LIBRARIES
354 #                               boost_signals-vc90-mt-gd-1_40
355 #                               boost_filesystem-vc90-mt-gd-1_40
356 #                               boost_date_time-vc90-mt-gd-1_40                    
357 #                          #what about boost_thread? JPR
358 #                       )
359 #               ELSE(NOT USE_DEBUG_LIB)
360 #                       SET(BOOST_LIBRARIES
361 #                               boost_signals-vc90-mt-1_40
362 #                               boost_filesystem-vc90-mt-1_40
363 #                               boost_date_time-vc90-mt-1_40
364 #                       )
365 #               ENDIF(USE_DEBUG_LIB)    
366           ENDIF(WIN32)
367       IF(NOT WIN32)
368
369                   SET(BOOST_LIBRARIES
370
371                         ${Boost_LIBRARIES}
372 #EED 10 Fev 2014
373 #EED                    boost_system-mt
374 #EED                    boost_thread-mt     
375 #EED                    boost_program_options-mt
376
377 #EED 03 mars 2011
378 #EED                    boost_signals-mt
379 #EED                    boost_filesystem-mt
380 #EED                    boost_date_time-mt
381 #EED                    boost_system-mt
382 #EED                    boost_program_options-mt
383 #EED                    boost_regex-mt
384 #EED                    boost_thread-mt     
385
386                         )
387       ENDIF(NOT WIN32)
388
389           MARK_AS_ADVANCED(Boost_INCLUDE_DIR)
390           MARK_AS_ADVANCED(Boost_LIBRARY_DIRS)
391      
392     ELSE(Boost_FOUND)
393       MESSAGE( STATUS "boost C++ library not found - Set Boost_INCLUDE_DIR to the directory containing boost headers")
394     ENDIF(Boost_FOUND)
395   ENDIF(NOT Boost_FOUND)
396  
397
398 ENDIF(USE_BOOST)
399 #-----------------------------------------------------------
400
401 IF(USE_XERCES)
402
403         # FIND xerces
404         IF(WIN32)
405         
406                 SET(XERCES_LIB_DIR $ENV{XERCES_DIR})
407         
408                 IF(NOT XERCES_LIB_DIR)  
409                   MESSAGE(FATAL_ERROR "XERCES_DIR not found")  
410                 ELSE(NOT XERCES_LIB_DIR)
411                   
412                 INCLUDE_DIRECTORIES( ${XERCES_LIB_DIR}/include )                
413                 LINK_DIRECTORIES(  ${XERCES_LIB_DIR}/lib )
414                   
415                 ENDIF(NOT XERCES_LIB_DIR)       
416                 
417                 IF(USE_DEBUG_LIB)
418 #EED 2019-07-03                 set(XERCES_LIBRARIES  xerces-c_3D)
419                         set(XERCES_LIBRARIES  xerces-c)
420                 ELSE(USE_DEBUG_LIB)
421 #EED 2019-07-03                 set(XERCES_LIBRARIES  xerces-c_3)
422                         set(XERCES_LIBRARIES  xerces-c)
423                 ENDIF(USE_DEBUG_LIB)
424                 
425                 MARK_AS_ADVANCED(XERCES_LIB_DIR)
426         ENDIF(WIN32)
427
428
429         IF(UNIX)
430                 IF(APPLE)
431                         SET(XERCES_LIBRARIES xerces-c )
432                          INCLUDE_DIRECTORIES( /opt/local/include )
433                          LINK_DIRECTORIES(  /opt/local/lib ) 
434 #JCP 10/01/11                    
435                 ELSE(NOT APPLE) 
436                         SET(XERCES_LIBRARIES xerces-c )
437                          INCLUDE_DIRECTORIES( /usr/local/include )
438                          LINK_DIRECTORIES(  /usr/local/lib /usr/lib) 
439                         #FIND_PACKAGE(Xerces)
440                         # Use if found
441                         #IF(Xerces_FOUND)
442                          #  INCLUDE_DIRECTORIES( ${XERCES_INCLUDE_DIR} ) 
443                         #ENDIF(Xerces_FOUND)            
444                 ENDIF(APPLE)
445         ENDIF(UNIX)     
446   
447 ENDIF(USE_XERCES)
448
449
450 ENDMACRO(CREA_FIND_AND_USE_LIBRARIES)