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