Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the option to statically link against the MSVC runtime library … #17

Open
wants to merge 2 commits into
base: backtrace
Choose a base branch
from

Conversation

cjserio
Copy link

@cjserio cjserio commented Sep 12, 2022

…by using the -DSTATIC_RUNTIME=ON argument passed to the cmake generator command.

…by using the -DSTATIC_RUNTIME=ON argument passed to the cmake generator command.
@vlussenburg vlussenburg changed the base branch from backtrace to feature/createDistributionZip September 12, 2022 16:03
@vlussenburg vlussenburg changed the base branch from feature/createDistributionZip to backtrace September 12, 2022 16:04
@drywolf
Copy link

drywolf commented Sep 16, 2022

Hi,
FYI I think you can already easily tell CMake to build targets either with /MD or /MT without doing so much custom CMake coding.

CMake introduced this feature in version 3.15
To use it you must change the cmake_minimum_required(VERSION ...) at the beginning of CMakeLists.txt.

# if you use any version older than 3.15, then these features will not work !
# you will not even get any warnings or other log messages about it
cmake_minimum_required(VERSION 3.12) # <--- for any version older than 3.15, setting CMAKE_MSVC_RUNTIME_LIBRARY will do nothing

# if you set a minimum version newer than 3.15, then the builtin CMake features for 
# switching the MSVC C++ Runtime linking  will start working for you
cmake_minimum_required(VERSION 3.15) # <--- you have to set at least 3.15 or any later version here

Then you can either set the global CMake variable CMAKE_MSVC_RUNTIME_LIBRARY at the beginning of the crashpad CMakeLists.txt
... or, if you want to set this on a per-target basis, you can use set_target_properties() on specific targets and set the MSVC_RUNTIME_LIBRARY property individually for each target.

By setting either of those to MultiThreaded$<$<CONFIG:Debug>:Debug> you will get the static /MT runtime-linking in Visual Studio/MSBuild ... if you set MultiThreaded$<$<CONFIG:Debug>:Debug>DLL you will get the dll /MD runtime-linking.

IMO there is rarely a need to fiddle with low-level compiler flags / compiler options when using CMake
(especially on Windows when using MSVC)
Modern CMake already has a lot of the common usecases covered 😉

PS: I tried doing the above in the CMakeLists.txt of this repo, and it worked on the first try.
(I can build both /MD or /MT simply by doing what I described above)

@vlussenburg
Copy link
Contributor

@KrzaQ WDYT?

@KrzaQ
Copy link
Contributor

KrzaQ commented Oct 6, 2022

I think I need to educate myself about this before offering an opinion. I expect I'll have the time to look at this next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants