godot-cpp icon indicating copy to clipboard operation
godot-cpp copied to clipboard

Expanding CMake to other compilers other than MSVC on Windows platform

Open BoHomola opened this issue 2 years ago • 3 comments

#1250

BoHomola avatar Sep 22 '23 13:09 BoHomola

Thank you for looking into this.

My understanding is that TYPED_METHOD_BIND should not be defined when using mingw, and that by using the WIN32 flag all windows builds (including mingw ones) will have that flag set.

So we need to detect the specific case of Clang as a MSVC frontend, which as far as I understand means checking the CXX_COMPILER_FRONTEND_VARIANT variable.

I don't know much about CMake, but this might work:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0ee99aa..215c719 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -55,7 +55,7 @@ endif()
 # Set some helper variables for readability
 set( compiler_is_clang "$<OR:$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:Clang>>" )
 set( compiler_is_gnu "$<CXX_COMPILER_ID:GNU>" )
-set( compiler_is_msvc "$<CXX_COMPILER_ID:MSVC>" )
+set( compiler_is_msvc "$<OR:$<CXX_COMPILER_ID:MSVC>,$<CXX_COMPILER_FRONTEND_VARIANT:MSVC>>" )
 
 # Default build type is Debug in the SConstruct
 if("${CMAKE_BUILD_TYPE}" STREQUAL "")

Faless avatar Oct 18 '23 14:10 Faless

Hello, thank you for your feedback.

CXX_COMPILER_FRONTEND_VARIANT would not work. I am using clang with GNU frontend. So the condition for defining TYPED_METHOD_BIND would still result in false.

If we want to specifically exclude MinGW, then a simple check if WIN and NOT GNU should work.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0ee99aa..45b9238 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -159,7 +159,7 @@ target_compile_definitions(${PROJECT_NAME} PUBLIC
                DEBUG_ENABLED
                DEBUG_METHODS_ENABLED
        >
-       $<${compiler_is_msvc}:
+    $<$<AND:$<BOOL:${WIN32}>,$<NOT:${compiler_is_gnu}>>:
                TYPED_METHOD_BIND
        >
 )

BoHomola avatar Oct 18 '23 21:10 BoHomola