CMakeLists.txt 15 KB
Newer Older
1
project(Slicer3)
2
3
4
5
6

cmake_minimum_required(VERSION 2.6)
if(COMMAND cmake_policy)
  cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
7
mark_as_advanced(CMAKE_BACKWARDS_COMPATIBILITY)
8

9
#-----------------------------------------------------------------------------
10
#
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
set(Slicer3_INSTALL_BIN_DIR "bin")
set(Slicer3_INSTALL_LIB_DIR "lib/Slicer3")
set(Slicer3_INSTALL_INCLUDE_DIR "include/Slicer3")
set(Slicer3_INSTALL_SHARE_DIR "share/Slicer3")
set(Slicer3_INSTALL_ITKFACTORIES_DIR "${Slicer3_INSTALL_LIB_DIR}/ITKFactories")

set(Slicer3_INSTALL_PLUGINS_BIN_DIR "${Slicer3_INSTALL_LIB_DIR}/Plugins")
set(Slicer3_INSTALL_PLUGINS_LIB_DIR "${Slicer3_INSTALL_LIB_DIR}/Plugins")
set(Slicer3_INSTALL_PLUGINS_INCLUDE_DIR "${Slicer3_INSTALL_INCLUDE_DIR}/Plugins")
set(Slicer3_INSTALL_PLUGINS_SHARE_DIR "${Slicer3_INSTALL_SHARE_DIR}/Plugins")
set(Slicer3_INSTALL_PLUGINS_CACHE_DIR "${Slicer3_INSTALL_LIB_DIR}/PluginsCache")

set(Slicer3_INSTALL_MODULES_BIN_DIR "${Slicer3_INSTALL_LIB_DIR}/Modules")
set(Slicer3_INSTALL_MODULES_LIB_DIR "${Slicer3_INSTALL_LIB_DIR}/Modules")
set(Slicer3_INSTALL_MODULES_INCLUDE_DIR "${Slicer3_INSTALL_INCLUDE_DIR}/Modules")
set(Slicer3_INSTALL_MODULES_SHARE_DIR "${Slicer3_INSTALL_SHARE_DIR}/Modules")

set(Slicer3_HOME "${Slicer3_BINARY_DIR}")

#-----------------------------------------------------------------------------
31
32
# Disable the warnings that DevStudio 2005 emits wrt to sprintf, strcpu, etc.
#
33
34
35
if(CMAKE_COMPILER_2005)
  add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
endif(CMAKE_COMPILER_2005)
36

37
# include a test for endianness (used to be done by default)
barre's avatar
barre committed
38

