forked from ome/ome-cmake-superbuild
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ExternalProjectHelpers.cmake
264 lines (231 loc) · 11.8 KB
/
ExternalProjectHelpers.cmake
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
## #%L
# Bio-Formats C++ libraries (cmake build infrastructure)
# %%
# Copyright © 2006 - 2014 Open Microscopy Environment:
# - Massachusetts Institute of Technology
# - National Institutes of Health
# - University of Dundee
# - Board of Regents of the University of Wisconsin-Madison
# - Glencoe Software, Inc.
# %%
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and documentation are
# those of the authors and should not be interpreted as representing official
# policies, either expressed or implied, of any organization.
# #L%
# Include superbuild logic for the given package(s)
# Each package is only included once, using the ${name}_INCLUDED guard
function(ome_add_package)
foreach(name ${ARGV})
get_property(included GLOBAL PROPERTY ${name}_INCLUDED SET)
if(NOT included)
set_property(GLOBAL PROPERTY ${name}_INCLUDED ON)
set(EP_PROJECT "${name}")
set(EP_SOURCE_DIR "${CMAKE_BINARY_DIR}/${name}-source")
set(EP_BINARY_DIR "${CMAKE_BINARY_DIR}/${name}-build")
include("${PROJECT_SOURCE_DIR}/packages/${name}/superbuild.cmake")
endif()
endforeach()
endfunction()
# Allow recursive addition of dependencies; store them in the specified
# variable and recursively add them. Dependencies are stored in
# target_DEPENDENCIES
function(ome_add_dependencies target)
get_property(dependencies_added GLOBAL PROPERTY ${target}_DEPENDENCIES_ADDED SET)
if(NOT dependencies_added)
set_property(GLOBAL PROPERTY ${target}_DEPENDENCIES_ADDED ON)
foreach(name ${ARGN})
ome_add_package("${name}")
list(APPEND ${target}_DEPENDENCIES "${name}")
endforeach()
if (${target}_DEPENDENCIES)
list(REMOVE_DUPLICATES ${target}_DEPENDENCIES)
endif()
set(${target}_DEPENDENCIES "${${target}_DEPENDENCIES}" PARENT_SCOPE)
add_custom_target(${target}-prerequisites
DEPENDS ${target}_DEPENDENCIES)
endif()
endfunction()
set(GENERIC_CMAKE_CONFIGURE "${PROJECT_SOURCE_DIR}/helpers/cmake_configure.cmake")
set(GENERIC_CMAKE_BUILD "${PROJECT_SOURCE_DIR}/helpers/cmake_build.cmake")
set(GENERIC_CMAKE_INSTALL "${PROJECT_SOURCE_DIR}/helpers/cmake_install.cmake")
set(GENERIC_CMAKE_TEST "${PROJECT_SOURCE_DIR}/helpers/cmake_test.cmake")
set(GENERIC_CMAKE_ENVIRONMENT "${PROJECT_SOURCE_DIR}/helpers/cmake_environment.cmake")
set(GENERIC_PYTHON_INSTALL "${PROJECT_SOURCE_DIR}/helpers/python_install.cmake")
# Compute -G arg for configuring external projects with the same CMake generator:
if(CMAKE_EXTRA_GENERATOR)
set(BIOFORMATS_EP_GENERATOR "${CMAKE_EXTRA_GENERATOR} - ${CMAKE_GENERATOR}")
else()
set(BIOFORMATS_EP_GENERATOR "${CMAKE_GENERATOR}")
endif()
set(source-cache "${CMAKE_BINARY_DIR}/sourcecache" CACHE FILEPATH "Directory for cached source downloads")
file(MAKE_DIRECTORY ${source-cache})
set(BIOFORMATS_EP_INSTALL_DIR ${CMAKE_BINARY_DIR}/superbuild-install)
set(BIOFORMATS_EP_INCLUDE_DIR ${CMAKE_BINARY_DIR}/superbuild-install/${CMAKE_INSTALL_INCLUDEDIR})
set(BIOFORMATS_EP_LIB_DIR ${CMAKE_BINARY_DIR}/superbuild-install/${CMAKE_INSTALL_LIBDIR})
set(BIOFORMATS_EP_BIN_DIR ${CMAKE_BINARY_DIR}/superbuild-install/${CMAKE_INSTALL_BINDIR})
set(BIOFORMATS_EP_PYTHON_DIR ${CMAKE_BINARY_DIR}/python)
list(APPEND CMAKE_PREFIX_PATH "${BIOFORMATS_EP_INSTALL_DIR}")
# Look in superbuild staging tree when building
if(WIN32)
# Windows compiler flags
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I${BIOFORMATS_EP_INCLUDE_DIR}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${BIOFORMATS_EP_LIB_DIR}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -L${BIOFORMATS_EP_LIB_DIR}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L${BIOFORMATS_EP_LIB_DIR}")
endif()
set(EP_SCRIPT_CONFIG "${PROJECT_BINARY_DIR}/project-config.cmake")
string(REPLACE ";" "^^" BIOFORMATS_EP_ESCAPED_CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH}")
set(BIOFORMATS_EP_CMAKE_ARGS
"-DCMAKE_PREFIX_PATH:INTERNAL=${BIOFORMATS_EP_ESCAPED_CMAKE_PREFIX_PATH}"
"-DCMAKE_BUILD_TYPE:INTERNAL=${CMAKE_BUILD_TYPE}"
)
# Set CMake OSX variables needed to be passed to external projects
if(APPLE)
list(APPEND BIOFORMATS_EP_CMAKE_ARGS
-DCMAKE_OSX_ARCHITECTURES:STRING=${CMAKE_OSX_ARCHITECTURES}
-DCMAKE_OSX_SYSROOT:PATH=${CMAKE_OSX_SYSROOT}
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=${CMAKE_OSX_DEPLOYMENT_TARGET})
endif()
set(BIOFORMATS_EP_CMAKE_CACHE_ARGS
"-DCMAKE_AR:FILEPATH=${CMAKE_AR}"
"-DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}"
"-DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}"
"-DCMAKE_LINKER:FILEPATH=${CMAKE_LINKER}"
"-DCMAKE_MAKE_PROGRAM:FILEPATH=${CMAKE_MAKE_PROGRAM}"
"-DCMAKE_NM:FILEPATH=${CMAKE_NM}"
"-DCMAKE_OBJCOPY:FILEPATH=${CMAKE_OBJCOPY}"
"-DCMAKE_OBJDUMP:FILEPATH=${CMAKE_OBJDUMP}"
"-DCMAKE_RANLIB:FILEPATH=${CMAKE_RANLIB}"
"-DCMAKE_STRIP:FILEPATH=${CMAKE_STRIP}"
"-DCMAKE_MAKE_PROGRAM:FILEPATH=${CMAKE_MAKE_PROGRAM}"
"-DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}"
"-DCMAKE_CXX_FLAGS_DEBUG:STRING=${CMAKE_CXX_FLAGS_DEBUG}"
"-DCMAKE_CXX_FLAGS_MINSIZEREL:STRING=${CMAKE_CXX_FLAGS_MINSIZEREL}"
"-DCMAKE_CXX_FLAGS_RELEASE:STRING=${CMAKE_CXX_FLAGS_RELEASE}"
"-DCMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_CXX_FLAGS_RELWITHDEBINFO}"
"-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}"
"-DCMAKE_C_FLAGS_DEBUG:STRING=${CMAKE_C_FLAGS_DEBUG}"
"-DCMAKE_C_FLAGS_MINSIZEREL:STRING=${CMAKE_C_FLAGS_MINSIZEREL}"
"-DCMAKE_C_FLAGS_RELEASE:STRING=${CMAKE_C_FLAGS_RELEASE}"
"-DCMAKE_C_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_C_FLAGS_RELWITHDEBINFO}"
"-DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_EXE_LINKER_FLAGS}"
"-DCMAKE_EXE_LINKER_FLAGS_DEBUG:STRING=${CMAKE_EXE_LINKER_FLAGS_DEBUG}"
"-DCMAKE_EXE_LINKER_FLAGS_MINSIZEREL:STRING=${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL}"
"-DCMAKE_EXE_LINKER_FLAGS_RELEASE:STRING=${CMAKE_EXE_LINKER_FLAGS_RELEASE}"
"-DCMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}"
"-DCMAKE_MODULE_LINKER_FLAGS:STRING=${CMAKE_MODULE_LINKER_FLAGS}"
"-DCMAKE_MODULE_LINKER_FLAGS_DEBUG:STRING=${CMAKE_MODULE_LINKER_FLAGS_DEBUG}"
"-DCMAKE_MODULE_LINKER_FLAGS_MINSIZEREL:STRING=${CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL}"
"-DCMAKE_MODULE_LINKER_FLAGS_RELEASE:STRING=${CMAKE_MODULE_LINKER_FLAGS_RELEASE}"
"-DCMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO}"
"-DCMAKE_SHARED_LINKER_FLAGS:STRING=${CMAKE_SHARED_LINKER_FLAGS}"
"-DCMAKE_SHARED_LINKER_FLAGS_DEBUG:STRING=${CMAKE_SHARED_LINKER_FLAGS_DEBUG}"
"-DCMAKE_SHARED_LINKER_FLAGS_MINSIZEREL:STRING=${CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL}"
"-DCMAKE_SHARED_LINKER_FLAGS_RELEASE:STRING=${CMAKE_SHARED_LINKER_FLAGS_RELEASE}"
"-DCMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO}"
"-DCMAKE_STATIC_LINKER_FLAGS:STRING=${CMAKE_STATIC_LINKER_FLAGS}"
"-DCMAKE_STATIC_LINKER_FLAGS_DEBUG:STRING=${CMAKE_STATIC_LINKER_FLAGS_DEBUG}"
"-DCMAKE_STATIC_LINKER_FLAGS_MINSIZEREL:STRING=${CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL}"
"-DCMAKE_STATIC_LINKER_FLAGS_RELEASE:STRING=${CMAKE_STATIC_LINKER_FLAGS_RELEASE}"
"-DCMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO:STRING=${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO}"
"-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=${CMAKE_EXPORT_COMPILE_COMMANDS}"
"-DCMAKE_INSTALL_BINDIR:PATH=${CMAKE_INSTALL_BINDIR}"
"-DCMAKE_INSTALL_DATADIR:PATH=${CMAKE_INSTALL_DATADIR}"
"-DCMAKE_INSTALL_DATAROOTDIR:PATH=${CMAKE_INSTALL_DATAROOTDIR}"
"-DCMAKE_INSTALL_INCLUDEDIR:PATH=${CMAKE_INSTALL_INCLUDEDIR}"
"-DCMAKE_INSTALL_LIBDIR:PATH=${CMAKE_INSTALL_LIBDIR}"
"-DCMAKE_INSTALL_LIBEXECDIR:PATH=${CMAKE_INSTALL_LIBEXECDIR}"
"-DCMAKE_INSTALL_LOCALSTATEDIR:PATH=${CMAKE_INSTALL_LOCALSTATEDIR}"
"-DCMAKE_INSTALL_OLDINCLUDEDIR:PATH=${CMAKE_INSTALL_OLDINCLUDEDIR}"
"-DCMAKE_INSTALL_SBINDIR:PATH=${CMAKE_INSTALL_SBINDIR}"
"-DCMAKE_INSTALL_SHAREDSTATEDIR:PATH=${CMAKE_INSTALL_SHAREDSTATEDIR}"
"-DCMAKE_INSTALL_SYSCONFDIR:PATH=${CMAKE_INSTALL_SYSCONFDIR}"
"-DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH}"
"-DCMAKE_SKIP_INSTALL_RPATH:BOOL=${CMAKE_SKIP_INSTALL_RPATH}"
"-DCMAKE_SKIP_RPATH:BOOL=${CMAKE_SKIP_RPATH}"
"-DCMAKE_USE_RELATIVE_PATHS:BOOL=${CMAKE_USE_RELATIVE_PATHS}"
"-DCMAKE_VERBOSE_MAKEFILE:BOOL=${CMAKE_VERBOSE_MAKEFILE}"
${SUPERBUILD_OPTIONS}
)
# With make, we can do a DESTDIR staging install, otherwise we have to
# make the staging directory the installation prefix (which might
# cause problems when the contents are relocated).
if (CMAKE_GENERATOR MATCHES "Unix Makefiles")
list(APPEND BIOFORMATS_EP_CMAKE_CACHE_ARGS "-DCMAKE_INSTALL_PREFIX:PATH=")
else()
list(APPEND BIOFORMATS_EP_CMAKE_CACHE_ARGS "-DCMAKE_INSTALL_PREFIX:PATH=${BIOFORMATS_EP_INSTALL_DIR}")
endif()
# Primarily for Windows; will need extending for non-x86 platforms if required.
if(MSVC)
list(APPEND BIOFORMATS_EP_CMAKE_CACHE_ARGS
"-DMSVC:INTERNAL=${MSVC}"
"-DMSVC_VERSION:INTERNAL=${MSVC_VERSION}")
endif()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
list(APPEND BIOFORMATS_EP_CMAKE_CACHE_ARGS
"-DEP_PLATFORM_BITS:INTERNAL=64")
else()
list(APPEND BIOFORMATS_EP_CMAKE_CACHE_ARGS
"-DEP_PLATFORM_BITS:INTERNAL=32")
endif()
set(BIOFORMATS_EP_SCRIPT_ARGS
"-DCMAKE_C_COMPILER_ID:STRING=${CMAKE_C_COMPILER_ID}"
"-DCMAKE_CXX_COMPILER_ID:STRING=${CMAKE_CXX_COMPILER_ID}"
"-DBIOFORMATS_EP_INSTALL_DIR:PATH=${BIOFORMATS_EP_INSTALL_DIR}"
"-DBIOFORMATS_EP_PYTHON_DIR:PATH=${BIOFORMATS_EP_PYTHON_DIR}"
"-DBIOFORMATS_EP_BIN_DIR:PATH=${BIOFORMATS_EP_BIN_DIR}"
"-DBIOFORMATS_EP_INCLUDE_DIR:PATH=${BIOFORMATS_EP_INCLUDE_DIR}"
"-DBIOFORMATS_EP_LIB_DIR:PATH=${BIOFORMATS_EP_LIB_DIR}"
"-DGENERIC_CMAKE_ENVIRONMENT:PATH=${GENERIC_CMAKE_ENVIRONMENT}"
"-DCMAKE_GENERATOR:PATH=${CMAKE_GENERATOR}"
)
set(BIOFORMATS_EP_COMMON_ARGS
LIST_SEPARATOR "^^"
DOWNLOAD_DIR ${source-cache}
CMAKE_GENERATOR ${BIOFORMATS_EP_GENERATOR}
CMAKE_ARGS ${BIOFORMATS_EP_CMAKE_ARGS}
CMAKE_CACHE_ARGS ${BIOFORMATS_EP_CMAKE_CACHE_ARGS}
)
# Create script file for use by external project scripts, where the
# command-line and cache args won't be used.
foreach(arg ${BIOFORMATS_EP_CMAKE_ARGS}
${BIOFORMATS_EP_CMAKE_CACHE_ARGS}
${BIOFORMATS_EP_SCRIPT_ARGS})
if("${arg}" MATCHES "^-D(.*)")
set(arg "${CMAKE_MATCH_1}")
if("${arg}" MATCHES "^([^:]+):([^=]+)=(.*)$")
set(name "${CMAKE_MATCH_1}")
set(type "${CMAKE_MATCH_2}")
set(value "${CMAKE_MATCH_3}")
string(REPLACE "\"" "\\\"" value "${value}")
set(line "set(${name} \"${value}\" CACHE ${type} \"${name} from superbuild\")")
list(APPEND EP_SCRIPT_PARAMS "${line}")
else()
message(WARNING "Regex match failed for ${arg}")
endif()
endif()
endforeach()
string(REPLACE ";" "\n" EP_SCRIPT_PARAMS "${EP_SCRIPT_PARAMS}")
file(WRITE "${EP_SCRIPT_CONFIG}" "${EP_SCRIPT_PARAMS}")