From: Lucian Petrut Date: Wed, 23 Aug 2023 14:21:12 +0000 (+0000) Subject: cmake: fix mingw-llvm shared linking X-Git-Tag: v19.0.0~575^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=ec4a2778f6c6a60763049e37a9cfa48fba31b404;p=ceph.git cmake: fix mingw-llvm shared linking mingw-llvm can't handle the '--exclude-libs' linker flag, so we'll have to skip it. At the same time, cmake can't locate the boost shared libs as the import libs are not generated when using mingw-llvm due to boost's clang-linux.jam file. For now, we'll patch the cmake files, using the dlls as import libs (which is allowed by mingw). While at it, we'll avoid linking the static AND dynamic boost libs, speeding the build. Signed-off-by: Lucian Petrut --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8287539a3fc70..c09d275f337ef 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -814,7 +814,8 @@ if(WITH_LIBCEPHFS) OUTPUT_NAME cephfs VERSION 2.0.0 SOVERSION 2) - if(NOT APPLE) + if(NOT APPLE AND NOT + (WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL Clang)) foreach(name ceph-common client osdc) set_property(TARGET cephfs APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--exclude-libs,lib${name}.a") diff --git a/win32_build.sh b/win32_build.sh index b7b395df1929f..8edf40326292b 100755 --- a/win32_build.sh +++ b/win32_build.sh @@ -231,8 +231,12 @@ if [[ -z $SKIP_DLL_COPY ]]; then $lz4Dir/lib/dll/liblz4-1.dll $sslDir/bin/libcrypto-1_1-x64.dll $sslDir/bin/libssl-1_1-x64.dll - $mingwLibpthreadDir/libwinpthread-1.dll - $boostDir/lib/*.dll) + $mingwLibpthreadDir/libwinpthread-1.dll) + if [[ $ENABLE_SHARED == "ON" ]]; then + required_dlls+=( + $boostDir/lib/*.dll + ) + fi if [[ -n $USE_MINGW_LLVM ]]; then required_dlls+=( $mingwTargetLibDir/libc++.dll diff --git a/win32_deps_build.sh b/win32_deps_build.sh index 351cb65e07180..a4ef7f43965ec 100755 --- a/win32_deps_build.sh +++ b/win32_deps_build.sh @@ -6,6 +6,7 @@ SCRIPT_DIR="$(dirname "$BASH_SOURCE")" SCRIPT_DIR="$(realpath "$SCRIPT_DIR")" USE_MINGW_LLVM=${USE_MINGW_LLVM:-} +ENABLE_SHARED=${ENABLE_SHARED:-OFF} num_vcpus=$(nproc) NUM_WORKERS=${NUM_WORKERS:-$num_vcpus} @@ -236,15 +237,32 @@ EOL ./bootstrap.sh +if [[ $ENABLE_SHARED == "ON" ]]; then + b2_link="shared" +else + b2_link="static" +fi + ./b2 install --user-config=user-config.jam toolset=$b2toolset \ target-os=windows release \ - link=static,shared \ + link=$b2_link \ threadapi=win32 --prefix=$boostDir \ address-model=64 architecture=x86 \ binary-format=pe abi=ms -j $NUM_WORKERS \ -sZLIB_INCLUDE=$zlibDir/include -sZLIB_LIBRARY_PATH=$zlibDir/lib \ --without-python --without-mpi --without-log --without-wave +if [[ -n $USE_MINGW_LLVM && $ENABLE_SHARED == "ON" ]]; then + # b2 doesn't generate import libs when using mingw-llvm. We'll tell cmake + # to use the dlls instead of import libs, which mingw is capable of. + # + # TODO: consider dropping this if we get to fix Boost's clang-linux.jam + # file. Worth mentioning that Boost might drop the import libs altogether: + # https://github.com/bfgroup/b2/issues/278 + find $boostDir/lib/cmake -name "*.cmake" \ + -exec sed -i 's/IMPORTED_LOCATION_RELEASE/IMPORTED_IMPLIB_RELEASE/g' {} \; +fi + echo "Building libbacktrace." cd $depsSrcDir if [[ ! -d $backtraceSrcDir ]]; then