Commit 21e287dc authored by Craig Scott's avatar Craig Scott
Browse files

Apple: Enable -Wl,-search_paths_first for non-macOS platforms

When building for Apple device platforms, don't expect
CMAKE_SYSTEM_VERSION to be set and don't set
DARWIN_MAJOR_VERSION. In turn, don't erroneously query the latter to
determine whether the -Wl,-search_paths_first linker flag is supported.
It is expected to be available for all Apple SDKs that we now support.

Projects may be relying on the linker flag not being added, so policy
CMP0123 provides backward compatibility for this change.
parent 38a8be1f
......@@ -15,30 +15,41 @@ if(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "tvOS" OR CMAK
if(NOT DEFINED CMAKE_FIND_ROOT_PATH_MODE_PACKAGE)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
endif()
endif()
# Darwin versions:
# 6.x == Mac OSX 10.2 (Jaguar)
# 7.x == Mac OSX 10.3 (Panther)
# 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)
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_SYSTEM_VERSION}")
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\2" DARWIN_MINOR_VERSION "${CMAKE_SYSTEM_VERSION}")
# Do not use the "-Wl,-search_paths_first" flag with the OSX 10.2 compiler.
# Done this way because it is too early to do a TRY_COMPILE.
if(NOT DEFINED HAVE_FLAG_SEARCH_PATHS_FIRST)
if(NOT DEFINED HAVE_FLAG_SEARCH_PATHS_FIRST)
# FIXME: We should be able to unilaterally set HAVE_FLAG_SEARCH_PATHS_FIRST
# to 1 here, but we need this condition to preserve backward
# compatibility. The old code used to assume CMAKE_SYSTEM_VERSION
# was always set and therefore DARWIN_MAJOR_VERSION would always
# be populated. For device platforms, it would end up as an empty
# string, resulting in HAVE_FLAG_SEARCH_PATHS_FIRST being set to 0.
# Some projects worked around another symptom of this by setting
# CMAKE_SYSTEM_VERSION, which is wrong but gave the behavior they
# wanted. We have to continue to honor that. We should remove all of
# this logic with a policy and set it to 1 always if not already
# defined.
set(HAVE_FLAG_SEARCH_PATHS_FIRST 0)
if("${DARWIN_MAJOR_VERSION}" GREATER 6)
if("${CMAKE_SYSTEM_VERSION}" VERSION_GREATER_EQUAL 7)
set(HAVE_FLAG_SEARCH_PATHS_FIRST 1)
endif()
endif()
else()
# Darwin versions:
# 6.x == Mac OSX 10.2 (Jaguar)
# 7.x == Mac OSX 10.3 (Panther)
# 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)
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_SYSTEM_VERSION}")
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\2" DARWIN_MINOR_VERSION "${CMAKE_SYSTEM_VERSION}")
# Done this way because it is too early to do a TRY_COMPILE.
if(NOT DEFINED HAVE_FLAG_SEARCH_PATHS_FIRST)
set(HAVE_FLAG_SEARCH_PATHS_FIRST 1)
endif()
endif()
# More desirable, but does not work:
#include(CheckCXXCompilerFlag)
#CHECK_CXX_COMPILER_FLAG("-Wl,-search_paths_first" HAVE_FLAG_SEARCH_PATHS_FIRST)
set(CMAKE_SHARED_LIBRARY_PREFIX "lib")
set(CMAKE_SHARED_LIBRARY_SUFFIX ".dylib")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment