Skip to content

Commit b85bc31

Browse files
committed
Added VFC_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.
1 parent ab7c352 commit b85bc31

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
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()
27
project(VFC)
38

49
# Build options
@@ -9,6 +14,7 @@ else()
914
set(VFC_SHARED_DEFAULT OFF)
1015
endif()
1116
set(VFC_SHARED ${VFC_SHARED_DEFAULT} CACHE BOOL "Build VFC using shared libraries.")
17+
set(VFC_STATIC_RUNTIME OFF CACHE BOOL "Use static runtime library on Windows.")
1218

1319
# Options for disabling portions of the build.
1420
set(VFC_BUILD_TESTS ON CACHE BOOL "Build unit tests.")

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Example uses include:
1414

1515
The following software is required to build VFC:
1616

17-
* [CMake](https://cmake.org/) 3.1 or later
17+
* [CMake](https://cmake.org/) 3.10 or later
1818
* [GLM](https://glm.g-truc.net/) (required, included as a submodule)
1919
* [RapidJSON](https://rapidjson.org/) (required for tool, included as a submodule)
2020
* [doxygen](https://doxygen.nl/) (optional)
@@ -75,6 +75,7 @@ The following options may be used when running cmake:
7575
* `-DCMAKE_BUILD_TYPE=Debug|Release`: Building in `Debug` or `Release`. This should always be specified.
7676
* `-DCMAKE_INSTALL_PREFIX=path`: Sets the path to install to when running `make install`.
7777
* `-DVFC_SHARED=ON|OFF`: Set to `ON` to build with shared libraries, `OFF` to build with static libraries. Default is `OFF`.
78+
* `-DVFC_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 `VFC_SHARED` is also `ON`. Default is `OFF`.
7879

7980
### Enabled Builds
8081

cmake/config.cmake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2020-2022 Aaron Barany
1+
# Copyright 2020-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.
@@ -20,6 +20,13 @@ set(CMAKE_CXX_STANDARD 14)
2020
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
2121

2222
if (MSVC)
23+
if (VFC_STATIC_RUNTIME)
24+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
25+
if (VFC_SHARED)
26+
message(WARNING
27+
"It is not recommended to have VFC_SHARED and VFC_STATIC_RUNTIME both set to ON.")
28+
endif()
29+
endif()
2330
add_compile_options(/W3 /WX /wd4200 /MP)
2431
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS)
2532
else()

0 commit comments

Comments
 (0)