diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5f7a8b7b..7ca36f9a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -131,7 +131,7 @@ jobs: run: cmake -E make_directory build - name: Run CMake (for Windows) working-directory: build - run: cmake -G "Ninja" -DCMAKE_C_COMPILER=cl.exe -DCMAKE_CXX_COMPILER=cl.exe -DVCPKG_TARGET_TRIPLET=x64-windows-static -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}\scripts\buildsystems\vcpkg.cmake -DBUILD_STATIC=1 -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}\build\install -DDEV_BUILD=1 -DPORTABLE=1 -DTOOLS=1 -DTESTS=1 -DDESKTOP=1 .. + run: cmake -G "Ninja" -DCMAKE_C_COMPILER=cl.exe -DCMAKE_CXX_COMPILER=cl.exe -DVCPKG_TARGET_TRIPLET=x64-windows-static -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}\scripts\buildsystems\vcpkg.cmake -DUSE_STATIC_RUNTIME=1 -DCBOT_STATIC=1 -DBOOST_STATIC=1 -DGLEW_STATIC=1 -DSNDFILE_STATIC=1 -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}\build\install -DDEV_BUILD=1 -DPORTABLE=1 -DTOOLS=1 -DTESTS=1 -DDESKTOP=1 .. - name: Build working-directory: build run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index 38474ef0..3ef580ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -189,7 +189,7 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") # Disable some useless warnings set(NORMAL_CXX_FLAGS "/wd\"4244\" /wd\"4309\" /wd\"4800\" /wd\"4996\" /wd\"4351\"") - if(BUILD_STATIC) + if(USE_STATIC_RUNTIME) set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") else() set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL$<$:Debug>") @@ -260,20 +260,20 @@ option(INSTALL_DOCS "Install Doxygen-generated documentation" OFF) # Build OpenAL sound support option(OPENAL_SOUND "Build OpenAL sound support" ON) -# Build Colobot with static libraries -option(BUILD_STATIC "The default linking option for external libraries" OFF) +# Link runtime library statically (currently only works for MSVC) +option(USE_STATIC_RUNTIME "Link the runtime library statically" OFF) # CBot can also be a static library -option(CBOT_STATIC "Build CBot as static libary" ${BUILD_STATIC}) +option(CBOT_STATIC "Build CBot as static libary" OFF) # This is useful in case you want to use static boost libraries -option(BOOST_STATIC "Link with static boost libraries" ${BUILD_STATIC}) +option(BOOST_STATIC "Link with static boost libraries" OFF) # This is useful on Windows, if linking against standard GLEW dll fails -option(GLEW_STATIC "Link statically with GLEW" ${BUILD_STATIC}) +option(GLEW_STATIC "Link statically with GLEW" OFF) # Link statically with LibSndFile -option(SNDFILE_STATIC "Link statically with LibSndFile" ${BUILD_STATIC}) +option(SNDFILE_STATIC "Link statically with LibSndFile" OFF) # Sometimes helpful if there is a different version of gtest installed on system vs bundled option(FORCE_BUNDLED_GTEST "Force the use of bundled gtest" OFF) @@ -292,6 +292,21 @@ if(DEV_BUILD) message(STATUS "Building with development extensions") endif() +## +# Additional settings to use when cross-compiling with MXE (http://mxe.cc/) +## + +include("${colobot_SOURCE_DIR}/cmake/mxe.cmake") + +## +# Additional settings for MSYS +## +include("${colobot_SOURCE_DIR}/cmake/msys.cmake") + +## +# Additional functions for colobot-lint +## +include("${colobot_SOURCE_DIR}/cmake/colobot-lint.cmake") ## # Searching for packages @@ -307,7 +322,7 @@ find_package(PhysFS REQUIRED) set(Boost_USE_STATIC_LIBS ${BOOST_STATIC}) set(Boost_USE_MULTITHREADED ON) -set(Boost_USE_STATIC_RUNTIME OFF) +set(Boost_USE_STATIC_RUNTIME ${USE_STATIC_RUNTIME}) set(Boost_ADDITIONALVERSION "1.51" "1.51.0") find_package(Boost COMPONENTS system filesystem regex REQUIRED) @@ -335,22 +350,6 @@ if(DEV_BUILD) add_definitions(-DDEV_BUILD) endif() -## -# Additional settings to use when cross-compiling with MXE (http://mxe.cc/) -## - -include("${colobot_SOURCE_DIR}/cmake/mxe.cmake") - -## -# Additional settings for MSYS -## -include("${colobot_SOURCE_DIR}/cmake/msys.cmake") - -## -# Additional functions for colobot-lint -## -include("${colobot_SOURCE_DIR}/cmake/colobot-lint.cmake") - ## # MSVC specific settings diff --git a/cmake/mxe.cmake b/cmake/mxe.cmake index ed01d8f7..aa904cf0 100644 --- a/cmake/mxe.cmake +++ b/cmake/mxe.cmake @@ -8,8 +8,8 @@ if((${CMAKE_CROSSCOMPILING}) AND (DEFINED MSYS)) set(PLATFORM_LINUX 0) set(PLATFORM_OTHER 0) # All must be static, CBOT and GLEW too - set(BUILD_STATIC ON) set(CBOT_STATIC ON) + set(BOOST_STATIC ON) set(GLEW_STATIC ON) set(SNDFILE_STATIC ON) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1b71851d..c578eb14 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -516,9 +516,11 @@ if(MXE) # MXE requires special treatment elseif(PLATFORM_WINDOWS) # because it isn't included in standard linking libraries if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") - if(BUILD_STATIC) + # TODO: this shouldn't be needed, the libraries targets should care of those transitive dependencies + # This should be treated as a temporary workaround + if(USE_STATIC_RUNTIME) # Since we're using static runtime, assume every external library is static too find_package(Intl REQUIRED) - # TODO: figure out why those dependencies are needed and find/link them in a better way + find_library(BZ2_LIBRARY NAMES bz2.lib) find_library(JPEG_LIBRARY NAMES jpeg.lib) find_library(TIFF_LIBRARY NAMES tiff.lib)