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 ...@@ -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) if(NOT DEFINED CMAKE_FIND_ROOT_PATH_MODE_PACKAGE)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
endif() endif()
endif()
# Darwin versions: if(NOT DEFINED HAVE_FLAG_SEARCH_PATHS_FIRST)
# 6.x == Mac OSX 10.2 (Jaguar) # FIXME: We should be able to unilaterally set HAVE_FLAG_SEARCH_PATHS_FIRST
# 7.x == Mac OSX 10.3 (Panther) # to 1 here, but we need this condition to preserve backward
# 8.x == Mac OSX 10.4 (Tiger) # compatibility. The old code used to assume CMAKE_SYSTEM_VERSION
# 9.x == Mac OSX 10.5 (Leopard) # was always set and therefore DARWIN_MAJOR_VERSION would always
# 10.x == Mac OSX 10.6 (Snow Leopard) # be populated. For device platforms, it would end up as an empty
# 11.x == Mac OSX 10.7 (Lion) # string, resulting in HAVE_FLAG_SEARCH_PATHS_FIRST being set to 0.
# 12.x == Mac OSX 10.8 (Mountain Lion) # Some projects worked around another symptom of this by setting
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_SYSTEM_VERSION}") # CMAKE_SYSTEM_VERSION, which is wrong but gave the behavior they
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\2" DARWIN_MINOR_VERSION "${CMAKE_SYSTEM_VERSION}") # 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
# Do not use the "-Wl,-search_paths_first" flag with the OSX 10.2 compiler. # defined.
# Done this way because it is too early to do a TRY_COMPILE. set(HAVE_FLAG_SEARCH_PATHS_FIRST 0)
if(NOT DEFINED HAVE_FLAG_SEARCH_PATHS_FIRST) if("${CMAKE_SYSTEM_VERSION}" VERSION_GREATER_EQUAL 7)
set(HAVE_FLAG_SEARCH_PATHS_FIRST 0) set(HAVE_FLAG_SEARCH_PATHS_FIRST 1)
if("${DARWIN_MAJOR_VERSION}" GREATER 6) 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) set(HAVE_FLAG_SEARCH_PATHS_FIRST 1)
endif() endif()
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_PREFIX "lib")
set(CMAKE_SHARED_LIBRARY_SUFFIX ".dylib") 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