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