From 99d7f3ddc009232bdbf272c38e0a7f7c1f201435 Mon Sep 17 00:00:00 2001 From: Aaron Barany Date: Fri, 29 Nov 2024 18:24:32 -0800 Subject: [PATCH] Added CUTTLEFISH_STATIC_RUNTIME CMake option. When set to ON, the static runtime library will be used on Windows. Set the minimum required CMake version to 3.15 on Windows to have access to set(CMAKE_MSVC_RUNTIME_LIBRARY. The minimum on other platforms is now 3.10 to prevent warnings on newer versions, as future versions will remove support for compatibility with minimum versions < 3.9. Set CMake policy for versions >= 3.27 to avoid warning when using find_package() with PVRTexLib. The usage was already compliant with new behavior. Create separate "tool" and "full" packages for Windows in CI. "tool" packages provide only the tool with static linking and runtime, while "full" is same as the previous package with the addition of the debug library. --- .github/workflows/main.yml | 24 +++++++++++++++++++----- CMakeLists.txt | 11 ++++++++++- README.md | 5 +++-- cmake/config.cmake | 7 +++++++ 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 53eca67..2e356b0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -231,13 +231,14 @@ jobs: ispc: 0 - arch: Win32 lib_type: Static - cmake_args: "-DCUTTLEFISH_SHARED=OFF -DCUTTLEFISH_ISPC_PATH=D:/ispc/bin/ispc.exe" + cmake_args: "-DCUTTLEFISH_SHARED=OFF -DCUTTLEFISH_STATIC_RUNTIME=ON -DCUTTLEFISH_ISPC_PATH=D:/ispc/bin/ispc.exe" ispc: 1 + artifact: win32-tool - arch: Win32 lib_type: Shared cmake_args: "-DCUTTLEFISH_SHARED=ON -DCUTTLEFISH_ISPC_PATH=D:/ispc/bin/ispc.exe" ispc: 1 - artifact: win32 + artifact: win32-full - arch: x64 lib_type: Static cmake_args: "-DCUTTLEFISH_SHARED=OFF" @@ -248,13 +249,14 @@ jobs: ispc: 0 - arch: x64 lib_type: Static - cmake_args: "-DCUTTLEFISH_SHARED=OFF -DCUTTLEFISH_ISPC_PATH=D:/ispc/bin/ispc.exe" + cmake_args: "-DCUTTLEFISH_SHARED=OFF -DCUTTLEFISH_STATIC_RUNTIME=ON -DCUTTLEFISH_ISPC_PATH=D:/ispc/bin/ispc.exe" ispc: 1 + artifact: win64-tool - arch: x64 lib_type: Shared cmake_args: "-DCUTTLEFISH_SHARED=ON -DCUTTLEFISH_ISPC_PATH=D:/ispc/bin/ispc.exe" ispc: 1 - artifact: win64 + artifact: win64-full steps: - name: checkout uses: actions/checkout@v4 @@ -325,9 +327,21 @@ jobs: Tests (Windows ${{ matrix.arch }} ${{ matrix.lib_type }} ISPC:${{ matrix.ispc }} Release) junit_files: "${{ env.test_results_location }}/*.xml" - name: Package artifact - if: matrix.artifact != '' + if: endsWith(matrix.artifact, '-full') + # Full package with debug and release, minus debug .exe. + run: |- + cmake --build . --config Debug --target install + cmake --build . --config Release --target install + rm cuttlefish\\bin\\cuttlefishd.exe + 7z a -tzip cuttlefish-${{ matrix.artifact }}.zip cuttlefish + working-directory: "${{ github.workspace }}/build" + - name: Package artifact + if: endsWith(matrix.artifact, '-tool') + # Only tool and supplemental DLLs. run: |- cmake --build . --config Release --target install + mv cuttlefish\\bin\\* cuttlfish + rm -r cuttlefish/bin cuttlefish\\lib cuttlefish\\include 7z a -tzip cuttlefish-${{ matrix.artifact }}.zip cuttlefish working-directory: "${{ github.workspace }}/build" - name: Publish artifact diff --git a/CMakeLists.txt b/CMakeLists.txt index 89f360d..3147377 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,12 @@ -cmake_minimum_required(VERSION 3.5) +if (WIN32) + # Needs 3.15 for CMAKE_MSVC_RUNTIME_LIBRARY. + cmake_minimum_required(VERSION 3.15) +else() + cmake_minimum_required(VERSION 3.10) +endif() +if (POLICY CMP0144) + cmake_policy(SET CMP0144 NEW) +endif() project(Cuttlefish) # Build options @@ -10,6 +18,7 @@ else() endif() set(CUTTLEFISH_SHARED ${CUTTLEFISH_SHARED_DEFAULT} CACHE BOOL "Build Cuttlefish using shared libraries.") +set(CUTTLEFISH_STATIC_RUNTIME OFF CACHE BOOL "Use static runtime library on Windows.") # Options for disabling portions of the build. set(CUTTLEFISH_BUILD_TESTS ON CACHE BOOL "Build unit tests.") diff --git a/README.md b/README.md index 4acdb27..1e2c2ff 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Features include: The following software is required to build Cuttlefish: -* [CMake](https://cmake.org/) 3.5 or later +* [CMake](https://cmake.org/) 3.10 or later * [FreeImage](http://freeimage.sourceforge.net/) (required, included as a submodule) * [GLM](https://glm.g-truc.net/0.9.9/index.html) (required, included as a submodule) * [squish](https://sourceforge.net/projects/libsquish/) (optional, included as a submodule) @@ -102,8 +102,9 @@ The following options may be used when running cmake: * `-DCMAKE_BUILD_TYPE=Debug|Release`: Building in `Debug` or `Release`. This should always be specified. * `-DCMAKE_INSTALL_PREFIX=path`: Sets the path to install to when running `make install`. -* `-DCUTTLEFISH_SHARED=ON|OFF`: Set to `ON` to build with shared libraries, `OFF` to build with static libraries. Default is `OFF`. +* `-DCUTTLEFISH_SHARED=ON|OFF`: Set to `ON` to build with shared libraries, `OFF` to build with static libraries. TDefault is the value of `BUILD_SHARED_LIBS` or `OFF`. * `-DCUTTLEFISH_ISPC_PATH=path`: The path to the ISPC compiler. If unset, ispc will be searched in the `PATH` or default instal location. +* `-DCUTTLEFISH_STATIC_RUNTIME=ON,OFF`: Set to `ON` to use the static runtime library on Windows. When `OFF`, it will respect the existing value of `CMAKE_MSVC_RUNTIME_LIBRARY`, or use dynamic runtime if otherwise unset. It is not recommended to set this to `ON` when `CUTTLEFISH_SHARED` is also `ON`. Default is `OFF`. ### Enabled Builds diff --git a/cmake/config.cmake b/cmake/config.cmake index 64835fd..7ecb200 100644 --- a/cmake/config.cmake +++ b/cmake/config.cmake @@ -47,6 +47,13 @@ elseif (CUTTLEFISH_ARCH MATCHES "^arm" OR CUTTLEFISH_ARCH STREQUAL "aarch64") endif() if (MSVC) + if (CUTTLEFISH_STATIC_RUNTIME) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + if (CUTTLEFISH_SHARED) + message(WARNING + "It is not recommended to have CUTTLEFISH_SHARED and CUTTLEFISH_STATIC_RUNTIME both set to ON.") + endif() + endif() add_compile_options(/W3 /WX /wd4200 /MP) if (CUTTLEFISH_ARCH STREQUAL "x86") add_compile_options(/arch:SSE2)