CMakeLists.txt 9.81 KB
Newer Older
1
2
3
project(Slicer3)
cmake_minimum_required(VERSION 2.2)
mark_as_advanced(CMAKE_BACKWARDS_COMPATIBILITY)
4

5
6
7
#
# Disable the warnings that DevStudio 2005 emits wrt to sprintf, strcpu, etc.
#
8
9
10
if(CMAKE_COMPILER_2005)
  add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
endif(CMAKE_COMPILER_2005)
11

barre's avatar
barre committed
12
13
14
15
if(COMMAND cmake_policy)
  cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)

16
17
18
19
20
#
# avoid linker bug in Mac OS 10.5
# see:
# http://wiki.finkproject.org/index.php/Fink:Packaging:Preparing_for_10.5#OpenGL_Bug
#
21
22
23
24
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)
25

26
27
#-----------------------------------------------------------------------------
# Slicer version number.
28
29
30
31
32
33
34
set(Slicer3_VERSION_MAJOR "3")
set(Slicer3_VERSION_MINOR "0")
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}")
35

36
37
#-----------------------------------------------------------------------------
# Build shared lib by default
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
option(BUILD_SHARED_LIBS "Build Slicer3 with shared libraries." ON)

if(BUILD_SHARED_LIBS)
  if(WIN32 AND NOT UNIX)
    set(SLICER3_LIB_INSTALL_DIR /bin)
  else(WIN32 AND NOT UNIX)
    set(SLICER3_LIB_INSTALL_DIR /lib)
  endif(WIN32 AND NOT UNIX)
endif(BUILD_SHARED_LIBS)

# Temporary hack to set/get persistent values accross subdirs until 2.6 comes
# Neither set_source_file_properties nor set(... INTERNAL FORCE) would work
macro(SET_PERSISTENT_PROPERTY property_name)
  set(_file "${Slicer3_BINARY_DIR}/persistent/${property_name}")
  file(WRITE "${_file}" "${ARGN}")
  #set(__${property_name} ${value} CACHE INTERNAL "" FORCE)
endmacro(SET_PERSISTENT_PROPERTY property_name value)

macro(GET_PERSISTENT_PROPERTY property_name var_name)
  set(_file "${Slicer3_BINARY_DIR}/persistent/${property_name}")
  if(EXISTS "${_file}")
    file(READ "${_file}" ${var_name})
  else(EXISTS "${_file}")
    set(${var_name})
  endif(EXISTS "${_file}")
  #set(${var_name} ${__${property_name}})
endmacro(GET_PERSISTENT_PROPERTY property_name var_name)
pieper's avatar
pieper committed
65
66
67
68
69

#
# Top level slicer3 configurations
#

70
71
72
73
74
set(LIBRARY_OUTPUT_PATH ${Slicer3_BINARY_DIR}/bin/ 
  CACHE PATH 
  "Single output directory for building all libraries." 
  FORCE)
set(EXECUTABLE_OUTPUT_PATH ${Slicer3_BINARY_DIR}/bin/ 
hliu's avatar
hliu committed
75

76
77
78
  CACHE PATH 
  "Single output directory for building all executables." 
  FORCE)
79
80
81
#
# Slicer libraries subdirectory
#
82
83
84
set(SLICER_INSTALL_LIBRARIES_DIR "lib/Slicer3")
set(SLICER_LIBRARIES_DIR 
  "${Slicer3_BINARY_DIR}/${SLICER_INSTALL_LIBRARIES_DIR}")
85

86
87
SET_PERSISTENT_PROPERTY(Slicer3_LIBRARIES "")
SET_PERSISTENT_PROPERTY(Slicer3_INCLUDE_DIRS "")
pieper's avatar
pieper committed
88
89
90

# Add the testing directories

91
92
93
94
95
96
97
98
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
99

100
101
102
103
104
105
#
# Libs
# - ITK
# - KWWidgets (pulls in VTK)
#

106
## Python
107
108
109
110
111
option(USE_PYTHON "Integrate a python interpreter into Slicer." OFF)
if(USE_PYTHON)
  find_package(PythonLibs)
  add_definitions(-DUSE_PYTHON)
endif(USE_PYTHON)
112
113


