Skip to content

Commit

Permalink
Added CUTTLEFISH_STATIC_RUNTIME CMake option.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
akb825 committed Nov 30, 2024
1 parent 024bc57 commit 99d7f3d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
24 changes: 19 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.")
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions cmake/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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$<$<CONFIG:Debug>: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)
Expand Down

0 comments on commit 99d7f3d

Please sign in to comment.