CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkBlockSetCMakeOSXVariables.cmake
Go to the documentation of this file.
1 ###########################################################################
2 #
3 # Library: CTK
4 #
5 # Copyright (c) Kitware Inc.
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 # http://www.apache.org/licenses/LICENSE-2.0.txt
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19 ###########################################################################
20 
21 #
22 # ctkBlockSetCMakeOSXVariables
23 #
24 
25 #
26 # Adapted from Paraview/Superbuild/CMakeLists.txt
27 #
28 
29 # Note: Change architecture *before* any enable_language() or project()
30 # calls so that it's set properly to detect 64-bit-ness...
31 #
32 if(APPLE)
33 
34  # Waiting universal binaries are supported and tested, complain if
35  # multiple architectures are specified.
36  if(NOT "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
37  list(LENGTH CMAKE_OSX_ARCHITECTURES arch_count)
38  if(arch_count GREATER 1)
39  message(FATAL_ERROR "error: Only one value (i386 or x86_64) should be associated with CMAKE_OSX_ARCHITECTURES.")
40  endif()
41  endif()
42 
43  # See CMake/Modules/Platform/Darwin.cmake)
44  # 8.x == Mac OSX 10.4 (Tiger)
45  # 9.x == Mac OSX 10.5 (Leopard)
46  # 10.x == Mac OSX 10.6 (Snow Leopard)
47  # 10.x == Mac OSX 10.7 (Lion)
48  set(OSX_SDK_104_NAME "Tiger")
49  set(OSX_SDK_105_NAME "Leopard")
50  set(OSX_SDK_106_NAME "Snow Leopard")
51  set(OSX_SDK_107_NAME "Lion")
52 
53  set(OSX_SDK_ROOTS
54  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
55  /Developer/SDKs
56  )
57  set(SDK_VERSIONS_TO_CHECK 10.7 10.6 10.5)
58  foreach(SDK_VERSION ${SDK_VERSIONS_TO_CHECK})
59  if(NOT CMAKE_OSX_DEPLOYMENT_TARGET OR "${CMAKE_OSX_DEPLOYMENT_TARGET}" STREQUAL "")
60  foreach(SDK_ROOT ${OSX_SDK_ROOTS})
61  set(TEST_OSX_SYSROOT "${SDK_ROOT}/MacOSX${SDK_VERSION}.sdk")
62  if(EXISTS "${TEST_OSX_SYSROOT}")
63  # Retrieve OSX target name
64  string(REPLACE "." "" sdk_version_no_dot ${SDK_VERSION})
65  set(OSX_NAME ${OSX_SDK_${sdk_version_no_dot}_NAME})
66  set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Force build for 64-bit ${OSX_NAME}." FORCE)
67  set(CMAKE_OSX_DEPLOYMENT_TARGET "${SDK_VERSION}" CACHE STRING "Force build for 64-bit ${OSX_NAME}." FORCE)
68  set(CMAKE_OSX_SYSROOT "${TEST_OSX_SYSROOT}" CACHE PATH "Force build for 64-bit ${OSX_NAME}." FORCE)
69  message(STATUS "Setting OSX_ARCHITECTURES to '${CMAKE_OSX_ARCHITECTURES}' as none was specified.")
70  message(STATUS "Setting OSX_DEPLOYMENT_TARGET to '${SDK_VERSION}' as none was specified.")
71  message(STATUS "Setting OSX_SYSROOT to '${TEST_OSX_SYSROOT}' as none was specified.")
72  endif()
73  endforeach()
74  endif()
75  endforeach()
76 
77  if(NOT "${CMAKE_OSX_SYSROOT}" STREQUAL "")
78  if(NOT EXISTS "${CMAKE_OSX_SYSROOT}")
79  message(FATAL_ERROR "error: CMAKE_OSX_SYSROOT='${CMAKE_OSX_SYSROOT}' does not exist")
80  endif()
81  endif()
82  mark_as_advanced( CMAKE_OSX_ARCHITECTURES )
83  mark_as_advanced( CMAKE_OSX_DEPLOYMENT_TARGET )
84  mark_as_advanced( CMAKE_OSX_SYSROOT )
85 endif()