mirage_old/cmake/configure_glfw_native.cmake
daiqingshuang b7936d2e1a init
2025-02-08 12:59:59 +08:00

40 lines
1.8 KiB
CMake
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function(configure_glfw_native target)
# 检测操作系统
if(WIN32)
target_compile_definitions(${target} PRIVATE GLFW_EXPOSE_NATIVE_WIN32)
message(STATUS "Exposing GLFW native Win32 API")
elseif(APPLE)
target_compile_definitions(${target} PRIVATE GLFW_EXPOSE_NATIVE_COCOA)
message(STATUS "Exposing GLFW native Cocoa API")
elseif(UNIX)
# 对于 Unix-like 系统,我们需要进一步检测
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
# 检测 Wayland
find_package(Wayland)
if(Wayland_FOUND)
target_compile_definitions(${target} PRIVATE GLFW_EXPOSE_NATIVE_WAYLAND)
message(STATUS "Exposing GLFW native Wayland API")
else()
# 如果没有 Wayland默认使用 X11
target_compile_definitions(${target} PRIVATE GLFW_EXPOSE_NATIVE_X11)
message(STATUS "Exposing GLFW native X11 API")
endif()
elseif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD|OpenBSD|NetBSD")
# BSD 系统通常使用 X11
target_compile_definitions(${target} PRIVATE GLFW_EXPOSE_NATIVE_X11)
message(STATUS "Exposing GLFW native X11 API for BSD")
else()
message(WARNING "Unknown Unix-like system, GLFW native API might not be properly exposed")
endif()
else()
message(WARNING "Unknown operating system, GLFW native API might not be properly exposed")
endif()
# 对于 EGL 支持,你可能需要额外的检测
# 这里我们简单地为所有非 Windows 和非 macOS 系统启用它
if(NOT WIN32 AND NOT APPLE)
target_compile_definitions(${target} PRIVATE GLFW_EXPOSE_NATIVE_EGL)
message(STATUS "Exposing GLFW native EGL API")
endif()
endfunction()