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 2e23398
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
34 changes: 28 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -224,37 +224,47 @@ jobs:
- arch: Win32
lib_type: Static
cmake_args: "-DCUTTLEFISH_SHARED=OFF"
shared_crt: ON
ispc: 0
- arch: Win32
lib_type: Shared
cmake_args: "-DCUTTLEFISH_SHARED=ON"
shared_crt: ON
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"
shared_crt: OFF
ispc: 1
artifact: win32-tool
- arch: Win32
lib_type: Shared
cmake_args: "-DCUTTLEFISH_SHARED=ON -DCUTTLEFISH_ISPC_PATH=D:/ispc/bin/ispc.exe"
shared_crt: ON
ispc: 1
artifact: win32
artifact: win32-full
- arch: x64
lib_type: Static
cmake_args: "-DCUTTLEFISH_SHARED=OFF"
shared_crt: ON
ispc: 0
- arch: x64
lib_type: Shared
cmake_args: "-DCUTTLEFISH_SHARED=ON"
shared_crt: ON
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"
shared_crt: OFF
ispc: 1
artifact: win64-tool
- arch: x64
lib_type: Shared
cmake_args: "-DCUTTLEFISH_SHARED=ON -DCUTTLEFISH_ISPC_PATH=D:/ispc/bin/ispc.exe"
shared_crt: ON
ispc: 1
artifact: win64
artifact: win64-full
steps:
- name: checkout
uses: actions/checkout@v4
Expand All @@ -278,7 +288,8 @@ jobs:
working-directory: "${{ github.workspace }}"
- name: Build gtest
run: |-
cmake .. -DCMAKE_INSTALL_PREFIX=${{ env.dependency_location }} -Dgtest_force_shared_crt=ON `
cmake .. -DCMAKE_INSTALL_PREFIX=${{ env.dependency_location }} `
-Dgtest_force_shared_crt=${{ matrix.shared_crt }} `
-A ${{ matrix.arch }} -T v141 -DCMAKE_DEBUG_POSTFIX=d
cmake --build . --config Debug
cmake --build . --config Debug --target install
Expand Down Expand Up @@ -325,9 +336,20 @@ 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.
run: |-
cmake --build . --config Debug --target install
cmake --build . --config Release --target install
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 cuttlefish-full
mv cuttlefish-full\bin cuttlefish
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
9 changes: 8 additions & 1 deletion cmake/config.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2017-2022 Aaron Barany
# Copyright 2017-2024 Aaron Barany
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down 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 2e23398

Please sign in to comment.