114
## ITK
115
116
117
118
find_package(ITK REQUIRED)
if(NOT ITK_FOUND)
  message(FATAL_ERROR "Need ITK to build")
endif(NOT ITK_FOUND)
119

120
include(${ITK_USE_FILE})
121

122
#
123
## KWWidgets
124
#
125
126
127
128
find_package(KWWidgets REQUIRED)
if(NOT KWWidgets_FOUND)
  message(FATAL_ERROR "Need KWWidgets to build")
endif(NOT KWWidgets_FOUND)
129

130
include(${KWWidgets_USE_FILE})
131

132
133
134
#
# Teem
#
135
136
137
138
139
find_package(TEEM REQUIRED)
if(NOT TEEM_FOUND)
  message(FATAL_ERROR "Need TEEMK to build")
endif(NOT TEEM_FOUND)
include(${TEEM_USE_FILE})
140

141
142
143
#
# BatchMake
#
144
145
146
147
148
option(USE_BatchMake "Build Slicer3 with BatchMake support." OFF)
if(USE_BatchMake)
  find_package(BatchMake REQUIRED)
  include(${BatchMake_USE_FILE})
endif(USE_BatchMake)
149
150
151
152

#
# MIDAS
#
153
option(USE_MIDAS "Build Slicer3 with MIDAS support." OFF)
154

hliu's avatar
hliu committed
155
#
156
# NaviTrack 
hliu's avatar
hliu committed
157
#
158
159
option(USE_NAVITRACK "Build Slicer3 with NaviTrack support." OFF)
if(USE_NAVITRACK)
160

161
  find_library(NAVITRACK_LIB 
162
    NAMES NaviTrack
163
    PATHS ${NAVITRACK_LIB_DIR} 
164
165
166
167
    )
  if(NAVITRACK_LIB-NOTFOUND)
    message(FATAL_ERROR "Need NaviTrack to build")
  endif(NAVITRACK_LIB-NOTFOUND)
hliu's avatar
hliu committed
168

169
  # include file for OpenTracker 2.0 
170
  find_path(NAVITRACK_INC "OpenTracker/OpenTracker.h" 
171
    ${NAVITRACK_INC_DIR}
172
    )
hliu's avatar
hliu committed
173

174
175
176
177
178
179
180
  if(NAVITRACK_INC-NOTFOUND)
    message(FATAL_ERROR "Need OpenTracker.h to build")
  endif(NAVITRACK_INC-NOTFOUND)
else(USE_NAVITRACK)
  set(NAVITRACK_LIB "")
  set(NAVITRACK_INC "")
endif(USE_NAVITRACK)
hliu's avatar
hliu committed
181

hliu's avatar
hliu committed
182
183
184
185
#
# IGSTK
# Built in Slicer3-lib
#
186
187
188
189
190
option(USE_IGSTK "Build Slicer3 with IGSTK support." OFF)
if(USE_IGSTK)
  find_package(IGSTK REQUIRED)
  include(${IGSTK_USE_FILE})
endif(USE_IGSTK)
hliu's avatar
hliu committed
191

barre's avatar
barre committed
192
193
194
195
# 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.

196
197
include("${KWWidgets_CMAKE_DIR}/KWWidgetsPathsMacros.cmake")
kwwidgets_generate_setup_paths_scripts(
198
199
  "${EXECUTABLE_OUTPUT_PATH}" "Slicer3SetupPaths" "${TEEM_DIR}/bin"
  "${BatchMake_DIR}/bin")
barre's avatar
barre committed
200
201

# VTK 5.0 does not have VTK_CMAKE_DIR
hliu's avatar
hliu committed
202

barre's avatar
barre committed
203
204
205
206
207
# 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}" "")

208
209
210
211
if(NOT VTK_CMAKE_DIR)
  set(VTK_CMAKE_DIR "${VTK_SOURCE_DIR}/CMake")
endif(NOT VTK_CMAKE_DIR)
include("${VTK_CMAKE_DIR}/vtkWrapTcl.cmake")
212

213
214
215
216
#
## check versions of VTK to track CVS HEAD
#

217
218
219
220
221
222
223
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)
224

225
226
227
228
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) 
229

