Use static MSVC runtime library (/MT) for Windows builds#1
Open
Use static MSVC runtime library (/MT) for Windows builds#1
Conversation
Configure CMAKE_MSVC_RUNTIME_LIBRARY to use MultiThreaded (static) runtime instead of the default MultiThreadedDLL (dynamic) runtime. This links the C runtime library statically, eliminating the need for vcruntime DLLs at runtime. - Enable CMP0091 policy to support CMAKE_MSVC_RUNTIME_LIBRARY - Set runtime to /MT for Release, /MTd for Debug configurations
Explicitly set MSVC_RUNTIME_LIBRARY property on bgfx, bx, bimg, bimg_decode, bimg_encode, and freetype targets to ensure they all use the static runtime library (/MT for Release, /MTd for Debug). This ensures consistent runtime linking across the main project and all third-party dependencies fetched via FetchContent.
Add CMAKE_POLICY_DEFAULT_CMP0091 to ensure the MSVC runtime library policy is propagated to all subprojects including those added via FetchContent (bgfx, bx, bimg, freetype).
The runtime library variable must be set before FetchContent targets are configured, not after. Move the setting to before the FetchContent_MakeAvailable(bgfx) call so bgfx, bx, bimg, and freetype all pick up the /MT runtime setting during their configuration.
bgfx's cmake_minimum_required(3.10.2) resets the CMP0091 policy, so we need to set CMAKE_POLICY_DEFAULT_CMP0091 NEW immediately before FetchContent_MakeAvailable to ensure the policy is applied when bgfx is configured.
Add target_compile_options with /MT and /MTd flags directly to each FetchContent target (bx, bimg, bimg_decode, bimg_encode, bgfx, freetype) as a more direct approach to ensure static runtime linking.
Add explicit /MT and /MTd compile options via add_compile_options in compile_flags.cmake so all visage library targets (VisageGraphics, VisageUtils, VisageUI, VisageWidgets, VisageWindowing, VisageApp) use the static runtime.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Configure CMAKE_MSVC_RUNTIME_LIBRARY to use MultiThreaded (static) runtime instead of the default MultiThreadedDLL (dynamic) runtime. This links the C runtime library statically, eliminating the need for vcruntime DLLs at runtime.