CMake Windows static runtime libs issue

Hi all, hopefully someone can offer a suggestion.
I am trying to build my plugin so that it links statically against the C++ runtime library on Windows (dont want users to have to get vc runtimes). I am using Cmake, and I have added this to my CMakeFile (from an example on the cmake website):
set_property(TARGET myplugin PROPERTY
MSVC_RUNTIME_LIBRARY “MultiThreaded$<$CONFIG:Debug:Debug>”)

When I generate my VS projects, it looks like the project file for myplugin has the correct code generation setting (eg /MTd for multi threaded static debug) but the client project (eg the VST3 project) has the dynamic runtime set (eg /MDd = multi threaded dynamic debug)

Does anyone know if this is an issue, or is there another juce related flag I need to set?


Another user helped me out. In case anyone else runs into it:
Different targets are created for each client, so in my case I added:
set_property(TARGET myplugin_VST3 PROPERTY
MSVC_RUNTIME_LIBRARY “MultiThreaded$<$CONFIG:Debug:Debug>”)

I’ve found a more ‘global’ solution to this problem:

  1. Bump the minimum CMake version:
    cmake_minimum_required(VERSION 3.16)

  2. Use this at the top of the cmake file (no need to configure per target)
    set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

1 Like

You can do that as well FWIW

  add_compile_options($<$<CONFIG:Release>:/MT> # Runtime library: Multi-threaded
                      $<$<CONFIG:RelWithDebInfo>:/MT> # Runtime library: Multi-threaded                           
                      $<$<CONFIG:Debug>:/MTd> # Runtime library: Multi-threaded Debug
1 Like

Thanks for the additional tips.