i have a weird problem with CMake and the MSVC runtime on windows.
My application is statically linked against the msvc runtime, which means all libraries i am linking statically, also have to be linked against the msvc runtime statically.
This works as expected for most of my libraries.
However i have a problem with libdatachannel. Libdatachannel provides a CMake project, with which i can generate nmake files. They provide a target “datachannel-static” with which i can generate a static library. The problem is that this static library is linked against the msvc runtime dynamically.
With the help of the maintainers of the libdatachannel project, i tried the following command to force the linking of the static runtime:
cmake -B ../libDataChannel-build -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DOPENSSL_ROOT_DIR=<..> -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded"
This gets completely ignored and the generated makefiles contain the /MD directive in the CXX flags.
I then tried setting the variable directly in the libdatachannel CMakeLists.txt with:
This also is ignored. I then tried to set the property for every target of libdatachannel:
Also without any success.
Only forcing the CXX flags and manually replacing /MD with /MT works.
It is noteworthy that on one windows machine, with the same setup as on the other, setting the MSVC runtime via command line is working, while on the other machine it is not. Both use cmake version 3.26.4 and are executed in the Visual Studio 2022 Developer Command Prompt v17.8.6.
This also applies to the sub-projects that are used by libdatachannel and utilize cmake.
I dont know what could be the cause of this issue.
Thanks in advance