Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Modules / Platform / Darwin.cmake
blobb0179f4324bd83f7bdaf4424e1d13797d347391f
1 SET(APPLE 1)
3 # Darwin versions:
4 #   6.x == Mac OSX 10.2
5 #   7.x == Mac OSX 10.3
6 #   8.x == Mac OSX 10.4
7 #   9.x == Mac OSX 10.5
8 STRING(REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_SYSTEM_VERSION}")
9 STRING(REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\2" DARWIN_MINOR_VERSION "${CMAKE_SYSTEM_VERSION}")
11 # Do not use the "-Wl,-search_paths_first" flag with the OSX 10.2 compiler.
12 # Done this way because it is too early to do a TRY_COMPILE.
13 IF(NOT DEFINED HAVE_FLAG_SEARCH_PATHS_FIRST)
14   SET(HAVE_FLAG_SEARCH_PATHS_FIRST 0)
15   IF("${DARWIN_MAJOR_VERSION}" GREATER 6)
16     SET(HAVE_FLAG_SEARCH_PATHS_FIRST 1)
17   ENDIF("${DARWIN_MAJOR_VERSION}" GREATER 6)
18 ENDIF(NOT DEFINED HAVE_FLAG_SEARCH_PATHS_FIRST)
19 # More desirable, but does not work:
20   #INCLUDE(CheckCXXCompilerFlag)
21   #CHECK_CXX_COMPILER_FLAG("-Wl,-search_paths_first" HAVE_FLAG_SEARCH_PATHS_FIRST)
23 SET(CMAKE_SHARED_LIBRARY_PREFIX "lib")
24 SET(CMAKE_SHARED_LIBRARY_SUFFIX ".dylib")
25 SET(CMAKE_SHARED_MODULE_PREFIX "lib")
26 SET(CMAKE_SHARED_MODULE_SUFFIX ".so")
27 SET(CMAKE_MODULE_EXISTS 1)
28 SET(CMAKE_DL_LIBS "")
30 SET(CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ")
31 SET(CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ")
32 SET(CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}")
33 SET(CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}")
35 SET(CMAKE_C_LINK_FLAGS "-headerpad_max_install_names")
36 SET(CMAKE_CXX_LINK_FLAGS "-headerpad_max_install_names")
38 IF(HAVE_FLAG_SEARCH_PATHS_FIRST)
39   SET(CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}")
40   SET(CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}")
41 ENDIF(HAVE_FLAG_SEARCH_PATHS_FIRST)
43 SET(CMAKE_PLATFORM_HAS_INSTALLNAME 1)
44 SET(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -headerpad_max_install_names")
45 SET(CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -headerpad_max_install_names")
46 SET(CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,")
47 SET(CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,")
48 SET(CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a")
50 # hack: if a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old build tree
51 # (where install_name_tool was hardcoded) and where CMAKE_INSTALL_NAME_TOOL isn't in the cache
52 # and still cmake didn't fail in CMakeFindBinUtils.cmake (because it isn't rerun)
53 # hardcode CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did before, Alex
54 IF(NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
55   FIND_PROGRAM(CMAKE_INSTALL_NAME_TOOL install_name_tool)
56 ENDIF(NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
58 # Set the assumed (Pre 10.5 or Default) location of the developer tools
59 SET(OSX_DEVELOPER_ROOT "/Developer")
61 # Find installed SDKs
62 FILE(GLOB _CMAKE_OSX_SDKS "${OSX_DEVELOPER_ROOT}/SDKs/*")
64 # If nothing is found there, then try locating the dev tools based on the xcode-select tool
65 # (available in Xcode >= 3.0 installations)
66 IF(NOT _CMAKE_OSX_SDKS)
67   FIND_PROGRAM(CMAKE_XCODE_SELECT xcode-select)
68   IF(CMAKE_XCODE_SELECT)
69     EXECUTE_PROCESS(COMMAND ${CMAKE_XCODE_SELECT} "-print-path"
70       OUTPUT_VARIABLE OSX_DEVELOPER_ROOT)
71     FILE(GLOB _CMAKE_OSX_SDKS "${OSX_DEVELOPER_ROOT}/SDKs/*")
72   ENDIF(CMAKE_XCODE_SELECT)
73 ENDIF(NOT _CMAKE_OSX_SDKS)
75 # Set CMAKE_OSX_DEPLOYMENT_TARGET_DEFAULT to the current version of OS X
76 EXECUTE_PROCESS(COMMAND sw_vers -productVersion OUTPUT_VARIABLE CURRENT_OSX_VERSION)
77 STRING(REGEX REPLACE "^.*(10)\\.([0-9]+)\\.*([0-9]+)*.*$" "\\1.\\2"
78   CMAKE_OSX_DEPLOYMENT_TARGET_DEFAULT ${CURRENT_OSX_VERSION})
80 # Set CMAKE_OSX_SYSROOT_DEFAULT based on CMAKE_OSX_DEPLOYMENT_TARGET_DEFAULT.
81 # This next block assumes that Apple will start being consistent with
82 # its SDK names from here on out...
83 IF(CMAKE_OSX_DEPLOYMENT_TARGET_DEFAULT GREATER "10.4")
84   SET(CMAKE_OSX_SYSROOT_DEFAULT
85     "${OSX_DEVELOPER_ROOT}/SDKs/MacOSX${CMAKE_OSX_DEPLOYMENT_TARGET_DEFAULT}.sdk")
86 ENDIF(CMAKE_OSX_DEPLOYMENT_TARGET_DEFAULT GREATER "10.4")
88 IF(CMAKE_OSX_DEPLOYMENT_TARGET_DEFAULT EQUAL "10.4")
89   SET(CMAKE_OSX_SYSROOT_DEFAULT
90     "${OSX_DEVELOPER_ROOT}/SDKs/MacOSX10.4u.sdk")
91 ENDIF(CMAKE_OSX_DEPLOYMENT_TARGET_DEFAULT EQUAL "10.4")
93 IF(CMAKE_OSX_DEPLOYMENT_TARGET_DEFAULT EQUAL "10.3")
94   SET(CMAKE_OSX_SYSROOT_DEFAULT
95     "${OSX_DEVELOPER_ROOT}/SDKs/MacOSX10.3.9.sdk")
96 ENDIF(CMAKE_OSX_DEPLOYMENT_TARGET_DEFAULT EQUAL "10.3")
98 # Allow environment variables set by the user to override our defaults.
99 # Use the same environment variables that Xcode uses.
100 SET(ENV_MACOSX_DEPLOYMENT_TARGET "$ENV{MACOSX_DEPLOYMENT_TARGET}")
101 SET(ENV_SDKROOT "$ENV{SDKROOT}")
103 # See if we need to override the default SDK or Deployment target with the
104 # environment variables
105 IF(NOT ENV_MACOSX_DEPLOYMENT_TARGET STREQUAL "")
106   SET(CMAKE_OSX_DEPLOYMENT_TARGET_VALUE ${ENV_MACOSX_DEPLOYMENT_TARGET})
107 ELSE(NOT ENV_MACOSX_DEPLOYMENT_TARGET STREQUAL "")
108   SET(CMAKE_OSX_DEPLOYMENT_TARGET_VALUE ${CMAKE_OSX_DEPLOYMENT_TARGET_DEFAULT})
109 ENDIF(NOT ENV_MACOSX_DEPLOYMENT_TARGET STREQUAL "")
111 IF(NOT ENV_SDKROOT STREQUAL "")
112   SET(CMAKE_OSX_SYSROOT_VALUE ${ENV_SDKROOT})
113 ELSE(NOT ENV_SDKROOT STREQUAL "")
114   SET(CMAKE_OSX_SYSROOT_VALUE ${CMAKE_OSX_SYSROOT_DEFAULT})
115 ENDIF(NOT ENV_SDKROOT STREQUAL "")
117 # Set cache variables - end user may change these during ccmake or cmake-gui configure.
118 IF(CURRENT_OSX_VERSION GREATER 10.3)
119   SET(CMAKE_OSX_DEPLOYMENT_TARGET ${CMAKE_OSX_DEPLOYMENT_TARGET_VALUE} CACHE STRING
120     "Minimum OS X version to target for deployment (at runtime); newer APIs weak linked. Set to empty string for default value.")
121 ENDIF(CURRENT_OSX_VERSION GREATER 10.3)
123 SET(CMAKE_OSX_SYSROOT ${CMAKE_OSX_SYSROOT_VALUE} CACHE PATH
124   "The product will be built against the headers and libraries located inside the indicated SDK.")
126 #----------------------------------------------------------------------------
127 function(SanityCheckSDKAndDeployTarget _sdk_path _deploy)
128   if (_deploy STREQUAL "")
129     return()
130   endif()
132   string (REGEX REPLACE "(.*MacOSX*)(....)(.*\\.sdk)" "\\2" SDK ${_sdk_path})
133   if (_deploy GREATER SDK)
134     message (FATAL_ERROR "CMAKE_OSX_DEPLOYMENT_TARGET (${_deploy}) is greater than CMAKE_OSX_SYSROOT SDK (${_sdk_path}). Please set CMAKE_OSX_DEPLOYMENT_TARGET to ${SDK}")
135   endif (_deploy GREATER SDK)
136 endfunction(SanityCheckSDKAndDeployTarget _sdk_path _deploy)
137 #----------------------------------------------------------------------------
139 # Make sure the combination of SDK and Deployment Target are allowed
140 SanityCheckSDKAndDeployTarget("${CMAKE_OSX_SYSROOT}" "${CMAKE_OSX_DEPLOYMENT_TARGET}")
142 # set _CMAKE_OSX_MACHINE to uname -m
143 EXECUTE_PROCESS(COMMAND uname -m
144   OUTPUT_STRIP_TRAILING_WHITESPACE
145   OUTPUT_VARIABLE _CMAKE_OSX_MACHINE)
147 # check for Power PC and change to ppc
148 IF(_CMAKE_OSX_MACHINE MATCHES "Power")
149   SET(_CMAKE_OSX_MACHINE ppc)
150 ENDIF(_CMAKE_OSX_MACHINE MATCHES "Power")
152 # set the default based on uname and not the environment variable
153 # as that is what is used to change it!
154 SET(CMAKE_OSX_ARCHITECTURES_DEFAULT ${_CMAKE_OSX_MACHINE})
156 # check for environment variable CMAKE_OSX_ARCHITECTURES
157 # if it is set.
158 IF(NOT "$ENV{CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
159   SET(CMAKE_OSX_ARCHITECTURES_VALUE "$ENV{CMAKE_OSX_ARCHITECTURES}")
160 ELSE(NOT "$ENV{CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
161   SET(CMAKE_OSX_ARCHITECTURES_VALUE ${CMAKE_OSX_ARCHITECTURES_DEFAULT})
162 ENDIF(NOT "$ENV{CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
164 # now put _CMAKE_OSX_MACHINE into the cache
165 SET(CMAKE_OSX_ARCHITECTURES ${CMAKE_OSX_ARCHITECTURES_VALUE} CACHE STRING
166   "Build architectures for OSX")
169 IF("${CMAKE_BACKWARDS_COMPATIBILITY}" MATCHES "^1\\.[0-6]$")
170   SET(CMAKE_SHARED_MODULE_CREATE_C_FLAGS
171     "${CMAKE_SHARED_MODULE_CREATE_C_FLAGS} -flat_namespace -undefined suppress")
172 ENDIF("${CMAKE_BACKWARDS_COMPATIBILITY}" MATCHES "^1\\.[0-6]$")
174 IF(NOT XCODE)
175   # Enable shared library versioning.  This flag is not actually referenced
176   # but the fact that the setting exists will cause the generators to support
177   # soname computation.
178   SET(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-install_name")
179   SET(CMAKE_SHARED_LIBRARY_SONAME_CXX_FLAG "-install_name")
180   SET(CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG "-install_name")
181 ENDIF(NOT XCODE)
183 # Xcode does not support -isystem yet.
184 IF(XCODE)
185   SET(CMAKE_INCLUDE_SYSTEM_FLAG_C)
186   SET(CMAKE_INCLUDE_SYSTEM_FLAG_CXX)
187 ENDIF(XCODE)
189 # Need to list dependent shared libraries on link line.  When building
190 # with -isysroot (for universal binaries), the linker always looks for
191 # dependent libraries under the sysroot.  Listing them on the link
192 # line works around the problem.
193 SET(CMAKE_LINK_DEPENDENT_LIBRARY_FILES 1)
195 SET(CMAKE_C_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS -w)
196 SET(CMAKE_CXX_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS -w)
197 SET(CMAKE_C_CREATE_SHARED_LIBRARY
198   "<CMAKE_C_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> <LINK_FLAGS> -o <TARGET> -install_name <TARGET_INSTALLNAME_DIR><TARGET_SONAME> <OBJECTS> <LINK_LIBRARIES>")
199 SET(CMAKE_CXX_CREATE_SHARED_LIBRARY
200   "<CMAKE_CXX_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <LINK_FLAGS> -o <TARGET> -install_name <TARGET_INSTALLNAME_DIR><TARGET_SONAME> <OBJECTS> <LINK_LIBRARIES>")
201 SET(CMAKE_Fortran_CREATE_SHARED_LIBRARY
202   "<CMAKE_Fortran_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_Fortran_FLAGS> <LINK_FLAGS> -o <TARGET> -install_name <TARGET_INSTALLNAME_DIR><TARGET_SONAME> <OBJECTS> <LINK_LIBRARIES>")
204 SET(CMAKE_CXX_CREATE_SHARED_MODULE
205       "<CMAKE_CXX_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS> <LINK_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
207 SET(CMAKE_C_CREATE_SHARED_MODULE
208       "<CMAKE_C_COMPILER>  <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_MODULE_CREATE_C_FLAGS> <LINK_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
210 SET(CMAKE_Fortran_CREATE_SHARED_MODULE
211       "<CMAKE_Fortran_COMPILER>  <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_MODULE_CREATE_Fortran_FLAGS> <LINK_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
213 SET(CMAKE_C_CREATE_MACOSX_FRAMEWORK
214       "<CMAKE_C_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> <LINK_FLAGS> -o <TARGET> -install_name <TARGET_INSTALLNAME_DIR><TARGET_SONAME> <OBJECTS> <LINK_LIBRARIES>")
215 SET(CMAKE_CXX_CREATE_MACOSX_FRAMEWORK
216       "<CMAKE_CXX_COMPILER> <LANGUAGE_COMPILE_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <LINK_FLAGS> -o <TARGET> -install_name <TARGET_INSTALLNAME_DIR><TARGET_SONAME> <OBJECTS> <LINK_LIBRARIES>")
220 # default to searching for frameworks first
221 SET(CMAKE_FIND_FRAMEWORK FIRST)
222 # set up the default search directories for frameworks
223 SET(CMAKE_SYSTEM_FRAMEWORK_PATH
224   ~/Library/Frameworks
225   /Library/Frameworks
226   /Network/Library/Frameworks
227   /System/Library/Frameworks)
229 # default to searching for application bundles first
230 SET(CMAKE_FIND_APPBUNDLE FIRST)
231 # set up the default search directories for application bundles
232 SET(CMAKE_SYSTEM_APPBUNDLE_PATH
233   ~/Applications
234   /Applications
235   /Developer/Applications)
237 INCLUDE(Platform/UnixPaths)
238 LIST(APPEND CMAKE_SYSTEM_PREFIX_PATH /sw)