Add CMake option to link MSVC runtime statically#878
Add CMake option to link MSVC runtime statically#878tbeu wants to merge 1 commit intomadler:developfrom
Conversation
|
Incorporated. Thanks. |
|
This seems rather strange. Why can't you just pass |
|
Merged commit: |
|
According to the CMake docs this is wrong and the variable should be set before project(). But honestly it should be better passed on the command line instead of the CMakeLists.txt because it can apply to your entire build not to just a single project, of which zlib may be one of many. |
|
@nmoinvaz Are you recommending that I undo this commit? |
|
Or adding a new change to be perfect? There is this PR too: |
|
I would undo this commit yes, the docs clearly state it must be set before Even if you were to move it, I also oppose #535, as I don't think you need a specialized option to statically link with runtime library. Instead it is easy enough to do: Windows: cmake -S . -B build -D CMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedLinux/Apple: export LDFLAGS=-static
cmake -S . -B build Or even: cmake -S . -B build -D CMAKE_EXE_LINKER_FLAGS=-static -D CMAKE_SHARED_LINKER_FLAGS=-staticAny user can also CMake command instructions, like the ones mentioned, are better suited for the GitHub wiki page for this project. I have edited it here. Feel free to change it. |
|
Thanks! I didn't even know there was a wiki. |
|
Sorry @tbeu. Reverted. |
|
I may have read that documentation wrong, it seems only I think if you keep this PR, at the very least it should be changed to |

This fixes #849 (and the broken CRT static linkage) in a proper way. Call
to link the C runtime library statically. Default (still) is dynamically.
This should supersed #535.