Skip to content

Commit

Permalink
Added VFC_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
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.
  • Loading branch information
akb825 committed Nov 30, 2024
1 parent ab7c352 commit 5364066
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
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(VFC)

# Build options
Expand All @@ -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.")
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

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 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.
Expand All @@ -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$<$<CONFIG:Debug>: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()
Expand Down

0 comments on commit 5364066

Please sign in to comment.