Skip to content
Snippets Groups Projects
Commit 4aed96e2 authored by Craig Scott's avatar Craig Scott
Browse files

Apple: Set CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG on non-macOS too

Since CMake 3.19, we no longer support macOS SDKs older than 10.5,
which corresponds to Xcode 3. Supporting older Xcode versions for
device platforms is also not realistic. We therefore expect the -rpath
linker option should always be supported now.

When targeting iOS, tvOS or watchOS, the previous disabling of -rpath
support meant that the install_name_dir of shared libraries and
frameworks was unable to use @rpath. This resulted in embedding
absolute paths for their install_name. When they were embedded in an
app bundle, this would cause the app to fail at runtime. By enabling the
-rpath linker option, the default install_name_dir is now @rpath for these platforms, which results in binaries that do work at runtime.

Fixes: #20036
parent 26af5908
No related branches found
No related tags found
No related merge requests found
INSTALL_NAME_DIR
----------------
macOS directory name for installed targets.
Directory name for installed targets on Apple platforms.
``INSTALL_NAME_DIR`` is a string specifying the directory portion of the
"install_name" field of shared libraries on macOS to use in the
installed targets.
"install_name" field of shared libraries on Apple platforms for
installed targets. When not set, the default directory used is determined
by :prop_tgt:`MACOSX_RPATH`. Policies :policy:`CMP0068` and :policy:`CMP0042`
are also relevant.
This property is initialized by the value of the variable
:variable:`CMAKE_INSTALL_NAME_DIR` if it is set when a target is
......
......@@ -341,3 +341,9 @@ Changes made since CMake 3.20.0 include the following.
and ``Intl_IS_BUILTIN``, but they were not implemented correctly.
These have been removed and replaced with a single ``Intl_IS_BUILT_IN``
check, whose name is consistent with the :module:`FindIconv` module.
* The ``-rpath`` linker flag is now specified as supported on all Apple
platforms, not just macOS. The ``install_name_dir`` used for
iOS, tvOS and watchOS should now default to ``@rpath`` instead of using
a full absolute path and failing at runtime when the library or framework
is embedded in an application bundle (see :prop_tgt:`XCODE_EMBED_<type>`).
CMAKE_INSTALL_NAME_DIR
----------------------
macOS directory name for installed targets.
Directory name for installed targets on Apple platforms.
``CMAKE_INSTALL_NAME_DIR`` is used to initialize the
:prop_tgt:`INSTALL_NAME_DIR` property on all targets. See that target
......
......@@ -47,11 +47,7 @@ set(CMAKE_SHARED_MODULE_PREFIX "lib")
set(CMAKE_SHARED_MODULE_SUFFIX ".so")
set(CMAKE_MODULE_EXISTS 1)
set(CMAKE_DL_LIBS "")
# Enable rpath support for 10.5 and greater where it is known to work.
if("${DARWIN_MAJOR_VERSION}" GREATER 8)
set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
endif()
set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
foreach(lang C CXX OBJC OBJCXX)
set(CMAKE_${lang}_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment