40 lines
1.8 KiB
CMake
40 lines
1.8 KiB
CMake
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()
|