From 5364066ff9096d22cf9c9dd1ba951759b7f245fb Mon Sep 17 00:00:00 2001 From: Aaron Barany Date: Fri, 29 Nov 2024 19:02:01 -0800 Subject: [PATCH] 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 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. --- CMakeLists.txt | 11 ++++++++++- README.md | 3 ++- cmake/config.cmake | 9 ++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4cbee2e..008b8ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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(VFC) # Build options @@ -9,6 +17,7 @@ else() set(VFC_SHARED_DEFAULT OFF) endif() set(VFC_SHARED ${VFC_SHARED_DEFAULT} CACHE BOOL "Build VFC using shared libraries.") +set(VFC_STATIC_RUNTIME OFF CACHE BOOL "Use static runtime library on Windows.") # Options for disabling portions of the build. set(VFC_BUILD_TESTS ON CACHE BOOL "Build unit tests.") diff --git a/README.md b/README.md index 0739e6e..cf74546 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Example uses include: The following software is required to build VFC: -* [CMake](https://cmake.org/) 3.1 or later +* [CMake](https://cmake.org/) 3.10 or later * [GLM](https://glm.g-truc.net/) (required, included as a submodule) * [RapidJSON](https://rapidjson.org/) (required for tool, included as a submodule) * [doxygen](https://doxygen.nl/) (optional) @@ -75,6 +75,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`. * `-DVFC_SHARED=ON|OFF`: Set to `ON` to build with shared libraries, `OFF` to build with static libraries. Default is `OFF`. +* `-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`. ### Enabled Builds diff --git a/cmake/config.cmake b/cmake/config.cmake index 371d741..8fd9578 100644 --- a/cmake/config.cmake +++ b/cmake/config.cmake @@ -1,4 +1,4 @@ -# Copyright 2020-2022 Aaron Barany +# Copyright 2020-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. @@ -20,6 +20,13 @@ set(CMAKE_CXX_STANDARD 14) set(CMAKE_POSITION_INDEPENDENT_CODE ON) if (MSVC) + if (VFC_STATIC_RUNTIME) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + if (VFC_SHARED) + message(WARNING + "It is not recommended to have VFC_SHARED and VFC_STATIC_RUNTIME both set to ON.") + endif() + endif() add_compile_options(/W3 /WX /wd4200 /MP) add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS) else()