Closed tbeu closed 9 months ago
Incorporated. Thanks.
This seems rather strange. Why can't you just pass -D CMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebug
on the command line?
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?
I would undo this commit yes, the docs clearly state it must be set before project()
.
Even if you were to move it, CMAKE_GENERATOR
would likely be invalid before project()
so it would need some rework.
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=MultiThreaded
Linux/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=-static
Any user can also set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded")
in their parent CMake project if they wanted. Also this PR change would discard any CMAKE_MSVC_RUNTIME_LIBRARY
setting that might be set by a parent project because it sets it in the else()
condition always.
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 CMP0091
needs to be set before project()
.
I think if you keep this PR, at the very least it should be changed to if(POLICY CMP0091 AND NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
. I fear it will mess up parent projects that already set this a different way.
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.