wxWidgets / wxWidgets

Cross-Platform C++ GUI Library
https://www.wxwidgets.org/
6.32k stars 1.79k forks source link

CMake: Fix using static runtime with msvc #25098

Closed MaartenBent closed 2 weeks ago

MaartenBent commented 2 weeks ago

This was broken with recent CMake versions, see wx-dev discussion https://groups.google.com/g/wx-dev/c/0ECwYNf8TfU

vadz commented 2 weeks ago

Thanks! Should anything here be backported?

MaartenBent commented 2 weeks ago

Yes, it can be backported. But I didn't fix the issue with CMAKE_MSVC_RUNTIME_LIBRARY yet. Could you apply the following?

diff --git "a/build/cmake/options.cmake" "b/build/cmake/options.cmake"
index bcda6164282..7cfcef1afe0 100644
--- "a/build/cmake/options.cmake"
+++ "b/build/cmake/options.cmake"
@@ -37,7 +37,7 @@ mark_as_advanced(wxBUILD_DEBUG_LEVEL)

 if(NOT APPLE)
     set(wxBUILD_USE_STATIC_RUNTIME_DEFAULT OFF)
-    if(MSVC AND CMAKE_MSVC_RUNTIME_LIBRARY)
+    if(MSVC AND CMAKE_MSVC_RUNTIME_LIBRARY AND NOT CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL")
         set(wxBUILD_USE_STATIC_RUNTIME_DEFAULT ON)
     endif()
     wx_option(wxBUILD_USE_STATIC_RUNTIME "Link using the static runtime library" ${wxBUILD_USE_STATIC_RUNTIME_DEFAULT})
vadz commented 2 weeks ago

Oops, sorry, I've looked at this too quickly and thought this was finished. I'll push the missing change soon.