From f0de764003df7cd029d27b24859fc444b3a461cf Mon Sep 17 00:00:00 2001 From: mhandb Date: Wed, 15 May 2024 12:56:07 +0200 Subject: [PATCH 1/3] fix build issues on Windows - call cmake build steps so it is compatible with Windows and linux - protect unix specific includes so they are not include in Windows - avoid to link to unix lib in Windows --- egl_probe/CMakeLists.txt | 11 +++++++++-- egl_probe/query_devices.cpp | 4 +++- egl_probe/test_device.cpp | 4 +++- setup.py | 3 ++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/egl_probe/CMakeLists.txt b/egl_probe/CMakeLists.txt index a59f358..70593b6 100644 --- a/egl_probe/CMakeLists.txt +++ b/egl_probe/CMakeLists.txt @@ -7,5 +7,12 @@ add_definitions(-DUSE_GLAD) add_executable(query_devices glad/egl.cpp glad/gl.cpp query_devices.cpp) add_executable(test_device glad/egl.cpp glad/gl.cpp test_device.cpp) -target_link_libraries(query_devices dl pthread) -target_link_libraries(test_device dl pthread) \ No newline at end of file + +IF(WIN32) + SET(PLATFORM_LIBS) +ELSE(WIN32) + SET(PLATFORM_LIBS dl pthread) +ENDIF(WIN32) + +target_link_libraries(query_devices ${PLATFORM_LIBS}) +target_link_libraries(test_device ${PLATFORM_LIBS}) \ No newline at end of file diff --git a/egl_probe/query_devices.cpp b/egl_probe/query_devices.cpp index d62e509..a21c823 100644 --- a/egl_probe/query_devices.cpp +++ b/egl_probe/query_devices.cpp @@ -7,7 +7,9 @@ #include #include #include -#include +#ifndef _WIN32 + #include +#endif #ifdef USE_GLAD #include diff --git a/egl_probe/test_device.cpp b/egl_probe/test_device.cpp index 9dc6102..6c85a5e 100644 --- a/egl_probe/test_device.cpp +++ b/egl_probe/test_device.cpp @@ -7,7 +7,9 @@ #include #include #include -#include +#ifndef _WIN32 + #include +#endif #ifdef USE_GLAD #include diff --git a/setup.py b/setup.py index 9722581..145469a 100644 --- a/setup.py +++ b/setup.py @@ -35,7 +35,8 @@ def build_extension(self, ext): os.mkdir(build_dir) # build using cmake - subprocess.check_call("cmake ..; make -j", cwd=build_dir, shell=True) + subprocess.check_call("cmake -S .. -B .", cwd=build_dir, shell=True) + subprocess.check_call("cmake --build .", cwd=build_dir, shell=True) if sys.version_info.major == 3: From cc7903da34fcf007c16a677b5f76fdd304087f77 Mon Sep 17 00:00:00 2001 From: mhandb Date: Wed, 26 Jun 2024 11:05:03 +0200 Subject: [PATCH 2/3] use stdcall calling convention even in x86 It allows the project to build for x86 target without changing the glad source code. Indeed, in windows the default calling convention for x86 is cdecl. And the glad source code expect some functions to use the stdcall calling convention. --- egl_probe/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/egl_probe/CMakeLists.txt b/egl_probe/CMakeLists.txt index 70593b6..d27c221 100644 --- a/egl_probe/CMakeLists.txt +++ b/egl_probe/CMakeLists.txt @@ -10,6 +10,11 @@ add_executable(test_device glad/egl.cpp glad/gl.cpp test_device.cpp) IF(WIN32) SET(PLATFORM_LIBS) + IF(NOT CMAKE_CL_64) + # tell the compiler to use stdcall calling convention even in x86 where cdecl is default + # this is a simple workaround for Win32 x86 support + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Gz") + ENDIF() ELSE(WIN32) SET(PLATFORM_LIBS dl pthread) ENDIF(WIN32) From e3276d3edfd628637b8237ce5619e2457991617f Mon Sep 17 00:00:00 2001 From: mhandb Date: Wed, 26 Jun 2024 21:30:25 +0200 Subject: [PATCH 3/3] revert use of a CMake workaround for 32bit build TODO: fix the code to support 32bit builds --- egl_probe/CMakeLists.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/egl_probe/CMakeLists.txt b/egl_probe/CMakeLists.txt index d27c221..70593b6 100644 --- a/egl_probe/CMakeLists.txt +++ b/egl_probe/CMakeLists.txt @@ -10,11 +10,6 @@ add_executable(test_device glad/egl.cpp glad/gl.cpp test_device.cpp) IF(WIN32) SET(PLATFORM_LIBS) - IF(NOT CMAKE_CL_64) - # tell the compiler to use stdcall calling convention even in x86 where cdecl is default - # this is a simple workaround for Win32 x86 support - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Gz") - ENDIF() ELSE(WIN32) SET(PLATFORM_LIBS dl pthread) ENDIF(WIN32)