]> Creatis software - clitk.git/blob - vv/CMakeLists.txt
Improve code reading in the CMakeLists.txt
[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
114 if(vv_QT_VERSION VERSION_GREATER "4")
115   find_package(Qt5Widgets REQUIRED)
116   find_package(Qt5Network REQUIRED)
117   find_package(Qt5Designer REQUIRED)
118 else()
119   find_package(Qt4 REQUIRED)
120 endif()
121
122 if(vv_QT_VERSION VERSION_GREATER "4")
123   link_directories(${QT5Widgets_LIBRARIES})
124   link_directories(${QT5Network_LIBRARIES})
125   link_directories(${QT5Designer_LIBRARIES})
126 else()
127   link_directories(${QT_LIBRARY_DIR})
128 endif()
129
130 if(vv_QT_VERSION VERSION_GREATER "4")
131   qt5_wrap_cpp(vv_SRCS
132     vvMainWindowBase.h
133     QTreePushButton.h
134     vvDocumentation.h
135     vvHelpDialog.h
136     vvQDicomSeriesSelector.h
137     vvSlicerManager.h
138     vvSlicer.h
139     vvStructureSetActor.h
140     vvROIActor.h
141     vvToolCreatorBase.h
142     )
143 else()
144   QT4_WRAP_CPP(vv_SRCS
145     vvMainWindowBase.h
146     QTreePushButton.h
147     vvDocumentation.h
148     vvHelpDialog.h
149     vvQDicomSeriesSelector.h
150     vvSlicerManager.h
151     vvStructureSetActor.h
152     vvROIActor.h
153     vvToolCreatorBase.h
154     )
155 endif()
156
157 if(vv_QT_VERSION VERSION_GREATER "4")
158   qt5_wrap_ui(vv_UI_CXX
159     qt_ui/vvHelpDialog.ui
160     qt_ui/vvDocumentation.ui
161     qt_ui/vvDicomSeriesSelector.ui
162     qt_ui/vvDummyWindow.ui #For testing
163     )
164 else()
165   QT4_WRAP_UI(vv_UI_CXX
166     qt_ui/vvHelpDialog.ui
167     qt_ui/vvDocumentation.ui
168     qt_ui/vvDicomSeriesSelector.ui
169     qt_ui/vvDummyWindow.ui #For testing
170     )
171 endif()
172
173 if(vv_QT_VERSION VERSION_GREATER "4")
174   QT5_add_resources(vv_SRCS vvIcons.qrc)
175 else()
176   QT4_ADD_RESOURCES(vv_SRCS vvIcons.qrc)
177 endif()
178   
179   # Add the autotools in the header vvToolsList.h for initialization of the dummy
180   # variables in vv.cxx for the tools contained in vvLib
181   if(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt IS_NEWER_THAN ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h)
182     file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h)
183     foreach(tool ${vv_TOOLS})
184       file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h "#include \"${tool}.h\"\n")
185       file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h "extern const vvToolCreator<${tool}> *dummy${tool};\n")
186       file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h "const vvToolCreator<${tool}> *dummy${tool}2 = dummy${tool};\n\n")
187     endforeach(tool)
188   endif(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt IS_NEWER_THAN ${CMAKE_CURRENT_BINARY_DIR}/vvToolsList.h)
189   
190   # Add the autotools and the common files ui
191   foreach(tool ${vv_TOOLS} ${vv_COMMON_WITH_UI})
192       set(vv_SRCS ${vv_SRCS} ${tool}.cxx)
193       if(vv_QT_VERSION VERSION_GREATER "4")
194         QT5_WRAP_CPP(vv_SRCS ${tool}.h)
195         QT5_WRAP_UI(vv_UI_CXX qt_ui/${tool}.ui)
196       else()
197         QT4_WRAP_CPP(vv_SRCS ${tool}.h)
198         QT4_WRAP_UI(vv_UI_CXX qt_ui/${tool}.ui)
199       endif()
200   endforeach(tool)
201   
202   # Add the common source files
203   foreach(tool ${vv_COMMON})
204       set(vv_SRCS ${vv_SRCS} ${tool}.cxx)
205       if(vv_QT_VERSION VERSION_GREATER "4")
206         QT5_WRAP_CPP(vv_SRCS ${tool}.h)
207       else()
208         QT4_WRAP_CPP(vv_SRCS ${tool}.h)
209       endif()
210   endforeach(tool)
211   
212   # if Windows and Qt was built as a static lib then don't set QT_DLL flag
213   set(QT_STATIC 0)
214   if(WIN32)
215     if(vv_QT_VERSION VERSION_GREATER "4")
216       if(EXISTS ${Qt5Widgets_LIBRARIES}/QtCore.prl)
217         file(READ ${Qt5Widgets_LIBRARIES}/QtCore.prl QT_CORE_PRL)
218         if(${QT_CORE_PRL} MATCHES "static")
219           set(QT_STATIC 1)
220         endif(${QT_CORE_PRL} MATCHES "static")
221       endif(EXISTS ${Qt5Widgets_LIBRARIES}/QtCore.prl)
222     else()
223       if(EXISTS ${QT_LIBRARY_DIR}/QtCore.prl)
224         file(READ ${QT_LIBRARY_DIR}/QtCore.prl QT_CORE_PRL)
225         if(${QT_CORE_PRL} MATCHES "static")
226           set(QT_STATIC 1)
227         endif(${QT_CORE_PRL} MATCHES "static")
228       endif(EXISTS ${QT_LIBRARY_DIR}/QtCore.prl)
229     endif()
230   endif(WIN32)
231   if(NOT QT_STATIC)
232     add_definitions(-DQT_DLL)
233   endif(NOT QT_STATIC)
234
235   add_definitions(-DQT_THREAD_SUPPORT)
236   if(vv_QT_VERSION VERSION_GREATER "4")
237     include_directories(
238       ${Qt5Widgets_INCLUDE_DIRS}
239       ${Qt5Gui_INCLUDE_DIRS}
240       ${Qt5Core_INCLUDE_DIRS}
241       ${Qt5Network_INCLUDE_DIRS}
242       ${Qt5Designer_INCLUDE_DIRS}
243       ${CMAKE_CURRENT_BINARY_DIR}
244       ${CMAKE_CURRENT_SOURCE_DIR}
245     )
246   else()
247     include_directories(
248       ${QT_INCLUDES}
249       ${QT_INCLUDE_DIR}
250       ${QT_QTGUI_INCLUDE_DIR}
251       ${QT_QTCORE_INCLUDE_DIR}
252       ${CMAKE_CURRENT_BINARY_DIR}
253       ${CMAKE_CURRENT_SOURCE_DIR}
254     )
255   endif()
256 #=========================================================
257
258 #=========================================================
259 #support for parallel deformable registration with OpenMP
260 if(NOT APPLE)
261 if(CMAKE_COMPILER_IS_GNUCC)
262   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
263 endif(CMAKE_COMPILER_IS_GNUCC)
264 endif(NOT APPLE)
265 #=========================================================
266
267 #=========================================================
268 include_directories(
269   ../common
270   ../tools
271   ../segmentation
272   )
273
274 #=========================================================
275 #Add each tool's dependencies
276 foreach(tool ${vv_TOOLS})
277   set(toolLibs ${toolLibs} ${${tool}_LIBS})
278 endforeach(tool)
279
280 #=========================================================
281 #Add Foundation Libraries (this should be after our libraries, since we depend
282 #on them)
283 if(vv_QT_VERSION VERSION_GREATER "4")
284 set(foundationLibraries clitkCommon ${ITK_LIBRARIES} ${VTK_LIBRARIES})
285 else()
286 set(foundationLibraries clitkCommon ${ITK_LIBRARIES} QVTK vtkHybrid)
287 endif()
288
289 #=========================================================
290 # Use CxImage to create animated gifs
291 if(CLITK_EXPERIMENTAL)
292   set(vvCxImage clitkCxImage)
293   set(vv_SRCS ${vv_SRCS} vvAnimatedGIFWriter.cxx)
294   include_directories(${CLITK_SOURCE_DIR}/utilities/CxImage)
295   add_subdirectory(${CLITK_SOURCE_DIR}/utilities/CxImage ${PROJECT_BINARY_DIR}/utilities/CxImage)
296 endif(CLITK_EXPERIMENTAL)
297 #=========================================================
298
299 #-----------------------------------------------------------------------------
300 # Avoid linker bug in Mac OS 10.5
301 # See http://wiki.finkproject.org/index.php/Fink:Packaging:Preparing_for_10.5#OpenGL_Bug
302 #
303 if(APPLE)
304   find_library(CoreFoundation_LIBRARY CoreFoundation REQUIRED)
305   find_library(ApplicationServices_LIBRARY ApplicationServices REQUIRED)
306   find_library(SystemConfiguration_LIBRARY SystemConfiguration REQUIRED)
307   find_library(Security_LIBRARY Security REQUIRED)
308   set(APPLE_FRAMEWORKS ${CoreFoundation_LIBRARY}
309     ${ApplicationServices_LIBRARY}
310     ${SystemConfiguration_LIBRARY}
311     ${Security_LIBRARY}
312     )
313   message(STATUS "===== ${APPLE_FRAMEWORKS}")
314 endif()
315 #=========================================================
316 #Create binary and libs for tests
317 if(vv_QT_VERSION VERSION_GREATER "4")
318 set(vvExternalLibs clitkSegmentationGgoLib ${toolLibs} ${foundationLibraries} ${vvCxImage} Qt5::Widgets Qt5::Network Qt5::Designer ${APPLE_FRAMEWORKS})
319 else()
320 set(vvExternalLibs clitkSegmentationGgoLib ${toolLibs} ${foundationLibraries} ${vvCxImage} ${QT_LIBRARIES} ${QT_QTNETWORK_LIBRARY} ${APPLE_FRAMEWORKS})
321 endif()
322 # QtNetwork is required by vvRegisterForm
323
324 #-----------------------------------------------------------------------------
325 # For retina displays, see
326 # http://public.kitware.com/pipermail/vtkusers/2015-February/090117.html
327 if(APPLE)
328   set(vv_SRCS ${vv_SRCS} vvOSXHelper.mm)
329 endif()
330
331 add_library(vvLib ${vv_SRCS} ${vv_UI_CXX})
332 target_link_libraries(vvLib ${vvExternalLibs})
333
334 if(WIN32)
335   add_executable(vv WIN32 vv.cxx vvIcon.rc)
336 else(WIN32)
337   add_executable(vv vv.cxx)
338 endif(WIN32)
339
340 target_link_libraries(vv vvLib)
341
342 #=========================================================
343 # Install options (also used by CPack)
344 install(TARGETS vv DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE)
345
346 #=========================================================
347
348 #=========================================================
349 # CPack options
350 set(CPACK_PACKAGE_NAME "vv")
351 set(CPACK_SOURCE_PACKAGE_FILE_NAME "vv-src")
352 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "vv, the 4D slicer : let's jump into a new dimension !")
353 set(CPACK_PACKAGE_VENDOR "Creatis-CLB")
354 set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/ReadMe.txt")
355 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
356 set(CPACK_PACKAGE_VERSION_MAJOR "1")
357 set(CPACK_PACKAGE_VERSION_MINOR "3")
358 set(CPACK_PACKAGE_VERSION_PATCH "0")
359 if(NIGHTLY)
360   set(CPACK_PACKAGE_INSTALL_DIRECTORY "vv-nightly")
361 else(NIGHTLY)
362   set(CPACK_PACKAGE_INSTALL_DIRECTORY "vv")
363 endif(NIGHTLY)
364 set(CPACK_STRIP_FILES TRUE)
365
366 if(WIN32)
367   # There is a bug in NSI that does not handle full unix paths properly. Make
368   # sure there is at least one set of four (4) backlasshes.
369   set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\icons\\\\ducky.ico")
370   set(CPACK_NSIS_INSTALLED_ICON_NAME "vv.exe")
371 if(NIGHTLY)
372   set(CPACK_NSIS_DISPLAY_NAME "vv - The 4D slicer (nightly)")
373 else(NIGHTLY)
374   set(CPACK_NSIS_DISPLAY_NAME "vv - The 4D slicer")
375 endif(NIGHTLY)
376   set(CPACK_NSIS_HELP_LINK "http://www.creatis.insa-lyon.fr/rio/vv")
377   set(CPACK_NSIS_URL_INFO_ABOUT "http://www.creatis.insa-lyon.fr/rio")
378   set(CPACK_NSIS_CONTACT "vv@creatis.insa-lyon.fr")
379   set(CPACK_NSIS_CREATE_ICONS_EXTRA "CreateShortCut \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\vv.lnk\\\" \\\"$INSTDIR\\\\bin\\\\vv.exe\\\" ")
380   set(CPACK_NSIS_DELETE_ICONS_EXTRA "Delete \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\vv.lnk\\\" ")
381   #set(CPACK_NSIS_MODIFY_PATH ON) SR: buggy, wait for cmake updates for a fix
382   #set(CPACK_BINARY_ZIP ON)
383 else(WIN32)
384   set(CPACK_GENERATOR "STGZ")
385   set(CPACK_SOURCE_GENERATOR "TGZ")
386 endif(WIN32)
387 include(CPack)
388 #=========================================================
389 #=========================================================
390 configure_file(vvConfiguration.h.in vvConfiguration.h)
391 #=========================================================