External_VTK.cmake 5.81 KB
Newer Older
1
2
3
4
#-----------------------------------------------------------------------------
# Get and build VTK
#

5
6
7
8
# Sanity checks
if(DEFINED VTK_DIR AND NOT EXISTS ${VTK_DIR})
  message(FATAL_ERROR "VTK_DIR variable is defined but corresponds to non-existing directory")
endif()
9

10
11
12
if(DEFINED VTK_SOURCE_DIR AND NOT EXISTS ${VTK_SOURCE_DIR})
  message(FATAL_ERROR "VTK_SOURCE_DIR variable is defined but corresponds to non-existing directory")
endif()
13

14
set(proj VTK)
15

16
if(NOT DEFINED VTK_DIR OR NOT DEFINED VTK_SOURCE_DIR)
17
#  message(STATUS "Adding project:${proj}")
18

19
20
  set(VTK_WRAP_TCL OFF)
  set(VTK_WRAP_PYTHON OFF)
21

22
  if(Slicer_USE_KWWIDGETS)
23
24
25
26
27
    list(APPEND VTK_DEPENDENCIES tcl)
    if (NOT WIN32)
      list(APPEND VTK_DEPENDENCIES tk)
    endif(NOT WIN32)
    set(VTK_WRAP_TCL ON)
28
  endif()
29

30
  if (Slicer_USE_PYTHONQT)
31
32
    set(VTK_WRAP_PYTHON ON)
    list(APPEND VTK_DEPENDENCIES python)
33
  endif()
34
35

  set(VTK_PYTHON_ARGS)
36
  if(Slicer_USE_PYTHON OR Slicer_USE_PYTHONQT)
37
    set(VTK_PYTHON_ARGS
38
      -DPYTHON_EXECUTABLE:PATH=${slicer_PYTHON_EXECUTABLE}
39
40
      -DPYTHON_INCLUDE_DIR:PATH=${slicer_PYTHON_INCLUDE}
      -DPYTHON_LIBRARY:FILEPATH=${slicer_PYTHON_LIBRARY}
41
      )
42
  endif()
43

44
45
46
  # On Mac, since:
  #    - Qt can't be build with X11 support
  #    - KWWidgets only support X11
47
  # the case where both Slicer_USE_QT and Slicer_USE_KWWIDGETS are ON is *NOT* supported
48

49
50
  set(VTK_QT_ARGS)
  if(NOT APPLE)
51
    if(Slicer_USE_QT)
52
53
54
55
56
57
58
      set(VTK_QT_ARGS
        -DDESIRED_QT_VERSION:STRING=4
        -DVTK_USE_GUISUPPORT:BOOL=ON
        -DVTK_USE_QVTK_QTOPENGL:BOOL=ON
        -DVTK_USE_QT:BOOL=ON
        -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
        )
59
    endif()
60
  else()
61
    if(Slicer_USE_KWWIDGETS AND NOT Slicer_USE_QT)
62
63
64
65
66
67
68
69
70
71
72
73
      set(VTK_QT_ARGS
        -DCMAKE_SHARED_LINKER_FLAGS:STRING="-Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib"
        -DCMAKE_EXE_LINKER_FLAGS:STRING="-Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib"
        -DOPENGL_INCLUDE_DIR:PATH=/usr/X11R6/include
        -DVTK_USE_CARBON:BOOL=OFF
        -DVTK_USE_COCOA:BOOL=OFF
        -DVTK_USE_X:BOOL=ON
        -DVTK_USE_RPATH:BOOL=ON
        -DVTK_USE_GUISUPPORT:BOOL=OFF
        -DVTK_USE_QVTK_QTOPENGL:BOOL=OFF
        -DVTK_USE_QT:BOOL=OFF
        )
74
    elseif(NOT Slicer_USE_KWWIDGETS AND Slicer_USE_QT)
75
76
77
78
79
80
81
82
83
84
85
      set(VTK_QT_ARGS
        -DVTK_USE_CARBON:BOOL=OFF
        -DVTK_USE_COCOA:BOOL=ON # Default to Cocoa, VTK/CMakeLists.txt will enable Carbon and disable cocoa if needed
        -DVTK_USE_X:BOOL=OFF
        -DVTK_USE_RPATH:BOOL=ON
        -DDESIRED_QT_VERSION:STRING=4
        -DVTK_USE_GUISUPPORT:BOOL=ON
        -DVTK_USE_QVTK_QTOPENGL:BOOL=ON
        -DVTK_USE_QT:BOOL=ON
        -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}
        )
86
87
    elseif(Slicer_USE_KWWIDGETS AND Slicer_USE_QT)
      MESSAGE(FATAL_ERROR "Case where Slicer_USE_QT and Slicer_USE_KWWIDGETS are ON is not supported on MAC")
88
    endif()
89
90
  endif()

91
  # Disable Tk when Python wrapping is enabled
