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

Fix: [MSVC] generate static libraries / executables correctly with vcpkg -static target #11208

Merged
merged 1 commit into from
Aug 18, 2023

Conversation

TrueBrain
Copy link
Member

Motivation / Problem

When building for MSVC I was often warned that /MDd (dynamic) was overwriting /MT (static), which surprised me, as we should be /MT. Now this was never the problem with our current libraries, and things were linked in statically anyway, but when adding breakpad for testing, it became apparent that we were actually compiling /MDd. But with the vcpkg target x64-windows-static I expected /MTd.

Description

Since CMake 3.15 (our minimum is 3.16) there is a CMake variable https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html to indicate whether /MD or /MT should be used. Seems in more recent MSVC and CMake this is finally handled properly, and MSVC was happily compiling the binary dynamic.

By setting it correctly, the /MTd is correctly added instead of the /MDd (well, it is -MTd and -MDd, but who is counting). The best way to validate this is to make an error in a file, and check the cl.exe line.

In case you wonder if it is actually the intention to build static, please see https://github.com/OpenTTD/OpenTTD/blob/master/cmake/CompileFlags.cmake#L8 . We already tried .. but that no longer works for the latest CMake / MSVC combo.

Limitations

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR touches english.txt or translations? Check the guidelines
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, game_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

@TrueBrain TrueBrain enabled auto-merge (squash) August 18, 2023 17:42
Copy link
Contributor

@glx22 glx22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the proper way is clearly better than the hacky way (especially when the hacky no longer works)

@TrueBrain TrueBrain merged commit 53af209 into OpenTTD:master Aug 18, 2023
20 checks passed
@TrueBrain TrueBrain deleted the msvc-static branch January 18, 2024 18:46
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.

None yet

2 participants