From b3290f0672645f86bce454f681784a82e1f72406 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sun, 12 Apr 2020 11:20:16 +0200 Subject: [PATCH] Don't link C libraries statically by default for Windows, as this isn't needed if another library has their own C libraries already has them statically linked. --- .drone.yml | 2 +- CMakeLists.txt | 10 +++++++--- conanfile.py | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.drone.yml b/.drone.yml index af99cd6..eefe284 100644 --- a/.drone.yml +++ b/.drone.yml @@ -62,7 +62,7 @@ steps: - update-alternatives --set i686-w64-mingw32-g++ /usr/bin/i686-w64-mingw32-g++-posix - update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix - update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix - - cmake -DCMAKE_BUILD_TYPE=Release . -B build-release-windows -DWINDOWS=ON + - cmake -DCMAKE_BUILD_TYPE=Release . -B build-release-windows -DWINDOWS=ON -DSTATICC=ON - cmake --build build-release-windows --target all -- -j 4 - cp /usr/x86_64-w64-mingw32/lib/libwinpthread-1.dll /drone/src/build-release-windows/bin/ - cp /drone/src/build-release-windows/lib/libpkmnLib.so /drone/src/build-release-windows/bin/ diff --git a/CMakeLists.txt b/CMakeLists.txt index d505536..78624e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,11 +89,15 @@ if (WINDOWS) message(STATUS "Using Windows build.") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L ${CMAKE_BINARY_DIR}/bin") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -Wa,-mbig-obj -Wl,-allow-multiple-definition") - # Statically link libraries we need in Windows. - SET(_LINKS ${_LINKS} -static-libgcc -static-libstdc++) - SET(_TESTLINKS ${_TESTLINKS} -static-libgcc -static-libstdc++) endif (WINDOWS) +if (STATICC) + SET(_LINKS ${_LINKS} -static-libgcc -static-libstdc++) + if (NOT DEFINED CONAN_EXPORTED) + SET(_TESTLINKS ${_TESTLINKS} -static-libgcc -static-libstdc++) + endif() +endif() + target_link_libraries(pkmnLib PUBLIC ${_LINKS}) diff --git a/conanfile.py b/conanfile.py index d5e9303..4d85a02 100644 --- a/conanfile.py +++ b/conanfile.py @@ -8,8 +8,8 @@ class PkmnLibConan(ConanFile): url = "https://git.p-epsilon.com/Deukhoofd/PkmnLib" description = "An implementation of CreatureLib to handle Pokemon battling." settings = "os", "compiler", "build_type" - options = {"shared": [True, False], "script_handler": ["angelscript"]} - default_options = {"shared": True, "script_handler": "angelscript"} + options = {"shared": [True, False], "script_handler": ["angelscript"], "staticC": [True, False]} + default_options = {"shared": True, "script_handler": "angelscript", "staticC": False} generators = "cmake" exports_sources = "*" compiler = "clang" @@ -20,6 +20,8 @@ class PkmnLibConan(ConanFile): if self.settings.os == "Windows": self.output.warn("Noticed Windows target, setting Cmake WINDOWS=On.") cmake.definitions["WINDOWS"] = "On" + if self.options.staticC: + cmake.definitions["STATICC"] = "On" cmake.configure() cmake.build()