In the CMake build on macOS, add an option to use @rpath in the shared library.
* CMakeLists.txt: Reorder build options before their use (style change only).
Put platform-relative build options last.
(RELATIVE_RPATH): New macOS-specific build option.
(serf_shared): Only add the INSTALL_LIB_DIR property on macOS,
depending on RELATIVE_RPATH.
* build/SerfPlatform.cmake (CMAKE_MACOSX_RPATH): Depends on RELATIVE_RPATH.
git-svn-id: https://svn.apache.org/repos/asf/serf/trunk@1842236 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7fd0051..babcaba 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -45,6 +45,27 @@
"Some features are not supported and the build "
"has not been tested on many supported platforms.")
+
+# Build options
+option(DEBUG "Enable debugging info and strict compile warnings" OFF)
+option(SKIP_SHARED "Disable building shared Serf libraries" OFF)
+option(SKIP_STATIC "Disable building static Serf libraries" OFF)
+option(LIBDIR "Install directory for architecture-dependent libraries" "")
+option(GSSAPI "Path to GSSAPI's install area" "")
+option(BROTLI "Path to Brotli's install area" "")
+option(DISABLE_LOGGING "Disable the logging framework at compile time" OFF)
+option(SKIP_TESTS "Disable building the unit tests and utilities" OFF)
+option(ENABLE_SLOW_TESTS "Enable long-running unit tests" OFF)
+
+# Platform-specific build options
+option(APR_STATIC "Windows: Link with static APR/-Util libraries" OFF)
+option(EXPAT "Windows: optional path to Expat's install area for APR_STATIC" "")
+option(RELATIVE_RPATH "macOS: Use @rpath in installed shared library" OFF)
+
+if(SKIP_SHARED AND SKIP_STATIC)
+ message(FATAL_ERROR "You have disabled both shared and static library builds.")
+endif()
+
# Initialize the build type if it was not set on the command line.
if(NOT CMAKE_BUILD_TYPE)
if(DEBUG)
@@ -58,23 +79,6 @@
include(SerfWindowsToolkit)
-# Build options
-option(DEBUG "Enable debugging info and strict compile warnings" OFF)
-option(SKIP_SHARED "Disable building shared Serf libraries" OFF)
-option(SKIP_STATIC "Disable building static Serf libraries" OFF)
-option(LIBDIR "Install directory for architecture-dependent libraries" "")
-option(GSSAPI "Path to GSSAPI's install area" "")
-option(BROTLI "Path to Brotli's install area" "")
-option(APR_STATIC "Windows: Link with static APR/-Util libraries" OFF)
-option(EXPAT "Windows: optional path to Expat's install area for APR_STATIC" "")
-option(DISABLE_LOGGING "Disable the logging framework at compile time" OFF)
-option(SKIP_TESTS "Disable building the unit tests and utilities" OFF)
-option(ENABLE_SLOW_TESTS "Enable long-running unit tests" OFF)
-
-if(SKIP_SHARED AND SKIP_STATIC)
- message(FATAL_ERROR "You have disabled both shared and static library builds.")
-endif()
-
# Public headers
list(APPEND HEADERS
"serf.h"
@@ -299,11 +303,13 @@
PRIVATE ${SERF_PRIVATE_TARGETS}
${SERF_STANDARD_LIBRARIES}
PUBLIC ${SERF_PUBLIC_TARGETS})
- set_target_properties(serf_shared
- PROPERTIES
+ set_target_properties(serf_shared PROPERTIES
VERSION ${SERF_VERSION}
- SOVERSION ${SERF_SOVERSION}
- INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")
+ SOVERSION ${SERF_SOVERSION})
+ if(SERF_DARWIN AND NOT RELATIVE_RPATH)
+ set_target_properties(serf_shared PROPERTIES
+ INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")
+ endif()
set(SERF_TARGETS "serf_shared")
if(SERF_WINDOWS)
diff --git a/build/SerfPlatform.cmake b/build/SerfPlatform.cmake
index 9a2c4b4..18aacef 100644
--- a/build/SerfPlatform.cmake
+++ b/build/SerfPlatform.cmake
@@ -19,7 +19,9 @@
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(SERF_DARWIN TRUE)
- set(CMAKE_MACOSX_RPATH FALSE)
+ if(NOT RELATIVE_RPATH)
+ set(CMAKE_MACOSX_RPATH FALSE)
+ endif()
message(STATUS "Target platform is Darwin (macOS)")
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(SERF_LINUX TRUE)