ctkBlockSetCMakeOSXVariables.cmake 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. # ctkBlockSetCMakeOSXVariables
  22. #
  23. #
  24. # Adapted from Paraview/Superbuild/CMakeLists.txt
  25. #
  26. # Note: Change architecture *before* any enable_language() or project()
  27. # calls so that it's set properly to detect 64-bit-ness...
  28. #
  29. if(APPLE)
  30. # Waiting universal binaries are supported and tested, complain if
  31. # multiple architectures are specified.
  32. if(NOT "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
  33. list(LENGTH CMAKE_OSX_ARCHITECTURES arch_count)
  34. if(arch_count GREATER 1)
  35. message(FATAL_ERROR "error: Only one value (i386 or x86_64) should be associated with CMAKE_OSX_ARCHITECTURES.")
  36. endif()
  37. endif()
  38. # See CMake/Modules/Platform/Darwin.cmake)
  39. # 8.x == Mac OSX 10.4 (Tiger)
  40. # 9.x == Mac OSX 10.5 (Leopard)
  41. # 10.x == Mac OSX 10.6 (Snow Leopard)
  42. # 10.x == Mac OSX 10.7 (Lion)
  43. set(OSX_SDK_104_NAME "Tiger")
  44. set(OSX_SDK_105_NAME "Leopard")
  45. set(OSX_SDK_106_NAME "Snow Leopard")
  46. set(OSX_SDK_107_NAME "Lion")
  47. set(OSX_SDK_ROOTS
  48. /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
  49. /Developer/SDKs
  50. )
  51. set(SDK_VERSIONS_TO_CHECK 10.7 10.6 10.5)
  52. foreach(SDK_VERSION ${SDK_VERSIONS_TO_CHECK})
  53. if(NOT CMAKE_OSX_DEPLOYMENT_TARGET OR "${CMAKE_OSX_DEPLOYMENT_TARGET}" STREQUAL "")
  54. foreach(SDK_ROOT ${OSX_SDK_ROOTS})
  55. set(TEST_OSX_SYSROOT "${SDK_ROOT}/MacOSX${SDK_VERSION}.sdk")
  56. if(EXISTS "${TEST_OSX_SYSROOT}")
  57. # Retrieve OSX target name
  58. string(REPLACE "." "" sdk_version_no_dot ${SDK_VERSION})
  59. set(OSX_NAME ${OSX_SDK_${sdk_version_no_dot}_NAME})
  60. set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Force build for 64-bit ${OSX_NAME}." FORCE)
  61. set(CMAKE_OSX_DEPLOYMENT_TARGET "${SDK_VERSION}" CACHE STRING "Force build for 64-bit ${OSX_NAME}." FORCE)
  62. set(CMAKE_OSX_SYSROOT "${TEST_OSX_SYSROOT}" CACHE PATH "Force build for 64-bit ${OSX_NAME}." FORCE)
  63. message(STATUS "Setting OSX_ARCHITECTURES to '${CMAKE_OSX_ARCHITECTURES}' as none was specified.")
  64. message(STATUS "Setting OSX_DEPLOYMENT_TARGET to '${SDK_VERSION}' as none was specified.")
  65. message(STATUS "Setting OSX_SYSROOT to '${TEST_OSX_SYSROOT}' as none was specified.")
  66. endif()
  67. endforeach()
  68. endif()
  69. endforeach()
  70. if(NOT "${CMAKE_OSX_SYSROOT}" STREQUAL "")
  71. if(NOT EXISTS "${CMAKE_OSX_SYSROOT}")
  72. message(FATAL_ERROR "error: CMAKE_OSX_SYSROOT='${CMAKE_OSX_SYSROOT}' does not exist")
  73. endif()
  74. endif()
  75. mark_as_advanced( CMAKE_OSX_ARCHITECTURES )
  76. mark_as_advanced( CMAKE_OSX_DEPLOYMENT_TARGET )
  77. mark_as_advanced( CMAKE_OSX_SYSROOT )
  78. endif()