From: Viktor Szakats Date: Tue, 8 Aug 2023 11:45:26 +0000 (+0000) Subject: cmake: allow `SHARE_LIB_OBJECT=ON` on all platforms X-Git-Tag: curl-8_3_0~180 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fc9bfb14520712672b4784e8b48256fb29204011;p=thirdparty%2Fcurl.git cmake: allow `SHARE_LIB_OBJECT=ON` on all platforms 2ebc74c36a19a1700af394c16855ce144d9878e3 #11546 introduced sharing libcurl objects for shared and static targets. The above automatically enabled for Windows builds, with an option to disable with `SHARE_LIB_OBJECT=OFF`. This patch extend this feature to all platforms as a manual option. You can enable it by setting `SHARE_LIB_OBJECT=ON`. Then shared objects are built in PIC mode, meaning the static lib will also have PIC code. [EXPERIMENTAL] Closes #11627 --- diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index faae6452c5..9bb8f0beb0 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -108,13 +108,18 @@ if(WIN32 AND set(IMPORT_LIB_SUFFIX "_imp") endif() -# On supported platforms, do a single compilation pass for libcurl sources -# and reuse these objects to generate both static and shared target. -# This is possible where PIC is the default for both shared and static and -# there is a way to tell the linker which libcurl symbols it should export -# (vs. marking these symbols exportable at compile-time). -if(WIN32 AND NOT DEFINED SHARE_LIB_OBJECT) - set(SHARE_LIB_OBJECT ON) +# Whether to do a single compilation pass for libcurl sources and reuse these +# objects to generate both static and shared target. +if(NOT DEFINED SHARE_LIB_OBJECT) + # Enable it by default on platforms where PIC is the default for both shared + # and static and there is a way to tell the linker which libcurl symbols it + # should export (vs. marking these symbols exportable at compile-time). + if(WIN32) + set(SHARE_LIB_OBJECT ON) + else() + # On other platforms, make it an option disabled by default + set(SHARE_LIB_OBJECT OFF) + endif() endif() if(SHARE_LIB_OBJECT) @@ -123,7 +128,8 @@ if(SHARE_LIB_OBJECT) target_link_libraries(${LIB_OBJECT} PRIVATE ${CURL_LIBS}) set_target_properties(${LIB_OBJECT} PROPERTIES COMPILE_DEFINITIONS "BUILDING_LIBCURL" - INTERFACE_COMPILE_DEFINITIONS "CURL_STATICLIB") + INTERFACE_COMPILE_DEFINITIONS "CURL_STATICLIB" + POSITION_INDEPENDENT_CODE ON) if(HIDES_CURL_PRIVATE_SYMBOLS) set_target_properties(${LIB_OBJECT} PROPERTIES COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS"