-
Notifications
You must be signed in to change notification settings - Fork 460
/
SlicerBlockSetCMakeOSXVariables.cmake
124 lines (113 loc) · 5.26 KB
/
SlicerBlockSetCMakeOSXVariables.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
################################################################################
#
# Program: 3D Slicer
#
# Copyright (c) Kitware Inc.
#
# See COPYRIGHT.txt
# or http://www.slicer.org/copyright/copyright.txt for details.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc.
# and was partially funded by NIH grant 3P41RR013218-12S1
#
################################################################################
#
# SlicerBlockSetCMakeOSXVariables
#
#
# Adapted from Paraview/Superbuild/CMakeLists.txt
#
# Note: Change architecture *before* any enable_language() or project()
# calls so that it's set properly to detect 64-bit-ness, and
# deployment target for the standard c++ library.
#
if(APPLE)
# Waiting universal binaries are supported and tested, complain if
# multiple architectures are specified.
if(NOT "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
list(LENGTH CMAKE_OSX_ARCHITECTURES arch_count)
if(arch_count GREATER 1)
message(FATAL_ERROR "error: Only one value (i386 or x86_64) should be associated with CMAKE_OSX_ARCHITECTURES.")
endif()
endif()
# See CMake/Modules/Platform/Darwin.cmake)
# 8.x == Mac OSX 10.4 (Tiger)
# 9.x == Mac OSX 10.5 (Leopard)
# 10.x == Mac OSX 10.6 (Snow Leopard)
# 11.x == Mac OSX 10.7 (Lion)
# 12.x == Mac OSX 10.8 (Mountain Lion)
# 13.x == Mac OSX 10.9 (Mavericks)
# 14.x == Mac OSX 10.10 (Yosemite)
set(OSX_SDK_104_NAME "Tiger")
set(OSX_SDK_105_NAME "Leopard")
set(OSX_SDK_106_NAME "Snow Leopard")
set(OSX_SDK_107_NAME "Lion")
set(OSX_SDK_108_NAME "Mountain Lion")
set(OSX_SDK_109_NAME "Mavericks")
set(OSX_SDK_1010_NAME "Yosemite")
set(OSX_SDK_ROOTS
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
/Developer/SDKs
)
# Explicitly set the OSX_SYSROOT to the latest one, as its required
# when the SX_DEPLOYMENT_TARGET is explicitly set
foreach(SDK_ROOT ${OSX_SDK_ROOTS})
if( "x${CMAKE_OSX_SYSROOT}x" STREQUAL "xx")
file(GLOB SDK_SYSROOTS "${SDK_ROOT}/MacOSX*.sdk")
if(NOT "x${SDK_SYSROOTS}x" STREQUAL "xx")
set(SDK_SYSROOT_NEWEST "")
set(SDK_VERSION "0")
# find the latest SDK
foreach(SDK_ROOT_I ${SDK_SYSROOTS})
# extract version from SDK
string(REGEX MATCH "MacOSX([0-9]+\\.[0-9]+)\\.sdk" _match "${SDK_ROOT_I}")
if("${CMAKE_MATCH_1}" VERSION_GREATER "${SDK_VERSION}")
set(SDK_SYSROOT_NEWEST "${SDK_ROOT_I}")
set(SDK_VERSION "${CMAKE_MATCH_1}")
endif()
endforeach()
if(NOT "x${SDK_SYSROOT_NEWEST}x" STREQUAL "xx")
string(REPLACE "." "" sdk_version_no_dot ${SDK_VERSION})
set(OSX_NAME ${OSX_SDK_${sdk_version_no_dot}_NAME})
set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Force build for 64-bit ${OSX_NAME}." FORCE)
set(CMAKE_OSX_SYSROOT "${SDK_SYSROOT_NEWEST}" CACHE PATH "Force build for 64-bit ${OSX_NAME}." FORCE)
message(STATUS "Setting OSX_ARCHITECTURES to '${CMAKE_OSX_ARCHITECTURES}' as none was specified.")
message(STATUS "Setting OSX_SYSROOT to latest '${CMAKE_OSX_SYSROOT}' as none was specified.")
endif()
endif()
endif()
endforeach()
if("x${CMAKE_OSX_DEPLOYMENT_TARGET}x" STREQUAL "xx")
string(REGEX MATCH "MacOSX([0-9]+\\.[0-9]+)\\.sdk" _match "${CMAKE_OSX_SYSROOT}")
set(SDK_VERSION "${CMAKE_MATCH_1}")
if( "${SDK_VERSION}" VERSION_GREATER "10.8" )
# add to cache to allow interactive editing after fatal error
set(CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE PATH "Deployment target needs to be explicitly set." FORCE)
message(FATAL_ERROR
"The OSX_SYSROOT is set to version ${SDK_VERSION} (>10.8) and OSX_DEPLOYMENT_TARGET is not explicitly set!\n"
"Since:\n"
" (1) the default runtime associated with >=10.9 deployment target is 'libc++'.[1]\n"
" (2) the default runtime associated with <=10.8 deployment target is 'libstdc++'.\n"
" (3) Qt support for 'macx-clang-libc++' is listed as 'unsupported' mkspecs.\n"
" (4) Qt binaries may be build against 'libstdc++' or 'libc++'.\n"
" (5) Mixing the two different runtime in binaries is unstable.\n"
" [1]http://stackoverflow.com/questions/19637164/c-linking-error-after-upgrading-to-mac-os-x-10-9-xcode-5-0-1/19637199#19637199\n"
"--------------------------------\n"
"Run '$otool -L $(which qmake) |grep lib.\\*c++' to check what library Qt is built against:\n"
" (1) if it is libstdc++ then add '-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.8' (or older) to the cmake command line.\n"
" (2) if it is libc++ then add '-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.9' (or newer) to the cmake command line.\n"
)
endif()
endif()
if(NOT "${CMAKE_OSX_SYSROOT}" STREQUAL "")
if(NOT EXISTS "${CMAKE_OSX_SYSROOT}")
message(FATAL_ERROR "error: CMAKE_OSX_SYSROOT='${CMAKE_OSX_SYSROOT}' does not exist")
endif()
endif()
endif()