92
  if (Slicer_USE_PYTHONQT)
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
    list(APPEND VTK_QT_ARGS -DVTK_USE_TK:BOOL=OFF)
  endif()

  set(slicer_TCL_LIB)
  set(slicer_TK_LIB)
  set(slicer_TCLSH)
  set(VTK_TCL_ARGS)
  if(VTK_WRAP_TCL)
    if(WIN32)
      set(slicer_TCL_LIB ${CMAKE_BINARY_DIR}/tcl-build/lib/tcl84.lib)
      set(slicer_TK_LIB ${CMAKE_BINARY_DIR}/tcl-build/lib/tk84.lib)
      set(slicer_TCLSH ${CMAKE_BINARY_DIR}/tcl-build/bin/tclsh.exe)
    elseif(APPLE)
      set(slicer_TCL_LIB ${CMAKE_BINARY_DIR}/tcl-build/lib/libtcl8.4.dylib)
      set(slicer_TK_LIB ${CMAKE_BINARY_DIR}/tcl-build/lib/libtk8.4.dylib)
      set(slicer_TCLSH ${CMAKE_BINARY_DIR}/tcl-build/bin/tclsh84)
    else()
      set(slicer_TCL_LIB ${CMAKE_BINARY_DIR}/tcl-build/lib/libtcl8.4.so)
      set(slicer_TK_LIB ${CMAKE_BINARY_DIR}/tcl-build/lib/libtk8.4.so)
      set(slicer_TCLSH ${CMAKE_BINARY_DIR}/tcl-build/bin/tclsh84)
    endif()
    set(VTK_TCL_ARGS
      -DTCL_INCLUDE_PATH:PATH=${CMAKE_BINARY_DIR}/tcl-build/include
      -DTK_INCLUDE_PATH:PATH=${CMAKE_BINARY_DIR}/tcl-build/include
      -DTCL_LIBRARY:FILEPATH=${slicer_TCL_LIB}
      -DTK_LIBRARY:FILEPATH=${slicer_TK_LIB}
      -DTCL_TCLSH:FILEPATH=${slicer_TCLSH}
      )
  endif()
  
123
124
125
126
127
  set(VTK_BUILD_STEP "")
  if(UNIX)
    configure_file(SuperBuild/vtk_build_step.cmake.in
      ${CMAKE_CURRENT_BINARY_DIR}/vtk_build_step.cmake
      @ONLY)
128
    set(VTK_BUILD_STEP ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/vtk_build_step.cmake)
129
130
  endif()
  
131
132
133
  ExternalProject_Add(${proj}
    SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
    BINARY_DIR ${proj}-build
134
135
    GIT_REPOSITORY "${git_protocol}://${Slicer_VTK_GIT_REPOSITORY}"
    GIT_TAG ${Slicer_VTK_GIT_TAG}
136
137
    CMAKE_GENERATOR ${gen}
    CMAKE_ARGS
jcfr's avatar
jcfr committed
138
139
140
      ${ep_common_args}
      -DBUILD_EXAMPLES:BOOL=OFF
      -DBUILD_SHARED_LIBS:BOOL=ON
141
142
      -DCMAKE_CXX_FLAGS:STRING=${ep_common_cxx_flags}
      -DCMAKE_C_FLAGS:STRING=${ep_common_c_flags}
143
      -DVTK_USE_PARALLEL:BOOL=ON
144
      -DVTK_DEBUG_LEAKS:BOOL=${Slicer_USE_VTK_DEBUG_LEAKS}
145
146
147
148
      -DVTK_WRAP_TCL:BOOL=${VTK_WRAP_TCL}
      -DVTK_USE_RPATH:BOOL=ON
      ${VTK_TCL_ARGS}
      -DVTK_WRAP_PYTHON:BOOL=${VTK_WRAP_PYTHON}
149
      -DVTK_INSTALL_PYTHON_USING_CMAKE:BOOL=ON
150
      -DVTK_INSTALL_LIB_DIR:PATH=${Slicer_INSTALL_LIB_DIR}
151
152
153
      ${VTK_PYTHON_ARGS}
      ${VTK_QT_ARGS}
      ${VTK_MAC_ARGS}
154
    BUILD_COMMAND ${VTK_BUILD_STEP}
155
    INSTALL_COMMAND ""
156
157
    DEPENDS 
      ${VTK_DEPENDENCIES}
158
159
160
    )
  set(VTK_DIR ${CMAKE_BINARY_DIR}/${proj}-build)
  set(VTK_SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj})
161
162
163
164

else()
  # The project is provided using VTK_DIR and VTK_SOURCE_DIR, nevertheless since other 
  # project may depend on VTK, let's add an 'empty' one
jcfr's avatar
jcfr committed
165
  SlicerMacroEmptyExternalProject(${proj} "${VTK_DEPENDENCIES}")
166
endif()