39
40
41
42
include(${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
test_big_endian(CMAKE_WORDS_BIGENDIAN)

#-----------------------------------------------------------------------------
43
44
45
46
# avoid linker bug in Mac OS 10.5
# see:
# http://wiki.finkproject.org/index.php/Fink:Packaging:Preparing_for_10.5#OpenGL_Bug
#
47
48
49
50
if(APPLE)
  set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib")
  set(CMAKE_EXE_LINKER_FLAGS "-Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib")
endif(APPLE)
51

52
53
#-----------------------------------------------------------------------------
# Slicer version number.
54
#
55
set(Slicer3_VERSION_MAJOR "3")
56
set(Slicer3_VERSION_MINOR "3")
57
58
59
60
61
if(NOT Slicer3_VERSION_PATCH)
  set(Slicer3_VERSION_PATCH "0")
endif(NOT Slicer3_VERSION_PATCH)
set(Slicer3_VERSION "${Slicer3_VERSION_MAJOR}.${Slicer3_VERSION_MINOR}")
set(Slicer3_VERSION_FULL "${Slicer3_VERSION}.${Slicer3_VERSION_PATCH}")
62

63
64
#-----------------------------------------------------------------------------
# Build shared lib by default
65
#
66
67
option(BUILD_SHARED_LIBS "Build Slicer3 with shared libraries." ON)

68
69
#-----------------------------------------------------------------------------
# Slicer3 macros
pieper's avatar
pieper committed
70
#
71
72
73
74
75
set(Slicer3_CMAKE_DIR "${Slicer3_SOURCE_DIR}/CMake" CACHE INTERNAL "")
add_subdirectory(CMake)
# Make sure VTK_CMAKE_DIR is at the beginning so that VTK's FindTCL is
# used before CMake's FindTCL.
set(CMAKE_MODULE_PATH "${VTK_CMAKE_DIR}" ${CMAKE_MODULE_PATH} "${Slicer3_CMAKE_DIR}")
pieper's avatar
pieper committed
76

77
include("${Slicer3_CMAKE_DIR}/Slicer3PersistenceMacros.cmake")
hliu's avatar
hliu committed
78

79
80
#-----------------------------------------------------------------------------
# Top level slicer3 configurations
81
#
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin")
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin")
mark_as_advanced(
  LIBRARY_OUTPUT_PATH
  EXECUTABLE_OUTPUT_PATH
)

# Do NOT force into the cache, as plugins need to override locally and scoping
# becomes an issue.
#set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin/ 
#  CACHE PATH "Single output directory for building all libraries." FORCE)
#set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin/ 
#  CACHE PATH "Single output directory for building all executables." FORCE)

#-----------------------------------------------------------------------------
# Slicer include and libraries subdirectory
98
#
99
100
101
slicer3_set_persistent_property(Slicer3_Libs_LIBRARIES "")
slicer3_set_persistent_property(Slicer3_Base_LIBRARIES "")
slicer3_set_persistent_property(Slicer3_Modules_LIBRARIES "")
102

103
104
105
slicer3_set_persistent_property(Slicer3_Libs_INCLUDE_DIRS "")
slicer3_set_persistent_property(Slicer3_Base_INCLUDE_DIRS "")
slicer3_set_persistent_property(Slicer3_Modules_INCLUDE_DIRS "")
pieper's avatar
pieper committed
106

107
#-----------------------------------------------------------------------------
pieper's avatar
pieper committed
108
# Add the testing directories
109
#
110
111
112
113
114
115
116
117
option(BUILD_TESTING "Test the project" ON)
set(Slicer3_BUILD_TESTING ${BUILD_TESTING})
set(LAUNCH_EXE ${Slicer3_BINARY_DIR}/Slicer3 --launch)
if(Slicer3_BUILD_TESTING)
  enable_testing()
  include(CTest)
  mark_as_advanced(TCL_TCLSH DART_ROOT)
endif(Slicer3_BUILD_TESTING)
hliu's avatar
hliu committed
118

119
#-----------------------------------------------------------------------------
120
121
122
123
124
# Libs
# - ITK
# - KWWidgets (pulls in VTK)
#

125
126
127
128
129
130
131
132
133
# Relax some constraints related to the build settings file. This was
# preventing people from using the same compiler but with a different generator,
# or just the same compiler installed in a non-standard location.

set(SKIP_KWWidgets_BUILD_SETTINGS_FILE 1)
set(SKIP_VTK_BUILD_SETTINGS_FILE 1)
set(SKIP_ITK_BUILD_SETTINGS_FILE 1)
set(SKIP_TEEM_BUILD_SETTINGS_FILE 1)
 
134
## Python
135
136
option(Slicer3_USE_PYTHON "Integrate a python interpreter into Slicer." OFF)
if(Slicer3_USE_PYTHON)
137
  find_package(PythonLibs)
138
endif(Slicer3_USE_PYTHON)
139

140
## ITK
141
142
143
144
145
find_package(ITK REQUIRED)
if(NOT ITK_FOUND)
  message(FATAL_ERROR "Need ITK to build")
endif(NOT ITK_FOUND)
include(${ITK_USE_FILE})
146
147

## KWWidgets
148
149
150
151
152
find_package(KWWidgets REQUIRED)
if(NOT KWWidgets_FOUND)
  message(FATAL_ERROR "Need KWWidgets to build")
endif(NOT KWWidgets_FOUND)
include(${KWWidgets_USE_FILE})
153

154
## Teem
155
156
find_package(TEEM REQUIRED)
if(NOT TEEM_FOUND)
157
  message(FATAL_ERROR "Need TEEM to build")
158
159
endif(NOT TEEM_FOUND)
include(${TEEM_USE_FILE})
160

161
162
163
164
165
166
## SlicerLibCurl
find_package(SLICERLIBCURL REQUIRED)
if(SLICERLIBCURL_FOUND)
  include(${SLICERLIBCURL_USE_FILE})
endif(SLICERLIBCURL_FOUND)
 
167
168
169
## BatchMake
option(Slicer3_USE_BatchMake "Build Slicer3 with BatchMake support." OFF)
if(Slicer3_USE_BatchMake)
170
171
  find_package(BatchMake REQUIRED)
  include(${BatchMake_USE_FILE})
172
endif(Slicer3_USE_BatchMake)
173

174
175
## MIDAS
option(Slicer3_USE_MIDAS "Build Slicer3 with MIDAS support." OFF)
176

177
178
179
## NaviTrack 
option(Slicer3_USE_NAVITRACK "Build Slicer3 with NaviTrack support." OFF)
if(Slicer3_USE_NAVITRACK)
180
  find_library(NAVITRACK_LIB 
181
    NAMES NaviTrack
182
    PATHS ${NAVITRACK_LIB_DIR} 
183
184
185
186
    )
  if(NAVITRACK_LIB-NOTFOUND)
    message(FATAL_ERROR "Need NaviTrack to build")
  endif(NAVITRACK_LIB-NOTFOUND)
187
  # include file for OpenTracker 2.0 
188
  find_path(NAVITRACK_INC "OpenTracker/OpenTracker.h" 
189
    ${NAVITRACK_INC_DIR}
190
191
192
193
    )
  if(NAVITRACK_INC-NOTFOUND)
    message(FATAL_ERROR "Need OpenTracker.h to build")
  endif(NAVITRACK_INC-NOTFOUND)
194
else(Slicer3_USE_NAVITRACK)
195
196
  set(NAVITRACK_LIB "")
  set(NAVITRACK_INC "")
197
endif(Slicer3_USE_NAVITRACK)
hliu's avatar
hliu committed
198

199
200
201
## IGSTK (Built in Slicer3-lib)
option(Slicer3_USE_IGSTK "Build Slicer3 with IGSTK support." OFF)
if(Slicer3_USE_IGSTK)
202
203
  find_package(IGSTK REQUIRED)
  include(${IGSTK_USE_FILE})
204
endif(Slicer3_USE_IGSTK)
hliu's avatar
hliu committed
205

206
207
208
209
210
211
212
213
214
215
216
217
218
#-----------------------------------------------------------------------------
# Need some Tcl/Tk info

include("${VTK_CMAKE_DIR}/vtkTclTkMacros.cmake")
VTK_GET_TCL_TK_VERSION(TCL_TK_MAJOR_VERSION TCL_TK_MINOR_VERSION)
set(TCL_TK_VERSION_DOT "${TCL_TK_MAJOR_VERSION}.${TCL_TK_MINOR_VERSION}")
set(TCL_TK_VERSION "${TCL_TK_MAJOR_VERSION}${TCL_TK_MINOR_VERSION}")

include("${KWWidgets_CMAKE_DIR}/KWWidgetsTclTkMacros.cmake")
incr_tcl_get_version(INCR_TCL_MAJOR_VERSION INCR_TCL_MINOR_VERSION)
set(INCR_TCL_VERSION_DOT "${INCR_TCL_MAJOR_VERSION}.${INCR_TCL_MINOR_VERSION}")
set(INCR_TCL_VERSION "${INCR_TCL_MAJOR_VERSION}${INCR_TCL_MINOR_VERSION}")

219
#-----------------------------------------------------------------------------
barre's avatar
barre committed
220
221
222
# Generate the default setup paths scripts.
# Generate some useful scripts that can be used to setup various environment 
# variables and launch the executable properly against external packages.
223
#
224
include("${KWWidgets_CMAKE_DIR}/KWWidgetsPathsMacros.cmake")
225
226
227
228
229
230
231
232
set(extra_dirs
  "${TEEM_DIR}/bin"
  "${BatchMake_DIR}/bin"
  "${Slicer3_HOME}/${Slicer3_INSTALL_PLUGINS_BIN_DIR}"
  "${Slicer3_HOME}/${Slicer3_INSTALL_PLUGINS_LIB_DIR}"
  "${Slicer3_HOME}/${Slicer3_INSTALL_MODULES_BIN_DIR}"
  "${Slicer3_HOME}/${Slicer3_INSTALL_MODULES_LIB_DIR}"
  )
233
kwwidgets_generate_setup_paths_scripts(
234
235
236
  "${EXECUTABLE_OUTPUT_PATH}" "Slicer3SetupPaths"
  "${extra_dirs}"
)
barre's avatar
barre committed
237

238
#-----------------------------------------------------------------------------
barre's avatar
barre committed
239
240
241
242
243
# VTK 5.0 does not have VTK_CMAKE_DIR
# Alternatively you could use KWWidget's wrapping, which encapsulate
# the differences between various VTK versions:
#  INCLUDE("${KWWidgets_CMAKE_DIR}/KWWidgetsWrappingMacros.cmake")
#  KWWidgets_WRAP_TCL(${LIB_NAME} LIB_TCL_SRCS "${LIB_SRCS}" "")
244
#
245
246
247
248
if(NOT VTK_CMAKE_DIR)
  set(VTK_CMAKE_DIR "${VTK_SOURCE_DIR}/CMake")
endif(NOT VTK_CMAKE_DIR)
include("${VTK_CMAKE_DIR}/vtkWrapTcl.cmake")
249

250
251
#-----------------------------------------------------------------------------
# Check versions of VTK to track CVS HEAD
252
#
253
254
255
256
257
258
259
find_package(VTK REQUIRED)
if(EXISTS ${VTK_CMAKE_DIR}/VTKVersionMacros.cmake)
  include(${VTK_CMAKE_DIR}/VTKVersionMacros.cmake)
else(EXISTS ${VTK_CMAKE_DIR}/VTKVersionMacros.cmake)
  #MESSAGE("Using local version of VTKVersionMacros for compatibility.")
  include(${Slicer3_SOURCE_DIR}/Scripts/VTKVersionMacros.cmake)
endif(EXISTS ${VTK_CMAKE_DIR}/VTKVersionMacros.cmake)
260

261
262
263
264
vtk_get_source_revision_and_date(VTKsource_revision VTKsource_date)
if(VTKsource_revision LESS 1.2196)
  message(FATAL_ERROR "Sorry, your VTK library was last updated on ${VTKsource_date}. Its source revision, according to vtkKWWidgetsVersion.h, is ${VTKsource_revision}. Please update to a newer revision.")
endif(VTKsource_revision LESS 1.2196) 
265

266
267
#-----------------------------------------------------------------------------
# These packages may exist within the Slicer3 source tree
lorensen's avatar
lorensen committed
268
#
269
270
271
272
273
274
set(GenerateCLP_DIR ${Slicer3_BINARY_DIR}/Libs/GenerateCLP)
set(GenerateLM_DIR ${Slicer3_BINARY_DIR}/Libs/GenerateLM)
set(ModuleDescriptionParser_DIR ${Slicer3_BINARY_DIR}/Libs/ModuleDescriptionParser)
set(LoadableModule_DIR ${Slicer3_BINARY_DIR}/Libs/LoadableModule)
set(vtkITK_DIR ${Slicer3_BINARY_DIR}/Libs/vtkITK)
set(TCLAP_DIR ${Slicer3_BINARY_DIR}/Libs/tclap)
275

276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# --------------------------------------------------------------------------
# Configure and install headers

include_directories("${CMAKE_CURRENT_BINARY_DIR}")

configure_file(
  ${CMAKE_CURRENT_SOURCE_DIR}/vtkSlicerConfigure.h.in 
  ${CMAKE_CURRENT_BINARY_DIR}/vtkSlicerConfigure.h
  )

install(FILES 
  "${CMAKE_CURRENT_BINARY_DIR}/vtkSlicerConfigure.h"
  DESTINATION ${Slicer3_INSTALL_INCLUDE_DIR} COMPONENT Development
  )

#-----------------------------------------------------------------------------
pieper's avatar
pieper committed
292
293
# Subdirectories
#
294
295
add_subdirectory(Libs)
add_subdirectory(Base)
296
add_subdirectory(Resources)
297

298
#-----------------------------------------------------------------------------
299
# At this point, let's not have the applications and modules guess which
300
301
# include paths or libraries they need, but use Slicer3_*_LIBRARIES and
# Slicer3_*_INCLUDE_DIRS instead. As far as modules are concerned, both
302
303
304
305
306
# variables are actually set automatically by the import script when building
# against a Slicer3 build or installed tree. When in-source, we need to
# set both variables now. Retrieve them from the persistent property cache
# since they were collected in each subdir (which makes it impossible to
# use normal variables, since a new scope is created in each subdir).
307
308
309
#
slicer3_get_persistent_property(Slicer3_Libs_LIBRARIES Slicer3_Libs_LIBRARIES)
slicer3_get_persistent_property(Slicer3_Base_LIBRARIES Slicer3_Base_LIBRARIES)
310

311
312
slicer3_get_persistent_property(Slicer3_Libs_INCLUDE_DIRS Slicer3_Libs_INCLUDE_DIRS)
slicer3_get_persistent_property(Slicer3_Base_INCLUDE_DIRS Slicer3_Base_INCLUDE_DIRS)
pieper's avatar
pieper committed
313

314
315
316
317
318
#-----------------------------------------------------------------------------
# Modules and CLI
#
option(Slicer3_BUILD_CLI "Build Slicer3 CLI Plugins" ON)
option(Slicer3_BUILD_MODULES "Build Slicer3 Modules" ON)
319

barre's avatar
barre committed
320
321
322
include("${Slicer3_CMAKE_DIR}/Slicer3PluginsMacros.cmake")
include("${Slicer3_CMAKE_DIR}/Slicer3ModulesMacros.cmake")

323
if(Slicer3_BUILD_MODULES)
324
  add_subdirectory(Modules)
325
326
327
328
329
330
331
else(Slicer3_BUILD_MODULES)
  # if Slicer3_BUILD_CLI is ON, we still need at least the CommandLineModule
  # so that we can have CLI, without all the other modules
  if(Slicer3_BUILD_CLI)
    add_subdirectory(Modules/CommandLineModule)
  endif(Slicer3_BUILD_CLI)
endif(Slicer3_BUILD_MODULES)
pieper's avatar
pieper committed
332

333
334
335
336
#-----------------------------------------------------------------------------
# Applications need to be built after Modules to capture the TractTracing in
# the correct ordering.
#
337
add_subdirectory(Applications)
338

339
340
341
#-----------------------------------------------------------------------------
# Testing
#
342
343
344
if(Slicer3_BUILD_TESTING)
  add_subdirectory(Testing)
endif(Slicer3_BUILD_TESTING)
pieper's avatar
pieper committed
345

346
# Install testing data
andy's avatar
andy committed
347

348
349
350
351
352
353
354
355
install(DIRECTORY
  Testing
  DESTINATION ${Slicer3_INSTALL_SHARE_DIR} COMPONENT Development
  PATTERN ".svn" EXCLUDE
  PATTERN "CMakeLists.txt" EXCLUDE
  )

#-----------------------------------------------------------------------------
356
# Launcher for slicer
357
#
358
add_subdirectory(Utilities/Launcher)
359

360
361
362
363
364
365
366
367
368
369
configure_file(
  ${Slicer3_SOURCE_DIR}/launch.tcl.in
  "${Slicer3_BINARY_DIR}/${Slicer3_INSTALL_LIB_DIR}/launch.tcl"
  )
install(
  FILES "${Slicer3_BINARY_DIR}/${Slicer3_INSTALL_LIB_DIR}/launch.tcl"
  DESTINATION ${Slicer3_INSTALL_LIB_DIR}
  )

#-----------------------------------------------------------------------------
370
# Package slicer
371
#
372
add_subdirectory(Utilities/Package)
andy's avatar
andy committed
373

374
#-----------------------------------------------------------------------------
375
# Documentation
376
#
377
378
379
380
option(BUILD_DOCUMENTATION "Build Slicer3 Documentation" OFF)
if(BUILD_DOCUMENTATION)
  add_subdirectory(Utilities/Doxygen)
endif(BUILD_DOCUMENTATION)
andy's avatar
andy committed
381

382
# setup file for setting custom ctest vars
383
configure_file(${Slicer3_SOURCE_DIR}/CTestCustom.cmake.in
384
  ${Slicer3_BINARY_DIR}/CTestCustom.cmake @ONLY)
385

386
#-----------------------------------------------------------------------------
387
388
# Set up for building against a Slicer3 build tree and a Slicer3 installation 
#
389
390
include(${Slicer3_SOURCE_DIR}/GenerateSlicer3Config.cmake)

391
392
393
configure_file(${Slicer3_SOURCE_DIR}/CTestConfig.cmake
  ${Slicer3_BINARY_DIR}/${Slicer3_INSTALL_LIB_DIR}/CTestConfig.cmake COPYONLY IMMEDIATE)

394
395
396
configure_file(${Slicer3_SOURCE_DIR}/UseSlicer3.cmake.in
  ${Slicer3_BINARY_DIR}/UseSlicer3.cmake COPYONLY IMMEDIATE)

397
398
399
400
401
configure_file(${Slicer3_SOURCE_DIR}/CMake/RemoveTemporaryFiles.cmake.in
  ${Slicer3_BINARY_DIR}/CMake/RemoveTemporaryFiles.cmake @ONLY IMMEDIATE)
configure_file(${Slicer3_SOURCE_DIR}/CMake/Slicer3SampleBuildTest.cmake.in
  ${Slicer3_BINARY_DIR}/CMake/Slicer3SampleBuildTest.cmake @ONLY)

402
403
install(FILES
  #   ${Slicer3_BINARY_DIR}/Slicer3BuildSettings.cmake
404
  ${Slicer3_SOURCE_DIR}/CTestConfig.cmake
405
406
  ${Slicer3_BINARY_DIR}/UseSlicer3.cmake
  ${Slicer3_BINARY_DIR}/Utilities/Slicer3Config.cmake
407
  DESTINATION ${Slicer3_INSTALL_LIB_DIR}
408
409
  COMPONENT Development
  )