platform_apple_xcode.cmake 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # ***** BEGIN GPL LICENSE BLOCK *****
  2. #
  3. # This program is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU General Public License
  5. # as published by the Free Software Foundation; either version 2
  6. # of the License, or (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software Foundation,
  15. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. #
  17. # The Original Code is Copyright (C) 2016, Blender Foundation
  18. # All rights reserved.
  19. # ***** END GPL LICENSE BLOCK *****
  20. # Xcode and system configuration for Apple.
  21. # require newer cmake on osx because of version handling,
  22. # older cmake cannot handle 2 digit subversion!
  23. cmake_minimum_required(VERSION 3.0.0)
  24. if(NOT CMAKE_OSX_ARCHITECTURES)
  25. set(CMAKE_OSX_ARCHITECTURES x86_64 CACHE STRING
  26. "Choose the architecture you want to build Blender for: i386, x86_64 or ppc"
  27. FORCE)
  28. endif()
  29. if(NOT DEFINED OSX_SYSTEM)
  30. execute_process(
  31. COMMAND xcodebuild -version -sdk macosx SDKVersion
  32. OUTPUT_VARIABLE OSX_SYSTEM
  33. OUTPUT_STRIP_TRAILING_WHITESPACE)
  34. endif()
  35. # workaround for incorrect cmake xcode lookup for developer previews - XCODE_VERSION does not
  36. # take xcode-select path into account but would always look into /Applications/Xcode.app
  37. # while dev versions are named Xcode<version>-DP<preview_number>
  38. execute_process(
  39. COMMAND xcode-select --print-path
  40. OUTPUT_VARIABLE XCODE_CHECK OUTPUT_STRIP_TRAILING_WHITESPACE)
  41. string(REPLACE "/Contents/Developer" "" XCODE_BUNDLE ${XCODE_CHECK}) # truncate to bundlepath in any case
  42. if(${CMAKE_GENERATOR} MATCHES "Xcode")
  43. # earlier xcode has no bundled developer dir, no sense in getting xcode path from
  44. if(${XCODE_VERSION} VERSION_GREATER 4.2)
  45. # reduce to XCode name without dp extension
  46. string(SUBSTRING "${XCODE_CHECK}" 14 6 DP_NAME)
  47. if(${DP_NAME} MATCHES Xcode5)
  48. set(XCODE_VERSION 5)
  49. endif()
  50. endif()
  51. ##### cmake incompatibility with xcode 4.3 and higher #####
  52. if(${XCODE_VERSION} MATCHES '') # cmake fails due looking for xcode in the wrong path, thus will be empty var
  53. message(FATAL_ERROR "Xcode 4.3 and higher must be used with cmake 2.8-8 or higher")
  54. endif()
  55. ### end cmake incompatibility with xcode 4.3 and higher ###
  56. if(${XCODE_VERSION} VERSION_EQUAL 4 OR ${XCODE_VERSION} VERSION_GREATER 4 AND ${XCODE_VERSION} VERSION_LESS 4.3)
  57. # Xcode 4 defaults to the Apple LLVM Compiler.
  58. # Override the default compiler selection because Blender only compiles with gcc up to xcode 4.2
  59. set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvmgcc42")
  60. message(STATUS "Setting compiler to: " ${CMAKE_XCODE_ATTRIBUTE_GCC_VERSION})
  61. endif()
  62. else() # unix makefile generator does not fill XCODE_VERSION var, so we get it with a command
  63. execute_process(COMMAND xcodebuild -version OUTPUT_VARIABLE XCODE_VERS_BUILD_NR)
  64. string(SUBSTRING "${XCODE_VERS_BUILD_NR}" 6 3 XCODE_VERSION) # truncate away build-nr
  65. unset(XCODE_VERS_BUILD_NR)
  66. endif()
  67. message(STATUS "Detected OS X ${OSX_SYSTEM} and Xcode ${XCODE_VERSION} at ${XCODE_BUNDLE}")
  68. if(${XCODE_VERSION} VERSION_LESS 4.3)
  69. # use guaranteed existing sdk
  70. set(CMAKE_OSX_SYSROOT /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk CACHE PATH "" FORCE)
  71. else()
  72. # note: xcode-select path could be ambiguous,
  73. # cause /Applications/Xcode.app/Contents/Developer or /Applications/Xcode.app would be allowed
  74. # so i use a selfcomposed bundlepath here
  75. set(OSX_SYSROOT_PREFIX ${XCODE_BUNDLE}/Contents/Developer/Platforms/MacOSX.platform)
  76. message(STATUS "OSX_SYSROOT_PREFIX: " ${OSX_SYSROOT_PREFIX})
  77. set(OSX_DEVELOPER_PREFIX /Developer/SDKs/MacOSX${OSX_SYSTEM}.sdk) # use guaranteed existing sdk
  78. set(CMAKE_OSX_SYSROOT ${OSX_SYSROOT_PREFIX}/${OSX_DEVELOPER_PREFIX} CACHE PATH "" FORCE)
  79. if(${CMAKE_GENERATOR} MATCHES "Xcode")
  80. # to silence sdk not found warning, just overrides CMAKE_OSX_SYSROOT
  81. set(CMAKE_XCODE_ATTRIBUTE_SDKROOT macosx${OSX_SYSTEM})
  82. endif()
  83. endif()
  84. # 10.11 is our min. target, if you use higher sdk, weak linking happens
  85. if(CMAKE_OSX_DEPLOYMENT_TARGET)
  86. if(${CMAKE_OSX_DEPLOYMENT_TARGET} VERSION_LESS 10.11)
  87. message(STATUS "Setting deployment target to 10.11, lower versions are not supported")
  88. set(CMAKE_OSX_DEPLOYMENT_TARGET "10.11" CACHE STRING "" FORCE)
  89. endif()
  90. else()
  91. set(CMAKE_OSX_DEPLOYMENT_TARGET "10.11" CACHE STRING "" FORCE)
  92. endif()
  93. if(NOT ${CMAKE_GENERATOR} MATCHES "Xcode")
  94. # force CMAKE_OSX_DEPLOYMENT_TARGET for makefiles, will not work else ( cmake bug ? )
  95. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
  96. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}")
  97. add_definitions("-DMACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}")
  98. endif()