CMakeLists.txt 9.61 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

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

22
23
#-----------------------------------------------------------------------------
# Slicer version number.
24
25
26
27
28
29
30
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}")
31

32
33
#-----------------------------------------------------------------------------
# Build shared lib by default
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
61
62
63
64
65

#
# Top level slicer3 configurations
#

66
67
68
69
70
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
71

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

82
83
SET_PERSISTENT_PROPERTY(Slicer3_LIBRARIES "")
SET_PERSISTENT_PROPERTY(Slicer3_INCLUDE_DIRS "")
pieper's avatar
pieper committed
84
85
86

# Add the testing directories

87
88
89
90
91
92
93
94
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
95

96
97
98
99
100
101
#
# Libs
# - ITK
# - KWWidgets (pulls in VTK)
#

102
## Python
103
104
105
106
107
option(USE_PYTHON "Integrate a python interpreter into Slicer." OFF)
if(USE_PYTHON)
  find_package(PythonLibs)
  add_definitions(-DUSE_PYTHON)
endif(USE_PYTHON)
108
109


110
## ITK
111
112
113
114
find_package(ITK REQUIRED)
if(NOT ITK_FOUND)
  message(FATAL_ERROR "Need ITK to build")
endif(NOT ITK_FOUND)
115

116
include(${ITK_USE_FILE})
117

118
#
119
## KWWidgets
120
#
121
122
123
124
find_package(KWWidgets REQUIRED)
if(NOT KWWidgets_FOUND)
  message(FATAL_ERROR "Need KWWidgets to build")
endif(NOT KWWidgets_FOUND)
125

126
include(${KWWidgets_USE_FILE})
127

128
129
130
#
# Teem
#
131
132
133
134
135
find_package(TEEM REQUIRED)
if(NOT TEEM_FOUND)
  message(FATAL_ERROR "Need TEEMK to build")
endif(NOT TEEM_FOUND)
include(${TEEM_USE_FILE})
136

137
138
139
#
# BatchMake
#
140
141
142
143
144
option(USE_BatchMake "Build Slicer3 with BatchMake support." OFF)
if(USE_BatchMake)
  find_package(BatchMake REQUIRED)
  include(${BatchMake_USE_FILE})
endif(USE_BatchMake)
145
146
147
148

#
# MIDAS
#
149
option(USE_MIDAS "Build Slicer3 with MIDAS support." OFF)
150

hliu's avatar
hliu committed
151
#
152
# NaviTrack 
hliu's avatar
hliu committed
153
#
154
155
option(USE_NAVITRACK "Build Slicer3 with NaviTrack support." OFF)
if(USE_NAVITRACK)
156

157
  find_library(NAVITRACK_LIB 
158
    NAMES NaviTrack
159
    PATHS ${NAVITRACK_LIB_DIR} 
160
161
162
163
    )
  if(NAVITRACK_LIB-NOTFOUND)
    message(FATAL_ERROR "Need NaviTrack to build")
  endif(NAVITRACK_LIB-NOTFOUND)
hliu's avatar
hliu committed
164

165
  # include file for OpenTracker 2.0 
166
  find_path(NAVITRACK_INC "OpenTracker/OpenTracker.h" 
167
    ${NAVITRACK_INC_DIR}
168
    )
hliu's avatar
hliu committed
169

170
171
172
173
174
175
176
  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
177

hliu's avatar
hliu committed
178
179
180
181
#
# IGSTK
# Built in Slicer3-lib
#
182
183
184
185
186
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
187

barre's avatar
barre committed
188
189
190
191
# 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.

192
193
include("${KWWidgets_CMAKE_DIR}/KWWidgetsPathsMacros.cmake")
kwwidgets_generate_setup_paths_scripts(
194
195
  "${EXECUTABLE_OUTPUT_PATH}" "Slicer3SetupPaths" "${TEEM_DIR}/bin"
  "${BatchMake_DIR}/bin")
barre's avatar
barre committed
196
197

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

barre's avatar
barre committed
199
200
201
202
203
# 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}" "")

204
205
206
207
if(NOT VTK_CMAKE_DIR)
  set(VTK_CMAKE_DIR "${VTK_SOURCE_DIR}/CMake")
endif(NOT VTK_CMAKE_DIR)
include("${VTK_CMAKE_DIR}/vtkWrapTcl.cmake")
208

209
210
211
212
#
## check versions of VTK to track CVS HEAD
#

213
214
215
216
217
218
219
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)
220

221
222
223
224
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) 
225

lorensen's avatar
lorensen committed
226
227
228
#
# These packages exist within the Slicer3 source tree
#
229
230
231
232
set(GenerateCLP_DIR ${Slicer3_BINARY_DIR}/Libs/GenerateCLP)
set(ModuleDescriptionParser_DIR ${Slicer3_BINARY_DIR}/Libs/ModuleDescriptionParser)
set(vtkITK_DIR ${Slicer3_BINARY_DIR}/Libs/vtkITK)
set(TCLAP_DIR ${Slicer3_BINARY_DIR}/Libs/tclap)
233

pieper's avatar
pieper committed
234
235
236
237
#
# Subdirectories
#

238
239
240
241
option(BUILD_CLI "Build Slicer3 CLI Plugins" ON)
mark_as_advanced(BUILD_CLI)
add_subdirectory(Libs)
add_subdirectory(Base)
242

243
244
245
246
247
248
249
250
# 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).
251

252
253
GET_PERSISTENT_PROPERTY(Slicer3_LIBRARIES Slicer3_LIBRARIES)
GET_PERSISTENT_PROPERTY(Slicer3_INCLUDE_DIRS Slicer3_INCLUDE_DIRS)
pieper's avatar
pieper committed
254

255
256
257
258
259
260
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
261

262
263
## Applications need to be built after Modules to capture the TractTracing in
## the correct ordering.
264
add_subdirectory(Applications)
265

266
267
268
if(Slicer3_BUILD_TESTING)
  add_subdirectory(Testing)
endif(Slicer3_BUILD_TESTING)
pieper's avatar
pieper committed
269

270
# include a test for endianness (used to be done by default)
271
272
include(${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
test_big_endian(CMAKE_WORDS_BIGENDIAN)
andy's avatar
andy committed
273

274
# Launcher for slicer
275
add_subdirectory(Utilities/Launcher)
276

277
# Package slicer
278
add_subdirectory(Utilities/Package)
andy's avatar
andy committed
279

280
# Documentation
281
282
283
284
option(BUILD_DOCUMENTATION "Build Slicer3 Documentation" OFF)
if(BUILD_DOCUMENTATION)
  add_subdirectory(Utilities/Doxygen)
endif(BUILD_DOCUMENTATION)
andy's avatar
andy committed
285

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

291
configure_file(
292
293
  ${Slicer3_SOURCE_DIR}/launch.tcl.in
  ${Slicer3_BINARY_DIR}/lib/launch.tcl
294
  )
pieper's avatar
pieper committed
295

296
install(
pieper's avatar
pieper committed
297
  FILES ${Slicer3_BINARY_DIR}/lib/launch.tcl
298
  DESTINATION lib
299
  )
300

301
# setup file for setting custom ctest vars
302
configure_file(${Slicer3_SOURCE_DIR}/CTestCustom.cmake.in
303
  ${Slicer3_BINARY_DIR}/CTestCustom.cmake @ONLY)
304
305
306
307

# Set up for building against a Slicer3 build tree and a Slicer3 installation 
#
#
308
309
310
311
312
313
314
315
316
317
318
319
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
  )