comparison OrthancFramework/Resources/CMake/BoostConfiguration.cmake @ 4044:d25f4c0fa160 framework

splitting code into OrthancFramework and OrthancServer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 10 Jun 2020 20:30:34 +0200
parents Resources/CMake/BoostConfiguration.cmake@05a363186da6
children 05b8fd21089c
comparison
equal deleted inserted replaced
4043:6c6239aec462 4044:d25f4c0fa160
1 if (STATIC_BUILD OR NOT USE_SYSTEM_BOOST)
2 set(BOOST_STATIC 1)
3 else()
4 include(FindBoost)
5
6 set(BOOST_STATIC 0)
7 #set(Boost_DEBUG 1)
8 #set(Boost_USE_STATIC_LIBS ON)
9
10 if (ENABLE_LOCALE)
11 list(APPEND ORTHANC_BOOST_COMPONENTS locale)
12 endif()
13
14 list(APPEND ORTHANC_BOOST_COMPONENTS filesystem thread system date_time regex)
15 find_package(Boost COMPONENTS ${ORTHANC_BOOST_COMPONENTS})
16
17 if (NOT Boost_FOUND)
18 foreach (item ${ORTHANC_BOOST_COMPONENTS})
19 string(TOUPPER ${item} tmp)
20
21 if (Boost_${tmp}_FOUND)
22 set(tmp2 "found")
23 else()
24 set(tmp2 "missing")
25 endif()
26
27 message("Boost component ${item} - ${tmp2}")
28 endforeach()
29
30 message(FATAL_ERROR "Unable to locate Boost on this system")
31 endif()
32
33
34 # Patch by xnox to fix issue #166 (CMake find_boost version is now
35 # broken with newer boost/cmake)
36 # https://bitbucket.org/sjodogne/orthanc/issues/166/
37 if (POLICY CMP0093)
38 set(BOOST144 1.44)
39 else()
40 set(BOOST144 104400)
41 endif()
42
43
44 # Boost releases 1.44 through 1.47 supply both V2 and V3 filesystem
45 # http://www.boost.org/doc/libs/1_46_1/libs/filesystem/v3/doc/index.htm
46 if (${Boost_VERSION} LESS ${BOOST144})
47 add_definitions(
48 -DBOOST_HAS_FILESYSTEM_V3=0
49 )
50 else()
51 add_definitions(
52 -DBOOST_HAS_FILESYSTEM_V3=1
53 -DBOOST_FILESYSTEM_VERSION=3
54 )
55 endif()
56
57 include_directories(${Boost_INCLUDE_DIRS})
58 link_libraries(${Boost_LIBRARIES})
59 endif()
60
61
62 if (BOOST_STATIC)
63 ##
64 ## Parameters for static compilation of Boost
65 ##
66
67 set(BOOST_NAME boost_1_69_0)
68 set(BOOST_VERSION 1.69.0)
69 set(BOOST_BCP_SUFFIX bcpdigest-1.5.6)
70 set(BOOST_MD5 "579bccc0ea4d1a261c1d0c5e27446c3d")
71 set(BOOST_URL "http://orthanc.osimis.io/ThirdPartyDownloads/${BOOST_NAME}_${BOOST_BCP_SUFFIX}.tar.gz")
72 set(BOOST_SOURCES_DIR ${CMAKE_BINARY_DIR}/${BOOST_NAME})
73
74 if (IS_DIRECTORY "${BOOST_SOURCES_DIR}")
75 set(FirstRun OFF)
76 else()
77 set(FirstRun ON)
78 endif()
79
80 DownloadPackage(${BOOST_MD5} ${BOOST_URL} "${BOOST_SOURCES_DIR}")
81
82
83 ##
84 ## Patching boost
85 ##
86
87 execute_process(
88 COMMAND ${PATCH_EXECUTABLE} -p0 -N -i
89 ${ORTHANC_ROOT}/Resources/Patches/boost-${BOOST_VERSION}-linux-standard-base.patch
90 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
91 RESULT_VARIABLE Failure
92 )
93
94 if (FirstRun AND Failure)
95 message(FATAL_ERROR "Error while patching a file")
96 endif()
97
98
99 ##
100 ## Generic configuration of Boost
101 ##
102
103 if (CMAKE_COMPILER_IS_GNUCXX)
104 add_definitions(-isystem ${BOOST_SOURCES_DIR})
105 endif()
106
107 include_directories(
108 BEFORE ${BOOST_SOURCES_DIR}
109 )
110
111 if (ORTHANC_BUILDING_FRAMEWORK_LIBRARY)
112 add_definitions(
113 # Packaging Boost inside the Orthanc Framework DLL
114 -DBOOST_ALL_DYN_LINK
115 -DBOOST_THREAD_BUILD_DLL
116 #-DBOOST_REGEX_BUILD_DLL
117 )
118 else()
119 add_definitions(
120 # Static build of Boost (this was the only possibility in
121 # Orthanc <= 1.7.1)
122 -DBOOST_ALL_NO_LIB
123 -DBOOST_ALL_NOLIB
124 -DBOOST_DATE_TIME_NO_LIB
125 -DBOOST_THREAD_BUILD_LIB
126 -DBOOST_PROGRAM_OPTIONS_NO_LIB
127 -DBOOST_REGEX_NO_LIB
128 -DBOOST_SYSTEM_NO_LIB
129 -DBOOST_LOCALE_NO_LIB
130 )
131 endif()
132
133 add_definitions(
134 # In static builds, explicitly prevent Boost from using the system
135 # locale in lexical casts. This is notably important if
136 # "boost::lexical_cast<double>()" is applied to strings containing
137 # "," instead of "." as decimal separators. Check out function
138 # "OrthancStone::LinearAlgebra::ParseVector()".
139 -DBOOST_LEXICAL_CAST_ASSUME_C_LOCALE
140 )
141
142 set(BOOST_SOURCES
143 ${BOOST_SOURCES_DIR}/libs/system/src/error_code.cpp
144 )
145
146 if ("${CMAKE_SYSTEM_VERSION}" STREQUAL "LinuxStandardBase" OR
147 "${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
148 add_definitions(
149 -DBOOST_SYSTEM_USE_STRERROR=1
150 )
151 endif()
152
153
154 ##
155 ## Configuration of boost::thread
156 ##
157
158 if (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR
159 CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR
160 CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR
161 CMAKE_SYSTEM_NAME STREQUAL "kFreeBSD" OR
162 CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR
163 CMAKE_SYSTEM_NAME STREQUAL "PNaCl" OR
164 CMAKE_SYSTEM_NAME STREQUAL "NaCl32" OR
165 CMAKE_SYSTEM_NAME STREQUAL "NaCl64" OR
166 CMAKE_SYSTEM_NAME STREQUAL "Android")
167 list(APPEND BOOST_SOURCES
168 ${BOOST_SOURCES_DIR}/libs/atomic/src/lockpool.cpp
169 ${BOOST_SOURCES_DIR}/libs/thread/src/pthread/once.cpp
170 ${BOOST_SOURCES_DIR}/libs/thread/src/pthread/thread.cpp
171 )
172
173 if ("${CMAKE_SYSTEM_VERSION}" STREQUAL "LinuxStandardBase" OR
174 CMAKE_SYSTEM_NAME STREQUAL "PNaCl" OR
175 CMAKE_SYSTEM_NAME STREQUAL "NaCl32" OR
176 CMAKE_SYSTEM_NAME STREQUAL "NaCl64")
177 add_definitions(-DBOOST_HAS_SCHED_YIELD=1)
178 endif()
179
180 # Fix for error: "boost_1_69_0/boost/chrono/detail/inlined/mac/thread_clock.hpp:54:28:
181 # error: use of undeclared identifier 'pthread_mach_thread_np'"
182 # https://github.com/envoyproxy/envoy/pull/1785
183 if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
184 add_definitions(-D_DARWIN_C_SOURCE=1)
185 endif()
186
187 elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
188 list(APPEND BOOST_SOURCES
189 ${BOOST_SOURCES_DIR}/libs/thread/src/win32/tss_dll.cpp
190 ${BOOST_SOURCES_DIR}/libs/thread/src/win32/thread.cpp
191 ${BOOST_SOURCES_DIR}/libs/thread/src/win32/tss_pe.cpp
192 )
193
194 elseif (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
195 # No support for threads in asm.js/WebAssembly
196
197 else()
198 message(FATAL_ERROR "Support your platform here")
199 endif()
200
201
202 ##
203 ## Configuration of boost::regex
204 ##
205
206 aux_source_directory(${BOOST_SOURCES_DIR}/libs/regex/src BOOST_REGEX_SOURCES)
207
208 list(APPEND BOOST_SOURCES
209 ${BOOST_REGEX_SOURCES}
210 )
211
212
213 ##
214 ## Configuration of boost::datetime
215 ##
216
217 list(APPEND BOOST_SOURCES
218 ${BOOST_SOURCES_DIR}/libs/date_time/src/gregorian/greg_month.cpp
219 )
220
221
222 ##
223 ## Configuration of boost::filesystem
224 ##
225
226 if (CMAKE_SYSTEM_NAME STREQUAL "PNaCl" OR
227 CMAKE_SYSTEM_NAME STREQUAL "NaCl32" OR
228 CMAKE_SYSTEM_NAME STREQUAL "NaCl64" OR
229 CMAKE_SYSTEM_NAME STREQUAL "Android")
230 # boost::filesystem is not available on PNaCl
231 add_definitions(
232 -DBOOST_HAS_FILESYSTEM_V3=0
233 -D__INTEGRITY=1
234 )
235 else()
236 add_definitions(
237 -DBOOST_HAS_FILESYSTEM_V3=1
238 )
239 list(APPEND BOOST_SOURCES
240 ${BOOST_NAME}/libs/filesystem/src/codecvt_error_category.cpp
241 ${BOOST_NAME}/libs/filesystem/src/operations.cpp
242 ${BOOST_NAME}/libs/filesystem/src/path.cpp
243 ${BOOST_NAME}/libs/filesystem/src/path_traits.cpp
244 )
245
246 if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR
247 CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR
248 CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
249 list(APPEND BOOST_SOURCES
250 ${BOOST_SOURCES_DIR}/libs/filesystem/src/utf8_codecvt_facet.cpp
251 )
252
253 elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
254 list(APPEND BOOST_SOURCES
255 ${BOOST_NAME}/libs/filesystem/src/windows_file_codecvt.cpp
256 )
257 endif()
258 endif()
259
260
261 ##
262 ## Configuration of boost::locale
263 ##
264
265 if (NOT ENABLE_LOCALE)
266 message("boost::locale is disabled")
267 else()
268 set(BOOST_ICU_SOURCES
269 ${BOOST_SOURCES_DIR}/libs/locale/src/icu/boundary.cpp
270 ${BOOST_SOURCES_DIR}/libs/locale/src/icu/codecvt.cpp
271 ${BOOST_SOURCES_DIR}/libs/locale/src/icu/collator.cpp
272 ${BOOST_SOURCES_DIR}/libs/locale/src/icu/conversion.cpp
273 ${BOOST_SOURCES_DIR}/libs/locale/src/icu/date_time.cpp
274 ${BOOST_SOURCES_DIR}/libs/locale/src/icu/formatter.cpp
275 ${BOOST_SOURCES_DIR}/libs/locale/src/icu/icu_backend.cpp
276 ${BOOST_SOURCES_DIR}/libs/locale/src/icu/numeric.cpp
277 ${BOOST_SOURCES_DIR}/libs/locale/src/icu/time_zone.cpp
278 )
279
280 list(APPEND BOOST_SOURCES
281 ${BOOST_SOURCES_DIR}/libs/locale/src/encoding/codepage.cpp
282 ${BOOST_SOURCES_DIR}/libs/locale/src/shared/generator.cpp
283 ${BOOST_SOURCES_DIR}/libs/locale/src/shared/date_time.cpp
284 ${BOOST_SOURCES_DIR}/libs/locale/src/shared/formatting.cpp
285 ${BOOST_SOURCES_DIR}/libs/locale/src/shared/ids.cpp
286 ${BOOST_SOURCES_DIR}/libs/locale/src/shared/localization_backend.cpp
287 ${BOOST_SOURCES_DIR}/libs/locale/src/shared/message.cpp
288 ${BOOST_SOURCES_DIR}/libs/locale/src/shared/mo_lambda.cpp
289 ${BOOST_SOURCES_DIR}/libs/locale/src/util/codecvt_converter.cpp
290 ${BOOST_SOURCES_DIR}/libs/locale/src/util/default_locale.cpp
291 ${BOOST_SOURCES_DIR}/libs/locale/src/util/gregorian.cpp
292 ${BOOST_SOURCES_DIR}/libs/locale/src/util/info.cpp
293 ${BOOST_SOURCES_DIR}/libs/locale/src/util/locale_data.cpp
294 )
295
296 if (CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR
297 CMAKE_SYSTEM_VERSION STREQUAL "LinuxStandardBase")
298 add_definitions(
299 -DBOOST_LOCALE_NO_WINAPI_BACKEND=1
300 -DBOOST_LOCALE_NO_POSIX_BACKEND=1
301 )
302
303 list(APPEND BOOST_SOURCES
304 ${BOOST_SOURCES_DIR}/libs/locale/src/std/codecvt.cpp
305 ${BOOST_SOURCES_DIR}/libs/locale/src/std/collate.cpp
306 ${BOOST_SOURCES_DIR}/libs/locale/src/std/converter.cpp
307 ${BOOST_SOURCES_DIR}/libs/locale/src/std/numeric.cpp
308 ${BOOST_SOURCES_DIR}/libs/locale/src/std/std_backend.cpp
309 )
310
311 if (BOOST_LOCALE_BACKEND STREQUAL "gcc" OR
312 BOOST_LOCALE_BACKEND STREQUAL "libiconv")
313 add_definitions(-DBOOST_LOCALE_WITH_ICONV=1)
314 elseif (BOOST_LOCALE_BACKEND STREQUAL "icu")
315 add_definitions(-DBOOST_LOCALE_WITH_ICU=1)
316 list(APPEND BOOST_SOURCES ${BOOST_ICU_SOURCES})
317 else()
318 message(FATAL_ERROR "Unsupported value for BOOST_LOCALE_BACKEND: ${BOOST_LOCALE_BACKEND}")
319 endif()
320
321 elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR
322 CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR
323 CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR
324 CMAKE_SYSTEM_NAME STREQUAL "kFreeBSD" OR
325 CMAKE_SYSTEM_NAME STREQUAL "PNaCl" OR
326 CMAKE_SYSTEM_NAME STREQUAL "NaCl32" OR
327 CMAKE_SYSTEM_NAME STREQUAL "NaCl64" OR
328 CMAKE_SYSTEM_NAME STREQUAL "Emscripten") # For WebAssembly or asm.js
329 add_definitions(
330 -DBOOST_LOCALE_NO_WINAPI_BACKEND=1
331 -DBOOST_LOCALE_NO_STD_BACKEND=1
332 )
333
334 list(APPEND BOOST_SOURCES
335 ${BOOST_SOURCES_DIR}/libs/locale/src/posix/codecvt.cpp
336 ${BOOST_SOURCES_DIR}/libs/locale/src/posix/collate.cpp
337 ${BOOST_SOURCES_DIR}/libs/locale/src/posix/converter.cpp
338 ${BOOST_SOURCES_DIR}/libs/locale/src/posix/numeric.cpp
339 ${BOOST_SOURCES_DIR}/libs/locale/src/posix/posix_backend.cpp
340 )
341
342 if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten" OR
343 BOOST_LOCALE_BACKEND STREQUAL "gcc" OR
344 BOOST_LOCALE_BACKEND STREQUAL "libiconv")
345 # In WebAssembly or asm.js, we rely on the version of iconv
346 # that is shipped with the stdlib
347 add_definitions(-DBOOST_LOCALE_WITH_ICONV=1)
348 elseif (BOOST_LOCALE_BACKEND STREQUAL "icu")
349 add_definitions(-DBOOST_LOCALE_WITH_ICU=1)
350 list(APPEND BOOST_SOURCES ${BOOST_ICU_SOURCES})
351 else()
352 message(FATAL_ERROR "Unsupported value for BOOST_LOCALE_BACKEND: ${BOOST_LOCALE_BACKEND}")
353 endif()
354
355 elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
356 add_definitions(
357 -DBOOST_LOCALE_NO_POSIX_BACKEND=1
358 -DBOOST_LOCALE_NO_STD_BACKEND=1
359 )
360
361 list(APPEND BOOST_SOURCES
362 ${BOOST_SOURCES_DIR}/libs/locale/src/win32/collate.cpp
363 ${BOOST_SOURCES_DIR}/libs/locale/src/win32/converter.cpp
364 ${BOOST_SOURCES_DIR}/libs/locale/src/win32/lcid.cpp
365 ${BOOST_SOURCES_DIR}/libs/locale/src/win32/numeric.cpp
366 ${BOOST_SOURCES_DIR}/libs/locale/src/win32/win_backend.cpp
367 )
368
369 # Starting with release 0.8.2, Orthanc statically links against
370 # libiconv on Windows. Indeed, the "WCONV" library of Windows XP
371 # seems not to support properly several codepages (notably
372 # "Latin3", "Hebrew", and "Arabic"). Set "BOOST_LOCALE_BACKEND"
373 # to "wconv" to use WCONV anyway.
374
375 if (BOOST_LOCALE_BACKEND STREQUAL "libiconv")
376 add_definitions(-DBOOST_LOCALE_WITH_ICONV=1)
377 elseif (BOOST_LOCALE_BACKEND STREQUAL "icu")
378 add_definitions(-DBOOST_LOCALE_WITH_ICU=1)
379 list(APPEND BOOST_SOURCES ${BOOST_ICU_SOURCES})
380 elseif (BOOST_LOCALE_BACKEND STREQUAL "wconv")
381 message("Using Window's wconv")
382 add_definitions(-DBOOST_LOCALE_WITH_WCONV=1)
383 else()
384 message(FATAL_ERROR "Unsupported value for BOOST_LOCALE_BACKEND on Windows: ${BOOST_LOCALE_BACKEND}")
385 endif()
386
387 else()
388 message(FATAL_ERROR "Support your platform here")
389 endif()
390 endif()
391
392
393 source_group(ThirdParty\\boost REGULAR_EXPRESSION ${BOOST_SOURCES_DIR}/.*)
394
395 endif()