Skip to content

Commit 6687ede

Browse files
committed
Added MSL_STATIC_RUNTIME CMake flag.
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.
1 parent dac9381 commit 6687ede

File tree

9 files changed

+30
-13
lines changed

9 files changed

+30
-13
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,19 +165,19 @@ jobs:
165165
- arch: Win32
166166
bits: 32
167167
lib_type: Static
168-
cmake_args: "-DMSL_SHARED=OFF -DBOOST_ROOT=D:/boost"
168+
cmake_args: "-DMSL_SHARED=OFF -DBoost_DIR=D:/boost/lib32-msvc-${{ env.msvc_version }}/cmake/Boost-${{ env.boost_version }}"
169169
- arch: Win32
170170
bits: 32
171171
lib_type: Shared
172-
cmake_args: "-DMSL_SHARED=ON -DBOOST_ROOT=D:/boost"
172+
cmake_args: "-DMSL_SHARED=ON -DBoost_DIR=D:/boost/lib32-msvc-${{ env.msvc_version }}/cmake/Boost-${{ env.boost_version }}"
173173
- arch: x64
174174
bits: 64
175175
lib_type: Static
176-
cmake_args: "-DMSL_SHARED=OFF -DBOOST_ROOT=D:/boost"
176+
cmake_args: "-DMSL_SHARED=OFF -DBoost_DIR=D:/boost/lib64-msvc-${{ env.msvc_version }}/cmake/Boost-${{ env.boost_version }}"
177177
- arch: x64
178178
bits: 64
179179
lib_type: Shared
180-
cmake_args: "-DMSL_SHARED=ON -DBOOST_ROOT=D:/boost"
180+
cmake_args: "-DMSL_SHARED=ON -DBoost_DIR=D:/boost/lib64-msvc-${{ env.msvc_version }}/cmake/Boost-${{ env.boost_version }}"
181181
steps:
182182
- name: checkout
183183
uses: actions/checkout@v4

CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
cmake_minimum_required(VERSION 3.5)
1+
if (WIN32)
2+
# Needs 3.15 for CMAKE_MSVC_RUNTIME_LIBRARY.
3+
cmake_minimum_required(VERSION 3.15)
4+
else()
5+
cmake_minimum_required(VERSION 3.10)
6+
endif()
7+
if (POLICY CMP0144)
8+
cmake_policy(SET CMP0144 NEW)
9+
endif()
210
project(MSL)
311

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

1322
# Options for disabling portions of the build.
1423
set(MSL_BUILD_TESTS ON CACHE BOOL "Build unit tests.")

Client/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ if (NOT GTEST_FOUND OR NOT MSL_BUILD_TESTS)
22
return()
33
endif()
44

5-
find_package(Boost COMPONENTS filesystem REQUIRED)
5+
find_package(Boost CONFIG COMPONENTS filesystem REQUIRED)
66
find_package(Threads)
77

88
file(GLOB_RECURSE sources *.cpp *.h)

Compile/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
find_package(Boost COMPONENTS filesystem wave REQUIRED)
1+
find_package(Boost CONFIG COMPONENTS filesystem wave REQUIRED)
22
find_package(Threads)
33

44
set(GLSLANG_DIR ${CMAKE_CURRENT_SOURCE_DIR}/glslang)

Compile/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ if (NOT GTEST_FOUND OR NOT MSL_BUILD_TESTS)
22
return()
33
endif()
44

5-
find_package(Boost COMPONENTS filesystem REQUIRED)
5+
find_package(Boost CONFIG COMPONENTS filesystem REQUIRED)
66
find_package(Threads)
77

88
file(GLOB_RECURSE sources *.cpp *.h)

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Multiple shader files may be compiled into a module. Examples for combining modu
3939

4040
The following software is required to build MSL:
4141

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

5252
> **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`
5353
54-
> **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.
54+
> **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.
5555
5656
The glslang, SPIRV-Cross, and SPIRV-Tools submodules can be grabbed by running `git submodule update --init --recursive`.
5757

@@ -87,6 +87,7 @@ The following options may be used when running cmake:
8787
* `-DCMAKE_BUILD_TYPE=Debug|Release`: Building in `Debug` or `Release`. This should always be specified.
8888
* `-DCMAKE_INSTALL_PREFIX=path`: Sets the path to install to when running make install.
8989
* `-DMSL_SHARED=ON|OFF`: Set to `ON` to build with shared libraries, `OFF` to build with static libraries. Default is `OFF`.
90+
* `-MSL_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`.
9091

9192
## Enabled Builds
9293

cmake/config.cmake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2018-2022 Aaron Barany
1+
# Copyright 2018-2024 Aaron Barany
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -19,6 +19,13 @@ set(CMAKE_CXX_STANDARD 17)
1919
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
2020

2121
if (MSVC)
22+
if (MSL_STATIC_RUNTIME)
23+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
24+
if (MSL_SHARED)
25+
message(WARNING
26+
"It is not recommended to have MSL_SHARED and MSL_STATIC_RUNTIME both set to ON.")
27+
endif()
28+
endif()
2229
add_compile_options(/W3 /WX /wd4200 /MP /bigobj)
2330
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS
2431
-D_CRT_NONSTDC_NO_WARNINGS -DBOOST_ALL_NO_LIB)

tools/mslb-extract/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
find_package(Boost COMPONENTS program_options filesystem)
1+
find_package(Boost CONFIG COMPONENTS program_options filesystem)
22

33
file(GLOB_RECURSE sources *.cpp *.h)
44
add_executable(mslb-extract ${sources})

tools/mslc/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
find_package(Boost COMPONENTS program_options)
1+
find_package(Boost CONFIG COMPONENTS program_options)
22

33
file(GLOB_RECURSE sources *.cpp *.h)
44
add_executable(mslc ${sources})

0 commit comments

Comments
 (0)