lorensen's avatar
lorensen committed
230
231
232
#
# These packages exist within the Slicer3 source tree
#
233
234
235
236
237
238
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)
239

pieper's avatar
pieper committed
240
241
242
243
#
# Subdirectories
#

244
245
246
247
option(BUILD_CLI "Build Slicer3 CLI Plugins" ON)
mark_as_advanced(BUILD_CLI)
add_subdirectory(Libs)
add_subdirectory(Base)
248

249
250
251
252
253
254
255
256
# At this point, let's not have the applications and modules guess which
# include paths or libraries they need, but use Slicer3_LIBRARIES and
# Slicer3_INCLUDE_DIRS instead. As far as modules are concerned, both
# 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).
257

258
259
GET_PERSISTENT_PROPERTY(Slicer3_LIBRARIES Slicer3_LIBRARIES)
GET_PERSISTENT_PROPERTY(Slicer3_INCLUDE_DIRS Slicer3_INCLUDE_DIRS)
pieper's avatar
pieper committed
260

261
262
263
264
265
266
option(BUILD_MODULES "Build Slicer3 Modules" ON)
mark_as_advanced(BUILD_MODULES)

if(BUILD_MODULES)
  add_subdirectory(Modules)
endif(BUILD_MODULES)
pieper's avatar
pieper committed
267

268
269
## Applications need to be built after Modules to capture the TractTracing in
## the correct ordering.
270
add_subdirectory(Applications)
271

272
273
274
if(Slicer3_BUILD_TESTING)
  add_subdirectory(Testing)
endif(Slicer3_BUILD_TESTING)
pieper's avatar
pieper committed
275

276
# include a test for endianness (used to be done by default)
277
278
include(${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
test_big_endian(CMAKE_WORDS_BIGENDIAN)
andy's avatar
andy committed
279

280
# Launcher for slicer
281
add_subdirectory(Utilities/Launcher)
282

283
# Package slicer
284
add_subdirectory(Utilities/Package)
andy's avatar
andy committed
285

286
# Documentation
287
288
289
290
option(BUILD_DOCUMENTATION "Build Slicer3 Documentation" OFF)
if(BUILD_DOCUMENTATION)
  add_subdirectory(Utilities/Doxygen)
endif(BUILD_DOCUMENTATION)
andy's avatar
andy committed
291

292
# CMAke 2.4 does not have INSTALL(DIRECTORY ...) do it manually
hayes's avatar
hayes committed
293
#INSTALL(DIRECTORY "${Slicer3_BINARY_DIR}/Modules/Packages"
294
#  DESTINATION ${SLICER_INSTALL_LIBRARIES_DIR}/Modules)
295
install(CODE "EXECUTE_PROCESS\(COMMAND \"${CMAKE_COMMAND}\" -E copy_directory \"${SLICER_LIBRARIES_DIR}/Modules/Packages\" \"\${CMAKE_INSTALL_PREFIX}/${SLICER_INSTALL_LIBRARIES_DIR}/Modules/Packages\"\)")
296

297
configure_file(
298
299
  ${Slicer3_SOURCE_DIR}/launch.tcl.in
  ${Slicer3_BINARY_DIR}/lib/launch.tcl
300
  )
pieper's avatar
pieper committed
301

302
install(
pieper's avatar
pieper committed
303
  FILES ${Slicer3_BINARY_DIR}/lib/launch.tcl
304
  DESTINATION lib
305
  )
306

307
# setup file for setting custom ctest vars
308
configure_file(${Slicer3_SOURCE_DIR}/CTestCustom.cmake.in
309
  ${Slicer3_BINARY_DIR}/CTestCustom.cmake @ONLY)
310
311
312
313

# Set up for building against a Slicer3 build tree and a Slicer3 installation 
#
#
314
315
316
317
318
319
320
321
322
323
324
325
include(${Slicer3_SOURCE_DIR}/GenerateSlicer3Config.cmake)

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

install(FILES
  #   ${Slicer3_BINARY_DIR}/Slicer3BuildSettings.cmake
  ${Slicer3_BINARY_DIR}/UseSlicer3.cmake
  ${Slicer3_BINARY_DIR}/Utilities/Slicer3Config.cmake
  DESTINATION lib/Slicer3
  COMPONENT Development
  )