]> Creatis software - clitk.git/blob - vv/CMakeLists.txt
Ensure the compilation with Qt4 and Qt5
[clitk.git] / vv / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.4)
2
3 #=========================================================
4 # To avoid warning with some version
5 if(COMMAND cmake_policy)
6   cmake_policy(SET CMP0003 NEW)
7   #cmake_policy(SET CMP0007 NEW)
8 endif(COMMAND cmake_policy)
9 #=========================================================
10
11
12 #=========================================================
13 #List of vv tools to compile
14 set(vv_TOOLS
15   vvToolMedianFilter
16   vvToolRigidReg
17   vvToolCropImage
18   vvToolBinarize
19   vvToolImageArithm
20   vvToolResample
21   vvToolMIP
22   vvToolConvert ## with dummy vvToolConvert.ui
23   vvToolROIManager
24   vvToolSegmentation
25   vvToolProfile
26   ## these ones are for tests (not working)
27   # vvToolTest
28   # vvToolFoo
29   # vvToolFooWithWidgetBase
30   # vvToolPlastimatch
31   # vvToolConnectedComponentLabeling
32   ## these ones are old ones
33   # vvToolExtractPatient
34   # vvToolExtractLung
35   # vvToolStructureSetManager
36 )
37 # dependencies of the tools
38 # Future issues : when tool depend on other tools ... how to manage that ?
39 #  >> add the relevant $_LIBS variable to the tool that has dependencies?
40 set(vvToolBinarize_LIBS clitkBinarizeImageLib)
41 set(vvToolProfile_LIBS clitkProfileImageLib)
42 set(vvToolResample_LIBS clitkResampleImageLib)
43 set(vvToolConvert_LIBS clitkImageConvertLib)
44 set(vvToolExtractPatient_LIBS clitkSegmentationGgoLib)
45 set(vvToolExtractLung_LIBS clitkSegmentationGgoLib)
46 set(vvToolCropImage_LIBS clitkCropImageLib)
47 set(vvToolMIP_LIBS clitkMIPLib)
48 set(vvToolMedianFilter_LIBS clitkMedianImageFilterLib)
49 set(vvToolImageArithm_LIBS clitkImageArithmImageLib)
50 set(vvToolROIManager_LIBS clitkDicomRTStruct)
51
52 #=========================================================
53 # List of vv source files
54
55 # in COMMON_WITH_UI -> must have .h and .cxx and .ui
56 set(vv_COMMON_WITH_UI
57   vvInfoPanel
58   vvMainWindow
59   vvLinkPanel
60   vvOverlayPanel
61   vvLandmarksPanel
62   vvProgressDialog
63   vvSegmentationDialog
64   vvSurfaceViewerDialog
65   vvDeformationDialog
66   vvStructSelector
67   vvIntensityValueSlider
68   vvLabelImageLoaderWidget
69   vvToolWidgetBase
70   vvToolSimpleInputSelectorWidget
71   vvToolInputSelectorWidget
72   vvRegisterForm
73 )
74
75 # All others sources
76 set(vv_SRCS
77   vvQProgressDialogITKCommand.cxx
78   vvQDicomSeriesSelector.cxx
79   QTreePushButton.cxx
80   vvMainWindowBase.cxx
81   vvImageWarp.cxx
82   vvDeformableRegistration.cxx
83   vtkVOXImageWriter.cxx
84   vvInteractorStyleNavigator.cxx
85   vvSlicer.cxx
86   vvLandmarks.cxx
87   vvLandmarksGlyph.cxx
88   vvClipPolyData.cxx
89   vvGlyphSource.cxx
90   vvGlyph2D.cxx
91   vvSlicerManager.cxx
92   vvSlicerManagerCommand.cxx
93   vvUtils.cxx
94 #  vvMaximumIntensityProjection.cxx
95   vvMesh.cxx
96   vvMeshActor.cxx
97   vvMeshReader.cxx
98   vvMidPosition.cxx
99   vvImageContour.cxx
100   vvBinaryImageOverlayActor.cxx
101   vvStructureSetActor.cxx
102   vvSaveState.cxx
103   vvReadState.cxx
104   vvROIActor.cxx
105   vvBlendImageActor.cxx
106   vvToolManager.cxx
107   vvToolCreatorBase.cxx
108   vvToolBaseBase.cxx
109 )
110
111 #=========================================================
112 # Qt related commands
113 if(vv_QT_VERSION VERSION_GREATER "4")
114 find_package(Qt5Widgets REQUIRED)
115 find_package(Qt5Network REQUIRED)
116 find_package(Qt5Designer REQUIRED)
117 link_directories(${QT5Widgets_LIBRARIES})
118 link_directories(${QT5Network_LIBRARIES})
119 link_directories(${QT5Designer_LIBRARIES})
120
121 qt5_wrap_cpp(vv_SRCS
122   vvMainWindowBase.h
123   QTreePushButton.h
124   vvDocumentation.h
125   vvHelpDialog.h
126   vvQDicomSeriesSelector.h
127   vvSlicerManager.h
128   vvStructureSetActor.h
129   vvROIActor.h
130   vvToolCreatorBase.h
131   )
132
133 qt5_wrap_ui(vv_UI_CXX
134   qt_ui/vvHelpDialog.ui
135   qt_ui/vvDocumentation.ui
136   qt_ui/vvDicomSeriesSelector.ui
137   qt_ui/vvDummyWindow.ui #For testing
138   )
139
140 QT5_add_resources(vv_SRCS vvIcons.qrc)
141
142 # Add the autotools in the header vvToolsList.h for initialization of the dummy
143 # variables in vv.cxx for the tools contained in vvLib
144 if(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt IS_NEWER_THAN ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h)
145   file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h)
146   foreach(tool ${vv_TOOLS})
147     file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h "#include \"${tool}.h\"\n")
148     file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h "extern const vvToolCreator<${tool}> *dummy${tool};\n")
149     file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h "const vvToolCreator<${tool}> *dummy${tool}2 = dummy${tool};\n\n")
150   endforeach(tool)
151 endif(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt IS_NEWER_THAN ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h)
152
153 # Add the autotools and the common files ui
154 foreach(tool ${vv_TOOLS} ${vv_COMMON_WITH_UI})
155     set(vv_SRCS ${vv_SRCS} ${tool}.cxx)
156     QT5_WRAP_CPP(vv_SRCS ${tool}.h)
157     QT5_WRAP_UI(vv_UI_CXX qt_ui/${tool}.ui)
158 endforeach(tool)
159
160 # Add the common source files
161 foreach(tool ${vv_COMMON})
162     set(vv_SRCS ${vv_SRCS} ${tool}.cxx)
163     QT5_WRAP_CPP(vv_SRCS ${tool}.h)
164 endforeach(tool)
165
166 # if Windows and Qt was built as a static lib then don't set QT_DLL flag
167 set(QT_STATIC 0)
168 if(WIN32)
169   if(EXISTS ${Qt5Widgets_LIBRARIES}/QtCore.prl)
170     file(READ ${Qt5Widgets_LIBRARIES}/QtCore.prl QT_CORE_PRL)
171     if(${QT_CORE_PRL} MATCHES "static")
172       set(QT_STATIC 1)
173     endif(${QT_CORE_PRL} MATCHES "static")
174   endif(EXISTS ${Qt5Widgets_LIBRARIES}/QtCore.prl)
175 endif(WIN32)
176 if(NOT QT_STATIC)
177   add_definitions(-DQT_DLL)
178 endif(NOT QT_STATIC)
179
180 add_definitions(-DQT_THREAD_SUPPORT)
181
182 include_directories(
183   ${Qt5Widgets_INCLUDE_DIRS}
184   ${Qt5GUI_INCLUDE_DIRS}
185   ${Qt5CORE_INCLUDE_DIRS}
186   ${Qt5Network_INCLUDE_DIRS}
187   ${Qt5Designer_INCLUDE_DIRS}
188   ${CMAKE_CURRENT_BINARY_DIR}
189   ${CMAKE_CURRENT_SOURCE_DIR}
190 )
191 else()
192 find_package(Qt4 REQUIRED)
193 link_directories(${QT_LIBRARY_DIR})
194
195
196 QT4_WRAP_CPP(vv_SRCS
197   vvMainWindowBase.h
198   QTreePushButton.h
199   vvDocumentation.h
200   vvHelpDialog.h
201   vvQDicomSeriesSelector.h
202   vvSlicerManager.h
203   vvStructureSetActor.h
204   vvROIActor.h
205   vvToolCreatorBase.h
206   )
207
208 QT4_WRAP_UI(vv_UI_CXX
209   qt_ui/vvHelpDialog.ui
210   qt_ui/vvDocumentation.ui
211   qt_ui/vvDicomSeriesSelector.ui
212   qt_ui/vvDummyWindow.ui #For testing
213   )
214
215 QT4_ADD_RESOURCES(vv_SRCS vvIcons.qrc)
216
217 # Add the autotools in the header vvToolsList.h for initialization of the dummy
218 # variables in vv.cxx for the tools contained in vvLib
219 if(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt IS_NEWER_THAN ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h)
220   file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h)
221   foreach(tool ${vv_TOOLS})
222     file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h "#include \"${tool}.h\"\n")
223     file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h "extern const vvToolCreator<${tool}> *dummy${tool};\n")
224     file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h "const vvToolCreator<${tool}> *dummy${tool}2 = dummy${tool};\n\n")
225   endforeach(tool)
226 endif(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt IS_NEWER_THAN ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h)
227
228 # Add the autotools and the common files ui
229 foreach(tool ${vv_TOOLS} ${vv_COMMON_WITH_UI})
230     set(vv_SRCS ${vv_SRCS} ${tool}.cxx)
231     QT4_WRAP_CPP(vv_SRCS ${tool}.h)
232     QT4_WRAP_UI(vv_UI_CXX qt_ui/${tool}.ui)
233 endforeach(tool)
234
235 # Add the common source files
236 foreach(tool ${vv_COMMON})
237     set(vv_SRCS ${vv_SRCS} ${tool}.cxx)
238     QT4_WRAP_CPP(vv_SRCS ${tool}.h)
239 endforeach(tool)
240
241 # if Windows and Qt was built as a static lib then don't set QT_DLL flag
242 set(QT_STATIC 0)
243 if(WIN32)
244   if(EXISTS ${QT_LIBRARY_DIR}/QtCore.prl)
245     file(READ ${QT_LIBRARY_DIR}/QtCore.prl QT_CORE_PRL)
246     if(${QT_CORE_PRL} MATCHES "static")
247       set(QT_STATIC 1)
248     endif(${QT_CORE_PRL} MATCHES "static")
249   endif(EXISTS ${QT_LIBRARY_DIR}/QtCore.prl)
250 endif(WIN32)
251 if(NOT QT_STATIC)
252   add_definitions(-DQT_DLL)
253 endif(NOT QT_STATIC)
254
255 add_definitions(-DQT_THREAD_SUPPORT)
256
257 include_directories(
258   ${QT_INCLUDES}
259   ${QT_INCLUDE_DIR}
260   ${QT_QTGUI_INCLUDE_DIR}
261   ${QT_QTCORE_INCLUDE_DIR}
262   ${CMAKE_CURRENT_BINARY_DIR}
263   ${CMAKE_CURRENT_SOURCE_DIR}
264 )
265 endif()
266 #=========================================================
267
268 #=========================================================
269 #support for parallel deformable registration with OpenMP
270 if(NOT APPLE)
271 if(CMAKE_COMPILER_IS_GNUCC)
272   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
273 endif(CMAKE_COMPILER_IS_GNUCC)
274 endif(NOT APPLE)
275 #=========================================================
276
277 #=========================================================
278 include_directories(
279   ../common
280   ../tools
281   ../segmentation
282   )
283
284 #=========================================================
285 #Add each tool's dependencies
286 foreach(tool ${vv_TOOLS})
287   set(toolLibs ${toolLibs} ${${tool}_LIBS})
288 endforeach(tool)
289
290 #=========================================================
291 #Add Foundation Libraries (this should be after our libraries, since we depend
292 #on them)
293 if(vv_QT_VERSION VERSION_GREATER "4")
294 set(foundationLibraries clitkCommon ${ITK_LIBRARIES} ${VTK_LIBRARIES})
295 else()
296 set(foundationLibraries clitkCommon ${ITK_LIBRARIES} QVTK vtkHybrid)
297 endif()
298
299 #=========================================================
300 # Use CxImage to create animated gifs
301 if(CLITK_EXPERIMENTAL)
302   set(vvCxImage clitkCxImage)
303   set(vv_SRCS ${vv_SRCS} vvAnimatedGIFWriter.cxx)
304   include_directories(${CLITK_SOURCE_DIR}/utilities/CxImage)
305   add_subdirectory(${CLITK_SOURCE_DIR}/utilities/CxImage ${PROJECT_BINARY_DIR}/utilities/CxImage)
306 endif(CLITK_EXPERIMENTAL)
307 #=========================================================
308
309 #-----------------------------------------------------------------------------
310 # Avoid linker bug in Mac OS 10.5
311 # See http://wiki.finkproject.org/index.php/Fink:Packaging:Preparing_for_10.5#OpenGL_Bug
312 #
313 if(APPLE)
314   find_library(CoreFoundation_LIBRARY CoreFoundation REQUIRED)
315   find_library(ApplicationServices_LIBRARY ApplicationServices REQUIRED)
316   find_library(SystemConfiguration_LIBRARY SystemConfiguration REQUIRED)
317   find_library(Security_LIBRARY Security REQUIRED)
318   set(APPLE_FRAMEWORKS ${CoreFoundation_LIBRARY}
319     ${ApplicationServices_LIBRARY}
320     ${SystemConfiguration_LIBRARY}
321     ${Security_LIBRARY}
322     )
323   message(STATUS "===== ${APPLE_FRAMEWORKS}")
324 endif()
325 #=========================================================
326 #Create binary and libs for tests
327 if(vv_QT_VERSION VERSION_GREATER "4")
328 set(vvExternalLibs clitkSegmentationGgoLib ${toolLibs} ${foundationLibraries} ${vvCxImage} Qt5::Widgets Qt5::Network Qt5::Designer ${APPLE_FRAMEWORKS})
329 else()
330 set(vvExternalLibs clitkSegmentationGgoLib ${toolLibs} ${foundationLibraries} ${vvCxImage} ${QT_LIBRARIES} ${QT_QTNETWORK_LIBRARY} ${APPLE_FRAMEWORKS})
331 endif()
332 # QtNetwork is required by vvRegisterForm
333
334 add_library(vvLib ${vv_SRCS} ${vv_UI_CXX})
335 target_link_libraries(vvLib ${vvExternalLibs})
336
337 if(WIN32)
338   add_executable(vv WIN32 vv.cxx vvIcon.rc)
339 else(WIN32)
340   add_executable(vv vv.cxx)
341 endif(WIN32)
342
343 target_link_libraries(vv vvLib)
344
345 #=========================================================
346 # Install options (also used by CPack)
347 install(TARGETS vv DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE)
348
349 #=========================================================
350
351 #=========================================================
352 # CPack options
353 set(CPACK_PACKAGE_NAME "vv")
354 set(CPACK_SOURCE_PACKAGE_FILE_NAME "vv-src")
355 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "vv, the 4D slicer : let's jump into a new dimension !")
356 set(CPACK_PACKAGE_VENDOR "Creatis-CLB")
357 set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/ReadMe.txt")
358 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
359 set(CPACK_PACKAGE_VERSION_MAJOR "1")
360 set(CPACK_PACKAGE_VERSION_MINOR "3")
361 set(CPACK_PACKAGE_VERSION_PATCH "0")
362 if(NIGHTLY)
363   set(CPACK_PACKAGE_INSTALL_DIRECTORY "vv-nightly")
364 else(NIGHTLY)
365   set(CPACK_PACKAGE_INSTALL_DIRECTORY "vv")
366 endif(NIGHTLY)
367 set(CPACK_STRIP_FILES TRUE)
368
369 if(WIN32)
370   # There is a bug in NSI that does not handle full unix paths properly. Make
371   # sure there is at least one set of four (4) backlasshes.
372   set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\icons\\\\ducky.ico")
373   set(CPACK_NSIS_INSTALLED_ICON_NAME "vv.exe")
374 if(NIGHTLY)
375   set(CPACK_NSIS_DISPLAY_NAME "vv - The 4D slicer (nightly)")
376 else(NIGHTLY)
377   set(CPACK_NSIS_DISPLAY_NAME "vv - The 4D slicer")
378 endif(NIGHTLY)
379   set(CPACK_NSIS_HELP_LINK "http://www.creatis.insa-lyon.fr/rio/vv")
380   set(CPACK_NSIS_URL_INFO_ABOUT "http://www.creatis.insa-lyon.fr/rio")
381   set(CPACK_NSIS_CONTACT "vv@creatis.insa-lyon.fr")
382   set(CPACK_NSIS_CREATE_ICONS_EXTRA "CreateShortCut \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\vv.lnk\\\" \\\"$INSTDIR\\\\bin\\\\vv.exe\\\" ")
383   set(CPACK_NSIS_DELETE_ICONS_EXTRA "Delete \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\vv.lnk\\\" ")
384   #set(CPACK_NSIS_MODIFY_PATH ON) SR: buggy, wait for cmake updates for a fix
385   #set(CPACK_BINARY_ZIP ON)
386 else(WIN32)
387   set(CPACK_GENERATOR "STGZ")
388   set(CPACK_SOURCE_GENERATOR "TGZ")
389 endif(WIN32)
390 include(CPack)
391 #=========================================================
392 #=========================================================
393 configure_file(vvConfiguration.h.in vvConfiguration.h)
394 #=========================================================