]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
MinGW: Fix static linkage with libgcc and libstdc++ and make it optional (#712)
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>
Fri, 30 Oct 2020 09:57:35 +0000 (11:57 +0200)
committerGitHub <noreply@github.com>
Fri, 30 Oct 2020 09:57:35 +0000 (10:57 +0100)
There is no reason to enable it by default. Looks like it was done for
enabling it to run with wine.

.github/workflows/build.yaml
CMakeLists.txt
src/CMakeLists.txt

index 3564441210c8f53b801b037600db970c8a608754..2c9ba26f094c2b2fb8f1ec7b461d469372f78b90 100644 (file)
@@ -192,7 +192,7 @@ jobs:
             CC: x86_64-w64-mingw32-gcc-posix
             CXX: x86_64-w64-mingw32-g++-posix
             ENABLE_CACHE_CLEANUP_TESTS: 1
-            CMAKE_PARAMS: -DCMAKE_BUILD_TYPE=CI -DCMAKE_SYSTEM_NAME=Windows -DZSTD_FROM_INTERNET=ON
+            CMAKE_PARAMS: -DCMAKE_BUILD_TYPE=CI -DCMAKE_SYSTEM_NAME=Windows -DZSTD_FROM_INTERNET=ON -DSTATIC_LINK=ON
             RUN_TESTS: unittest-in-wine
             apt_get: elfutils mingw-w64 wine
 
index e756c5789fce500d4edcb4e3ec2a4847cf2531ec..1b36dc329685d8b7c69eeb6053bc692bf32bd9fc 100644 (file)
@@ -97,6 +97,10 @@ find_package(zstd 1.1.2 REQUIRED)
 include(CodeAnalysis)
 option(ENABLE_TRACING "Enable possibility to use internal ccache tracing" OFF)
 
+if(WIN32 AND CMAKE_CXX_COMPILER_ID MATCHES "GNU")
+  option(STATIC_LINK "Link statically with system libraries" OFF)
+endif()
+
 #
 # Source code
 #
index 12258870329f340588789ff408681ca5af73b801..1d5bf17d63f872fc8066904c81cfb47b792598c0 100644 (file)
@@ -56,9 +56,12 @@ if(WIN32)
   target_link_libraries(ccache_lib PRIVATE ws2_32 "psapi")
 
   if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
-    target_link_libraries(
-      ccache_lib PRIVATE -static gcc stdc++ winpthread -dynamic)
-  elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+    if(STATIC_LINK)
+      target_link_libraries(ccache_lib PRIVATE -static-libgcc -static-libstdc++ -static winpthread -dynamic)
+    else()
+      target_link_libraries(ccache_lib PRIVATE winpthread)
+    endif()
+  elseif(STATIC_LINK AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
     target_link_libraries(ccache_lib PRIVATE -static c++ -dynamic)
   endif()
 endif()