]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: fix mingw-llvm shared linking
authorLucian Petrut <lpetrut@cloudbasesolutions.com>
Wed, 23 Aug 2023 14:21:12 +0000 (14:21 +0000)
committerLucian Petrut <lpetrut@cloudbasesolutions.com>
Wed, 30 Aug 2023 12:59:00 +0000 (12:59 +0000)
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 <lpetrut@cloudbasesolutions.com>
src/CMakeLists.txt
win32_build.sh
win32_deps_build.sh

index 8287539a3fc7081e5581b1168f0d2fd897c2d1f1..c09d275f337efc01ad0e2c1c813e45607d84f687 100644 (file)
@@ -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")
index b7b395df1929feb57232d45ee6fdfd8398569f10..8edf40326292bc77c9804527ce899d0452250dc5 100755 (executable)
@@ -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
index 351cb65e07180139b7abb890986bc03bdd855df2..a4ef7f43965ec8f557dd32d1da0e2bedb54043e0 100755 (executable)
@@ -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