-
Notifications
You must be signed in to change notification settings - Fork 11
/
CMakeLists.txt
274 lines (220 loc) · 9.1 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
cmake_minimum_required(VERSION 3.3)
project(SimpleITKPythonPackage NONE)
if(NOT DEFINED SimpleITKPythonPackage_SUPERBUILD)
set(SimpleITKPythonPackage_SUPERBUILD 1)
endif()
# Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
mark_as_advanced(CMAKE_BUILD_TYPE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()
if(NOT DEFINED SimpleITK_SOURCE_DIR)
set(SimpleITK_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/SimpleITK")
endif()
if(SimpleITKPythonPackage_SUPERBUILD)
set(ep_common_cmake_cache_args)
if(NOT CMAKE_CONFIGURATION_TYPES)
list(APPEND ep_common_cmake_cache_args
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
)
endif()
#-----------------------------------------------------------------------------
# Options
option ( SimpleITK_PYTHON_THREADS "Enable threaded python usage by unlocking the GIL." ON )
mark_as_advanced( SimpleITK_PYTHON_THREADS )
#
# When building different "flavor" of SimpleITK python packages on a given platform,
# explicitly setting the following options allow to speed up package generation by
# re-using existing resources.
#
# SimpleITK_SOURCE_DIR: Path to an existing source directory
#
# SWIG_EXECUTABLE: Path to an existing executable
#
# SimpleITK_DIR: Path to an existing SimpleITK build or install directory
#
option ( SimpleITKPythonPackage_BUILD_PYTHON "Build SimpleITK python module" ON )
mark_as_advanced( SimpleITKPythonPackage_BUILD_PYTHON )
# compile with multiple processors
include(ProcessorCount)
ProcessorCount(NPROC)
if (NOT NPROC EQUAL 0)
set( ENV{MAKEFLAGS} "-j${NPROC}" )
endif()
#-----------------------------------------------------------------------------
include(ExternalProject)
# Add an empty external project
function(sitk_ExternalProject_Add_Empty proj depends)
set(depends_args)
if(NOT depends STREQUAL "")
set(depends_args DEPENDS ${depends})
endif()
ExternalProject_add(${proj}
SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
DOWNLOAD_COMMAND ""
UPDATE_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
BUILD_IN_SOURCE 1
BUILD_ALWAYS 1
INSTALL_COMMAND ""
${depends_args}
)
endfunction()
#-----------------------------------------------------------------------------
# A separate project is used to download SimpleITK, so that the SuperBuild
# subdirectory can be use for SimpleITK's SuperBuild to build the
# required Lua, GTest etc.
# Sanity checks
if(DEFINED SimpleITK_SOURCE_DIR AND NOT EXISTS ${SimpleITK_SOURCE_DIR})
message(FATAL_ERROR "SimpleITK_SOURCE_DIR variable is defined but corresponds to nonexistent directory: \"${SimpleITK_SOURCE_DIR}\"")
endif()
message(STATUS "SuperBuild - SimpleITK_SOURCE_DIR: ${SimpleITK_SOURCE_DIR}")
#-----------------------------------------------------------------------------
# SimpleITK "Core" libraries: This is the SimpleITK Superbuild project
# that build all the tools needed (GTest, PCRE, Swig, Lua & GTest) and
# then SimpleITK "core" libraries.
message(STATUS "SuperBuild - SimpleITK-superbuild")
# Sanity checks
if(DEFINED SimpleITK_DIR AND NOT EXISTS ${SimpleITK_DIR})
message(FATAL_ERROR "SimpleITK_DIR variable is defined but corresponds to nonexistent directory")
endif()
if(DEFINED SWIG_EXECUTABLE AND NOT EXISTS ${SWIG_EXECUTABLE})
message(FATAL_ERROR "SWIG_EXECUTABLE variable is defined but corresponds to nonexistent file")
endif()
if(NOT DEFINED SimpleITK_DIR AND NOT DEFINED SWIG_EXECUTABLE)
set(SimpleITK_SUPERBUILD_DIR ${CMAKE_BINARY_DIR}/sitk-sb)
ExternalProject_add(SimpleITK-superbuild
SOURCE_DIR ${SimpleITK_SOURCE_DIR}/SuperBuild
BINARY_DIR ${SimpleITK_SUPERBUILD_DIR}
DOWNLOAD_COMMAND ""
UPDATE_COMMAND ""
CMAKE_CACHE_ARGS
${ep_common_cmake_cache_args}
-DBUILD_EXAMPLES:BOOL=OFF
-DBUILD_TESTING:BOOL=OFF
-DBUILD_DOXYGEN:BOOL=OFF
-DWRAP_DEFAULT:BOOL=OFF
-DSimpleITK_INSTALL_DOC_DIR:STRING=SimpleITK
-DSimpleITK_BUILD_STRIP:BOOL=ON
-DSimpleITK_BUILD_DISTRIBUTE:BOOL=ON
-DSimpleITK_GIT_PROTOCOL:STRING=https
-DSKBUILD:BOOL=${SKBUILD}
USES_TERMINAL_CONFIGURE 1
USES_TERMINAL_BUILD 1
INSTALL_COMMAND ""
)
set(SimpleITK_DIR ${SimpleITK_SUPERBUILD_DIR}/SimpleITK-build)
set(ITK_DIR ${SimpleITK_SUPERBUILD_DIR}/ITK-prefix/lib/cmake/ITK)
if(WIN32)
set(SWIG_EXECUTABLE ${SimpleITK_SUPERBUILD_DIR}/swigwin/swig.exe)
else()
set(SWIG_EXECUTABLE ${SimpleITK_SUPERBUILD_DIR}/Swig/bin/swig)
endif()
else()
sitk_ExternalProject_Add_Empty(
SimpleITK-superbuild
)
endif()
message(STATUS "SuperBuild - SimpleITK_DIR: ${SimpleITK_DIR}")
message(STATUS "SuperBuild - ITK_DIR: ${ITK_DIR}")
message(STATUS "SuperBuild - SWIG_EXECUTABLE: ${SWIG_EXECUTABLE}")
#-----------------------------------------------------------------------------
if(NOT SimpleITKPythonPackage_BUILD_PYTHON)
return()
endif()
#-----------------------------------------------------------------------------
# Search for python interpreter and libraries
message(STATUS "SuperBuild - Searching for python")
if (PYTHON_VERSION_STRING)
# need to do something with the passed variable to silence unused
# CMake warning.
endif()
# Sanity checks
if(DEFINED PYTHON_INCLUDE_DIR AND NOT EXISTS ${PYTHON_INCLUDE_DIR})
message(FATAL_ERROR "PYTHON_INCLUDE_DIR variable is defined but corresponds to nonexistent directory")
endif()
if(DEFINED PYTHON_LIBRARY AND NOT EXISTS ${PYTHON_LIBRARY})
message(FATAL_ERROR "PYTHON_LIBRARY variable is defined but corresponds to nonexistent file")
endif()
if(DEFINED PYTHON_EXECUTABLE AND NOT EXISTS ${PYTHON_EXECUTABLE})
message(FATAL_ERROR "PYTHON_EXECUTABLE variable is defined but corresponds to nonexistent file")
endif()
if(NOT DEFINED PYTHON_INCLUDE_DIR
OR NOT DEFINED PYTHON_LIBRARY
OR NOT DEFINED PYTHON_EXECUTABLE)
find_package ( PythonLibs REQUIRED )
find_package ( PythonInterp REQUIRED )
endif()
message(STATUS "SuperBuild - PYTHON_INCLUDE_DIR: ${PYTHON_INCLUDE_DIR}")
message(STATUS "SuperBuild - PYTHON_LIBRARY: ${PYTHON_LIBRARY}")
message(STATUS "SuperBuild - PYTHON_EXECUTABLE: ${PYTHON_EXECUTABLE}")
#-----------------------------------------------------------------------------
# SimpleITK Python module: This project build only the SimpleITK python
# module.
message(STATUS "SuperBuild - SimpleITK-python => Requires SimpleITK-superbuild")
set(SimpleITK_PYTHON_DIR "${CMAKE_BINARY_DIR}/SimpleITK-python")
ExternalProject_add(SimpleITK-python
SOURCE_DIR ${SimpleITK_SOURCE_DIR}/Wrapping/Python
BINARY_DIR ${SimpleITK_PYTHON_DIR}
DOWNLOAD_COMMAND ""
UPDATE_COMMAND ""
CMAKE_CACHE_ARGS
${ep_common_cmake_cache_args}
-DPython_INCLUDE_DIR:PATH=${PYTHON_INCLUDE_DIR}
-DPython_LIBRARY:PATH=${PYTHON_LIBRARY}
-DPython_EXECUTABLE:PATH=${PYTHON_EXECUTABLE}
-DBUILD_TESTING:BOOL=OFF
-DSimpleITK_PYTHON_THREADS:BOOL=${SimpleITK_PYTHON_THREADS}
-DSimpleITK_DIR:PATH=${SimpleITK_DIR}
-DITK_DIR:PATH=${ITK_DIR}
-DSWIG_EXECUTABLE:PATH=${SWIG_EXECUTABLE}
-DSimpleITK_BUILD_STRIP:BOOL=ON
-DSKBUILD:BOOL=ON
USES_TERMINAL_CONFIGURE 1
USES_TERMINAL_BUILD 1
INSTALL_COMMAND ""
DEPENDS SimpleITK-superbuild
)
message(STATUS "SuperBuild - SimpleITK_PYTHON_DIR: ${SimpleITK_PYTHON_DIR}")
#-----------------------------------------------------------------------------
# SimpleITKPythonPackage: This project adds install rules for the "Runtime" component
# of both SimpleITK code and python libraries.
message(STATUS "SuperBuild - ${PROJECT_NAME} => Requires SimpleITK-python")
ExternalProject_add(${PROJECT_NAME}
SOURCE_DIR ${CMAKE_SOURCE_DIR}
BINARY_DIR ${CMAKE_BINARY_DIR}/${PROJECT_NAME}-build
DOWNLOAD_COMMAND ""
UPDATE_COMMAND ""
CMAKE_CACHE_ARGS
${ep_common_cmake_cache_args}
-DSimpleITKPythonPackage_SUPERBUILD:BOOL=0
-DSimpleITK_DIR:PATH=${SimpleITK_DIR}
-DSimpleITK_PYTHON_DIR:PATH=${SimpleITK_PYTHON_DIR}
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}
USES_TERMINAL_CONFIGURE 1
INSTALL_COMMAND ""
DEPENDS SimpleITK-python
)
install(SCRIPT ${CMAKE_BINARY_DIR}/${PROJECT_NAME}-build/cmake_install.cmake)
else()
#-----------------------------------------------------------------------------
# Install SimpleITK Core "Runtime" components
install(CODE "
unset(CMAKE_INSTALL_COMPONENT)
set(COMPONENT \"Runtime\")
include\(\"${SimpleITK_DIR}/cmake_install.cmake\")
unset(CMAKE_INSTALL_COMPONENT)
")
# Install SimpleITK Python "Runtime" components
install(CODE "
unset(CMAKE_INSTALL_COMPONENT)
set(COMPONENT \"Runtime\")
include\(\"${SimpleITK_PYTHON_DIR}/cmake_install.cmake\")
unset(CMAKE_INSTALL_COMPONENT)
")
endif()