Skip to content

Commit

Permalink
Added MSL_STATIC_RUNTIME CMake flag.
Browse files Browse the repository at this point in the history
Allows for linking to the static runtime library on Windows.

Updated the minimum CMake version to 3.15 on Windows to support
set(CMAKE_MSVC_RUNTIME_LIBRARY. Other systems now require 3.10 to silence
warnings that newer versions will drop compatibility for a declared minimum
version < 3.10.

Use CONFIG mode for finding boost. Silences warning that in future versions
FindBoost.cmake will be removed. Updated example in README to set Boost_DIR
instead of other paths for FindBoost.cmake.
  • Loading branch information
akb825 committed Nov 30, 2024
1 parent dac9381 commit 8cd9389
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 14 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,19 @@ jobs:
- arch: Win32
bits: 32
lib_type: Static
cmake_args: "-DMSL_SHARED=OFF -DBOOST_ROOT=D:/boost"
cmake_args: "-DMSL_SHARED=OFF"
- arch: Win32
bits: 32
lib_type: Shared
cmake_args: "-DMSL_SHARED=ON -DBOOST_ROOT=D:/boost"
cmake_args: "-DMSL_SHARED=ON"
- arch: x64
bits: 64
lib_type: Static
cmake_args: "-DMSL_SHARED=OFF -DBOOST_ROOT=D:/boost"
cmake_args: "-DMSL_SHARED=OFF"
- arch: x64
bits: 64
lib_type: Shared
cmake_args: "-DMSL_SHARED=ON -DBOOST_ROOT=D:/boost"
cmake_args: "-DMSL_SHARED=ON"
steps:
- name: checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -217,7 +217,8 @@ jobs:
run: |-
mkdir build
cd build
cmake ${{ env.cmake_common_args }} ${{ matrix.cmake_args }} -A ${{ matrix.arch }} `
cmake ${{ env.cmake_common_args }} ${{ matrix.cmake_args }} `
-DBoost_DIR=D:/boost/lib${{ matrix.bits }}-msvc-${{ env.msvc_version }}/cmake/Boost-${{ env.boost_version }} -A ${{ matrix.arch }} `
-T v${{ env.msvc_toolset }} ${{ github.workspace }}
working-directory: "${{ github.workspace }}"
- name: Build debug
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(MSL)

# Build options
Expand All @@ -9,6 +17,7 @@ else()
set(MSL_SHARED_DEFAULT OFF)
endif()
set(MSL_SHARED ${MSL_SHARED_DEFAULT} CACHE BOOL "Build MSL using shared libraries.")
set(MSL_STATIC_RUNTIME OFF CACHE BOOL "Use static runtime library on Windows.")

# Options for disabling portions of the build.
set(MSL_BUILD_TESTS ON CACHE BOOL "Build unit tests.")
Expand Down
2 changes: 1 addition & 1 deletion Client/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ if (NOT GTEST_FOUND OR NOT MSL_BUILD_TESTS)
return()
endif()

find_package(Boost COMPONENTS filesystem REQUIRED)
find_package(Boost CONFIG COMPONENTS filesystem REQUIRED)
find_package(Threads)

file(GLOB_RECURSE sources *.cpp *.h)
Expand Down
2 changes: 1 addition & 1 deletion Compile/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
find_package(Boost COMPONENTS filesystem wave REQUIRED)
find_package(Boost CONFIG COMPONENTS filesystem wave REQUIRED)
find_package(Threads)

set(GLSLANG_DIR ${CMAKE_CURRENT_SOURCE_DIR}/glslang)
Expand Down
2 changes: 1 addition & 1 deletion Compile/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ if (NOT GTEST_FOUND OR NOT MSL_BUILD_TESTS)
return()
endif()

find_package(Boost COMPONENTS filesystem REQUIRED)
find_package(Boost CONFIG COMPONENTS filesystem REQUIRED)
find_package(Threads)

file(GLOB_RECURSE sources *.cpp *.h)
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Multiple shader files may be compiled into a module. Examples for combining modu

The following software is required to build MSL:

* [cmake](https://cmake.org/) 3.5 or later
* [cmake](https://cmake.org/) 3.10 or later
* [boost](https://www.boost.org/) (required unless only building client library without tests)
* [Python](https://www.python.org/) 3 or later (required unless only building client library)
* [glslang](https://github.com/KhronosGroup/glslang) (required for compiler, provided as submodule)
Expand All @@ -51,7 +51,7 @@ The following software is required to build MSL:

> **Note:** Boost must be built with C++11 support. For example, when building and installing through the b2 bootstrap command: `./b2 "-std=c++11" -j4 install`
> **Note:** When Boost is manually installed, the appropriate variables should be set. In the case of Windows, the `BOOST_LIBRARYDIR` and `BOOST_ROOT` variables should be set. (examples: `BOOST_LIBRARYDIR=C:\local\boost_1_64_0\lib64-msvc-14.1` and `BOOST_ROOT=C:\local\boost_1_64_0`) In Windows, the value of `BOOST_LIBRARYDIR` should also be on `PATH` to ensure the DLLs can be loaded.
> **Note:** When Boost is manually installed, the appropriate variables should be set. In the case of Windows, the `Boost_DIR` variable should be set. (example: `Boost_DIR=C:\local\boost_1_83_0\lib64-msvc-14.1\cmake\Boost-1.83.0`) In Windows, the path to the libraries (e.g. `C:\local\boost_1_83_0\lib64-msvc-14.1`) should be set on `PATH` to ensure the DLLs can be loaded.
The glslang, SPIRV-Cross, and SPIRV-Tools submodules can be grabbed by running `git submodule update --init --recursive`.

Expand Down Expand Up @@ -87,6 +87,7 @@ 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.
* `-DMSL_SHARED=ON|OFF`: Set to `ON` to build with shared libraries, `OFF` to build with static libraries. Default is `OFF`.
* `-DMSL_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 `MSL_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 2018-2022 Aaron Barany
# Copyright 2018-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 All @@ -19,6 +19,13 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

if (MSVC)
if (MSL_STATIC_RUNTIME)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
if (MSL_SHARED)
message(WARNING
"It is not recommended to have MSL_SHARED and MSL_STATIC_RUNTIME both set to ON.")
endif()
endif()
add_compile_options(/W3 /WX /wd4200 /MP /bigobj)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS
-D_CRT_NONSTDC_NO_WARNINGS -DBOOST_ALL_NO_LIB)
Expand Down
2 changes: 1 addition & 1 deletion tools/mslb-extract/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
find_package(Boost COMPONENTS program_options filesystem)
find_package(Boost CONFIG COMPONENTS program_options filesystem)

file(GLOB_RECURSE sources *.cpp *.h)
add_executable(mslb-extract ${sources})
Expand Down
2 changes: 1 addition & 1 deletion tools/mslc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
find_package(Boost COMPONENTS program_options)
find_package(Boost CONFIG COMPONENTS program_options)

file(GLOB_RECURSE sources *.cpp *.h)
add_executable(mslc ${sources})
Expand Down

0 comments on commit 8cd9389

Please sign in to comment.