Skip to content

Potential issue with CMAKE_MSVC_RUNTIME_LIBRARY #12

Description

@Rewriter00x

Hello @meemknight! I may have discovered an issue with your way of setting CMAKE_MSVC_RUNTIME_LIBRARY

I will refer to this snippet, as this is how you set it up in your cmakeSetup video

set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Release>:Release>")

In theory this should set CMAKE_MSVC_RUNTIME_LIBRARY to MultiThreadedRelease when config is Release and MultiThreadedDebug when config is debug. Correct me if I'm wrong, but I see two different issues here:

Firstly, if we take a look at official documentation of cmake for CMAKE_MSVC_RUNTIME_LIBRARY, we find that MultiThreadedRelease is not an allowed value for CMAKE_MSVC_RUNTIME_LIBRARY, which is the first issue I've encountered when trying to link runtime statically. The correct value for release configuration is simply MultiThreaded

Lastly, using set() twice for CMAKE_MSVC_RUNTIME_LIBRARY causes it to be overwritten by the latest call. I replaced static runtime with dynamic and after running dumpbin /dependents on built files I have proven that this usage of set() does not work. I have later adjusted the snipped and received the correct linking results

So, here's how this should look like (the similar example can be found in already mentioned CMAKE_MSVC_RUNTIME_LIBRARY documentation):

set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

Fun fact: if we switch places in your snippet to set release first, as your do in most your repos, like so:

set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Release>:Release>")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

everything will work correctly, since first we always set release value, which may be invalid (MultiThreadedRelease), but then we always overwrite it with correct values (MultiThreaded for release and MultiThreadedDebug for debug).

I would advise you fix this in all your cmake setup repos, as release line is wrong and obsolete, and will break if placed after debug line

Thank you for your attention!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions