]> Creatis software - crea.git/blob - cmake/CREAMacro_FindAndUseLibraries.cmake
*** empty log message ***
[crea.git] / cmake / CREAMacro_FindAndUseLibraries.cmake
1
2
3 MACRO(CREA_FIND_AND_USE_LIBRARIES)
4
5 #-----------------------------------------------------------------------------
6 # If one can invoke this macro then crea has already been found !!
7 # However if one whishes to link against crea and crea was built 
8 # with wx or vtk then we have to find them.
9 # This USE_CREA var is made to resolve this dependency.
10 IF(USE_CREA)
11   IF(CREA_BUILT_WITH_WX)
12     SET(USE_WXWIDGETS ON)
13   ENDIF(CREA_BUILT_WITH_WX)
14   IF(CREA_BUILT_WITH_VTK)
15     SET(USE_VTK ON)
16   ENDIF(CREA_BUILT_WITH_VTK)
17 ENDIF(USE_CREA)
18 #-----------------------------------------------------------------------------
19
20
21 #-----------------------------------------------------------------------------
22 IF(USE_QT4)
23   IF(NOT QT_FOUND)      
24   
25         INCLUDE(${CREA_CMAKE_DIR}/CREAMacro_FindAndUseQt.cmake)
26         #FIND_PACKAGE(Qt4 REQUIRED)     
27         
28     IF(QT_FOUND)
29       MESSAGE ( STATUS "=======================================")
30       MESSAGE ( STATUS "Looking for QT4... found")
31       MESSAGE ( STATUS "* Inc Dir = ${QT_INCLUDE_DIR}")
32       MESSAGE ( STATUS "* Version = ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH}")
33       INCLUDE(${QT_USE_FILE})
34          
35       CREA_DEFINE( USE_QT )
36     #    SET(QT_LIBRARIES
37     #      ${QT_LIBRARIES}
38     #      ) 
39     #  MARK_AS_ADVANCED(Qt4_DIR)
40    ENDIF(QT_FOUND)
41   ENDIF(NOT QT_FOUND)
42 ENDIF(USE_QT4)
43 #-----------------------------------------------------------------------------
44
45 #-----------------------------------------------------------------------------
46 IF(USE_VTK)
47   INCLUDE(${CREA_CMAKE_DIR}/CREAMacro_FindAndUseVTK.cmake)
48   CREA_FIND_AND_USE_VTK()  
49 ENDIF(USE_VTK)
50 #-----------------------------------------------------------------------------
51
52 #-----------------------------------------------------------------------------
53 IF(USE_KWWIDGETS)
54   IF(NOT KWWidgets_FOUND)
55     # Search KWWidgets
56     FIND_PACKAGE(KWWidgets)
57     # If found
58     IF(KWWidgets_FOUND)
59       MESSAGE ( STATUS "=======================================")
60       MESSAGE ( STATUS "Looking for KWWidgets... found")
61       MESSAGE ( STATUS "* Dir     = ${KWWidgets_DIR}")
62       MESSAGE ( STATUS "* Version = ${KWWidgets_MAJOR_VERSION}.${KWWidgets_MINOR_VERSION}.${KWWidgets_BUILD_VERSION}")
63       IF (USE_VTK)
64          # KWWidgets must not search again for vtk !
65         SET(KWWidgets_NO_USE_VTK ON)
66       ENDIF (USE_VTK)
67
68       INCLUDE(${KWWidgets_USE_FILE})
69       CREA_DEFINE( USE_KWWIDGETS )
70       SET(KWWIDGETS_LIBRARIES
71         ${KWWidgets_LIBRARIES}
72         ) 
73       MARK_AS_ADVANCED(KWWidgets_DIR)
74     ELSE(KWWidgets_FOUND)
75       message(FATAL_ERROR "KWWidgets_DIR not found")
76     ENDIF(KWWidgets_FOUND)
77   ENDIF(NOT KWWidgets_FOUND)
78 ENDIF(USE_KWWIDGETS)
79 #-----------------------------------------------------------------------------
80
81
82
83 #-----------------------------------------------------------------------------
84 IF(USE_ITK)
85   IF(NOT ITK_FOUND)
86     # Search ITK
87     FIND_PACKAGE(ITK)
88     # If itk found
89     IF(ITK_FOUND)
90       MESSAGE ( STATUS "=======================================")
91       MESSAGE ( STATUS "Looking for ITK... found")
92       MESSAGE ( STATUS "* Dir     = ${ITK_DIR}")
93       MESSAGE ( STATUS "* Version = ${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR}.${ITK_VERSION_PATCH}")
94       SET(SKIP_ITK_BUILD_SETTINGS_FILE ON)
95       INCLUDE(${ITK_USE_FILE})
96       CREA_DEFINE( USE_ITK )
97       CREA_DEFINE( _USE_ITK_ )
98       SET(ITK_LIBRARIES
99         ITKCommon ITKIO ITKBasicFilters ITKAlgorithms
100         )  
101       MARK_AS_ADVANCED(ITK_DIR)
102     ELSE(ITK_FOUND)
103       message(FATAL_ERROR "ITK_DIR not found")
104     ENDIF(ITK_FOUND)
105   ENDIF(NOT ITK_FOUND)
106 ENDIF(USE_ITK)
107 #-----------------------------------------------------------------------------
108
109
110 #-----------------------------------------------------------------------------
111 IF(USE_GDCM)
112   IF (USE_GDCM2)
113     MESSAGE(ERROR "CANNOT USE BOTH gdcm AND gdcm2 !")
114   ENDIF (USE_GDCM2)
115
116   IF(NOT GDCM_FOUND)
117     # Search GDCM
118     FIND_PACKAGE(GDCM)
119     # If gdcm found
120     IF(GDCM_FOUND)
121       INCLUDE(${GDCM_USE_FILE})
122       CREA_DEFINE( USE_GDCM )
123       
124       MESSAGE ( STATUS "=======================================")
125       MESSAGE ( STATUS "Looking for GDCM... found")
126       MESSAGE ( STATUS "* Dir       = ${GDCM_DIR}")
127       MESSAGE ( STATUS "* Version   = ${GDCM_MAJOR_VERSION}.${GDCM_MINOR_VERSION}.${GDCM_BUILD_VERSION}")
128       MESSAGE ( STATUS "* Namespace = ${GDCM_NAME_SPACE}")
129       
130       # Test that GDCM_NAME_SPACE is **NOT** "gdcm" or will conflict with 
131       # embedded gdcm in ITK and will result in hard seg faults !
132       IF(USE_ITK)
133         IF (GDCM_NAME_SPACE STREQUAL "gdcm")
134           MESSAGE(FATAL_ERROR "GDCM_NAME_SPACE value is 'gdcm' which conflicts with ITK embededd gdcm namespace : rebuild gdcm with another GDCM_NAME_SPACE value")
135         ENDIF (GDCM_NAME_SPACE STREQUAL "gdcm")
136       ENDIF(USE_ITK)
137       
138       MARK_AS_ADVANCED(GDCM_DIR)
139       
140       SET(GDCM_LIBRARIES
141         ${GDCM_LIBRARIES} 
142         )
143       
144       # TODO : Test that GDCM was built with option "vtkgdcm"
145       IF(USE_GDCM_VTK)
146         IF(USE_VTK)
147           SET(GDCM_LIBRARIES
148             ${GDCM_LIBRARIES}
149             vtkgdcm  
150             )
151         ENDIF(USE_VTK)
152       ENDIF(USE_GDCM_VTK)
153       
154     ENDIF(GDCM_FOUND)
155   ENDIF(NOT GDCM_FOUND)
156 ENDIF(USE_GDCM)
157
158 #-----------------------------------------------------------------------------
159
160 #-----------------------------------------------------------------------------
161 IF(USE_GDCM2)
162   IF(NOT GDCM_FOUND)
163     # Search GDCM2
164     FIND_PACKAGE(GDCM)
165     # If gdcm found
166     IF(GDCM_FOUND)
167       INCLUDE(${GDCM_USE_FILE})
168       
169       IF(NOT ${GDCM_MAJOR_VERSION} EQUAL 2)
170         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")
171       ENDIF(NOT ${GDCM_MAJOR_VERSION} EQUAL 2)
172       
173       CREA_DEFINE( USE_GDCM2 )
174       CREA_DEFINE_WITH_VAL( GDCM_NAME_SPACE gdcm )
175       
176       MESSAGE ( STATUS "=======================================")
177       MESSAGE ( STATUS "Looking for GDCM2... found")
178       MESSAGE ( STATUS "* Dir       = ${GDCM_DIR}")
179       MESSAGE ( STATUS "* Version   = ${GDCM_MAJOR_VERSION}.${GDCM_MINOR_VERSION}.${GDCM_BUILD_VERSION}")
180       MESSAGE ( STATUS "* Namespace = ${GDCM_NAME_SPACE}")
181       
182       # Test that GDCM_NAME_SPACE is **NOT** "gdcm" or will conflict with 
183       # embedded gdcm in ITK and will result in hard seg faults !
184       IF(USE_ITK)
185         IF (GDCM_NAME_SPACE STREQUAL "gdcm")
186           MESSAGE(FATAL_ERROR "GDCM_NAME_SPACE value is 'gdcm' which conflicts with ITK embededd gdcm namespace : rebuild gdcm with another GDCM_NAME_SPACE value")
187         ENDIF (GDCM_NAME_SPACE STREQUAL "gdcm")
188       ENDIF(USE_ITK)
189       
190       MARK_AS_ADVANCED(GDCM_DIR)
191       
192       SET(GDCM_LIBRARIES
193         ${GDCM_LIBRARIES} 
194         )
195       
196       # TODO : Test that GDCM was built with option "vtkgdcm"
197       IF(USE_GDCM_VTK)
198         IF(USE_VTK)
199           SET(GDCM_LIBRARIES
200             ${GDCM_LIBRARIES}
201             vtkgdcm  
202             )
203         ENDIF(USE_VTK)
204       ENDIF(USE_GDCM_VTK)
205       
206     ENDIF(GDCM_FOUND)
207   ENDIF(NOT GDCM_FOUND)
208 ENDIF(USE_GDCM2)
209
210 #-----------------------------------------------------------------------------
211
212 #-----------------------------------------------------------------------------
213 IF(USE_WXWIDGETS)
214   IF(NOT wxWidgets_FOUND)
215     INCLUDE(${CREA_CMAKE_DIR}/CREAMacro_FindAndUseWxWidgets.cmake)
216     CREA_FIND_WXWIDGETS()
217     CREA_USE_WXWIDGETS()
218   ENDIF(NOT wxWidgets_FOUND)
219 ENDIF(USE_WXWIDGETS)
220 #-----------------------------------------------------------------------------
221
222
223
224 #-----------------------------------------------------------------------------
225 IF(USE_DOXYGEN) 
226   IF(NOT DOXYGEN)
227     MESSAGE ( STATUS "=======================================")
228     FIND_PACKAGE(Doxygen REQUIRED)
229     #  MESSAGE(STATUS "Looking for doxygen... - found ${DOXYGEN}")
230     #  IF(DOXYGEN)
231     #    
232     #  ELSE(DOXYGEN)
233     #    MESSAGE(FATAL_ERROR "Doxygen not found. Required to build the doxygen documentation")
234   ENDIF(NOT DOXYGEN)
235 ENDIF(USE_DOXYGEN)
236 #-----------------------------------------------------------------------------
237
238
239 #-----------------------------------------------------------------------------
240 IF(USE_LATEX)   
241         IF (NOT LATEX_COMPILER)
242                 FIND_PACKAGE(LATEX REQUIRED)
243                 MESSAGE ( STATUS "=======================================")
244                 MESSAGE(STATUS "Looking for latex... - found ${LATEX_COMPILER}")
245         ENDIF (NOT LATEX_COMPILER)
246   
247 ENDIF(USE_LATEX) 
248 #-----------------------------------------------------------------------------
249
250 #-----------------------------------------------------------------------------
251 IF(USE_TTH) 
252   IF (NOT TTH_EXECUTABLE)
253     FIND_FILE( TTH_EXECUTABLE NAME tth tth.exe PATHS . $ENV{CREATIS}/tth_exe/ ~/Creatis/tth ~/Creatis/tth_linux $ENV{TTH}) 
254
255     IF (NOT TTH_EXECUTABLE)
256       MESSAGE(FATAL_ERROR "TTH not found (LATEX_tth_CONVERTER). Required to build the HTML documentation from tex source")
257     ELSE (NOT  TTH_EXECUTABLE)
258       MESSAGE ( STATUS "=======================================")
259       MESSAGE ( STATUS "Looking for tth... - found ${TTH_EXECUTABLE}")
260     ENDIF(NOT TTH_EXECUTABLE)
261     MARK_AS_ADVANCED( TTH_EXECUTABLE )
262   ENDIF(NOT TTH_EXECUTABLE)
263 ENDIF(USE_TTH)
264 #-----------------------------------------------------------------------------
265
266 #-----------------------------------------------------------------------------
267 IF(USE_BOOST)
268   IF(NOT Boost_FOUND)
269   
270     find_package( Boost 1.37.0 COMPONENTS signals date_time filesystem system )
271
272    IF(Boost_FOUND)
273         MESSAGE ( STATUS "=======================================")
274         MESSAGE ( STATUS "Looking for boost C++ library... - found in ${Boost_INCLUDE_DIR}")
275         INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})       
276         LINK_DIRECTORIES( ${Boost_LIBRARY_DIRS} )
277            #target_link_libraries(${Boost_LIBRARIES})
278          ELSE(Boost_FOUND)
279         MESSAGE(FATAL_ERROR "boost C++ library not found - Set Boost_INCLUDE_DIR to the directory containing boost headers")
280      ENDIF(Boost_FOUND)  
281       # CREA_DEFINE( USE_BOOST )
282 #      include_directories(${Boost_INCLUDE_DIRS})
283   #    add_executable(foo foo.cc)
284  #     target_link_libraries(foo ${Boost_LIBRARIES})
285   # endif()
286  
287     # FIND_PACKAGE(Boost REQUIRED)
288     # IF(Boost_FOUND)
289       # MESSAGE ( STATUS "=======================================")
290       # MESSAGE ( STATUS "Looking for boost C++ library... - found in ${Boost_INCLUDE_DIR}")
291       # INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})       
292       # LINK_DIRECTORIES( ${Boost_LIBRARY_DIRS} )
293            
294       # CREA_DEFINE( USE_BOOST )
295           # IF(WIN32)
296                 
297                 # LINK_DIRECTORIES( ${Boost_INCLUDE_DIRS}/stage/lib) #JCP 01/10/2009
298                 # #LINK_DIRECTORIES( ${Boost_LIBRARY_DIRS})
299                 # #MESSAGE ("EED " ${Boost_LIBRARY_DIRS})
300                 # #libboost_signals-vc71-mt-1_37
301                 # #libboost_filesystem-vc71-mt-1_37
302                 # #boost_date_time-vc71-mt-1_37
303         
304                 # #message("creamacro find and use lib = ${Boost_SIGNALS_LIBRARY}")
305                 # SET(BOOST_LIBRARIES
306                                 # boost_signals-vc90-mt-1_40
307                 # boost_filesystem-vc90-mt-1_40
308                 # boost_date_time-vc90-mt-1_40
309                    
310                    # #what about boost_thread? JPR
311             # )
312           # ENDIF(WIN32)
313       # IF(NOT WIN32)
314         # IF(APPLE)
315                   # SET(BOOST_LIBRARIES
316                         # boost_signals
317                         # boost_filesystem
318                                 # boost_date_time
319                         # boost_program_options
320                         # boost_regex
321                         # boost_thread
322                         # )
323         # ELSE(NOT APPLE)
324                   # SET(BOOST_LIBRARIES
325                         # boost_signals-mt
326                         # boost_filesystem-mt
327                         # boost_date_time-mt
328                                 # boost_system-mt
329                         # boost_program_options-mt
330                         # boost_regex-mt
331                         # boost_thread-mt           
332                         # )
333         # ENDIF(APPLE)  
334       # ENDIF(NOT WIN32)
335           
336       # MARK_AS_ADVANCED(Boost_INCLUDE_DIR)
337     # ELSE(Boost_FOUND)
338       # MESSAGE(FATAL_ERROR "boost C++ library not found - Set Boost_INCLUDE_DIR to the directory containing boost headers")
339     # ENDIF(Boost_FOUND)
340   ENDIF(NOT Boost_FOUND)
341 ENDIF(USE_BOOST)
342 #-----------------------------------------------------------------------------
343
344
345 ENDMACRO(CREA_FIND_AND_USE_LIBRARIES)