From: Orgad Shaneh Date: Fri, 30 Oct 2020 09:57:35 +0000 (+0200) Subject: MinGW: Fix static linkage with libgcc and libstdc++ and make it optional (#712) X-Git-Tag: v4.1~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d2eb812ebe8a51085a5d348bbab7ea11725588b8;p=thirdparty%2Fccache.git MinGW: Fix static linkage with libgcc and libstdc++ and make it optional (#712) There is no reason to enable it by default. Looks like it was done for enabling it to run with wine. --- diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 356444121..2c9ba26f0 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index e756c5789..1b36dc329 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 # diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 122588703..1d5bf17d6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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()