ScrapExplorer - CMakeLists.txt
Home / ext / glfw / src Lines: 1 | Size: 12828 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1 2add_library(glfw ${GLFW_LIBRARY_TYPE} 3 "${GLFW_SOURCE_DIR}/include/GLFW/glfw3.h" 4 "${GLFW_SOURCE_DIR}/include/GLFW/glfw3native.h" 5 internal.h platform.h mappings.h 6 context.c init.c input.c monitor.c platform.c vulkan.c window.c 7 egl_context.c osmesa_context.c null_platform.h null_joystick.h 8 null_init.c null_monitor.c null_window.c null_joystick.c) 9 10# The time, thread and module code is shared between all backends on a given OS, 11# including the null backend, which still needs those bits to be functional 12if (APPLE) 13 target_sources(glfw PRIVATE cocoa_time.h cocoa_time.c posix_thread.h 14 posix_module.c posix_thread.c) 15elseif (WIN32) 16 target_sources(glfw PRIVATE win32_time.h win32_thread.h win32_module.c 17 win32_time.c win32_thread.c) 18else() 19 target_sources(glfw PRIVATE posix_time.h posix_thread.h posix_module.c 20 posix_time.c posix_thread.c) 21endif() 22 23add_custom_target(update_mappings 24 COMMAND "${CMAKE_COMMAND}" -P "${GLFW_SOURCE_DIR}/CMake/GenerateMappings.cmake" mappings.h.in mappings.h 25 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" 26 COMMENT "Updating gamepad mappings from upstream repository" 27 SOURCES mappings.h.in "${GLFW_SOURCE_DIR}/CMake/GenerateMappings.cmake" 28 VERBATIM) 29 30set_target_properties(update_mappings PROPERTIES FOLDER "GLFW3") 31 32if (GLFW_BUILD_COCOA) 33 enable_language(OBJC) 34 target_compile_definitions(glfw PRIVATE _GLFW_COCOA) 35 target_sources(glfw PRIVATE cocoa_platform.h cocoa_joystick.h cocoa_init.m 36 cocoa_joystick.m cocoa_monitor.m cocoa_window.m 37 nsgl_context.m) 38endif() 39 40if (GLFW_BUILD_WIN32) 41 target_compile_definitions(glfw PRIVATE _GLFW_WIN32) 42 target_sources(glfw PRIVATE win32_platform.h win32_joystick.h win32_init.c 43 win32_joystick.c win32_monitor.c win32_window.c 44 wgl_context.c) 45endif() 46 47if (GLFW_BUILD_X11) 48 target_compile_definitions(glfw PRIVATE _GLFW_X11) 49 target_sources(glfw PRIVATE x11_platform.h xkb_unicode.h x11_init.c 50 x11_monitor.c x11_window.c xkb_unicode.c 51 glx_context.c) 52endif() 53 54if (GLFW_BUILD_WAYLAND) 55 target_compile_definitions(glfw PRIVATE _GLFW_WAYLAND) 56 target_sources(glfw PRIVATE wl_platform.h wl_init.c 57 wl_monitor.c wl_window.c) 58endif() 59 60if (GLFW_BUILD_X11 OR GLFW_BUILD_WAYLAND) 61 if (CMAKE_SYSTEM_NAME STREQUAL "Linux") 62 target_sources(glfw PRIVATE linux_joystick.h linux_joystick.c) 63 endif() 64 target_sources(glfw PRIVATE posix_poll.h posix_poll.c) 65endif() 66 67if (GLFW_BUILD_WAYLAND) 68 include(CheckIncludeFiles) 69 include(CheckFunctionExists) 70 check_function_exists(memfd_create HAVE_MEMFD_CREATE) 71 if (HAVE_MEMFD_CREATE) 72 target_compile_definitions(glfw PRIVATE HAVE_MEMFD_CREATE) 73 endif() 74 75 find_program(WAYLAND_SCANNER_EXECUTABLE NAMES wayland-scanner) 76 if (NOT WAYLAND_SCANNER_EXECUTABLE) 77 message(FATAL_ERROR "Failed to find wayland-scanner") 78 endif() 79 80 macro(generate_wayland_protocol protocol_file) 81 set(protocol_path "${GLFW_SOURCE_DIR}/deps/wayland/${protocol_file}") 82 83 string(REGEX REPLACE "\\.xml$" "-client-protocol.h" header_file ${protocol_file}) 84 string(REGEX REPLACE "\\.xml$" "-client-protocol-code.h" code_file ${protocol_file}) 85 86 add_custom_command(OUTPUT ${header_file} 87 COMMAND "${WAYLAND_SCANNER_EXECUTABLE}" client-header "${protocol_path}" ${header_file} 88 DEPENDS "${protocol_path}" 89 VERBATIM) 90 91 add_custom_command(OUTPUT ${code_file} 92 COMMAND "${WAYLAND_SCANNER_EXECUTABLE}" private-code "${protocol_path}" ${code_file} 93 DEPENDS "${protocol_path}" 94 VERBATIM) 95 96 target_sources(glfw PRIVATE ${header_file} ${code_file}) 97 endmacro() 98 99 generate_wayland_protocol("wayland.xml") 100 generate_wayland_protocol("viewporter.xml") 101 generate_wayland_protocol("xdg-shell.xml") 102 generate_wayland_protocol("idle-inhibit-unstable-v1.xml") 103 generate_wayland_protocol("pointer-constraints-unstable-v1.xml") 104 generate_wayland_protocol("relative-pointer-unstable-v1.xml") 105 generate_wayland_protocol("fractional-scale-v1.xml") 106 generate_wayland_protocol("xdg-activation-v1.xml") 107 generate_wayland_protocol("xdg-decoration-unstable-v1.xml") 108endif() 109 110if (WIN32 AND GLFW_BUILD_SHARED_LIBRARY) 111 configure_file(glfw.rc.in glfw.rc @ONLY) 112 target_sources(glfw PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/glfw.rc") 113endif() 114 115if (UNIX AND GLFW_BUILD_SHARED_LIBRARY) 116 # On Unix-like systems, shared libraries can use the soname system. 117 set(GLFW_LIB_NAME glfw) 118else() 119 set(GLFW_LIB_NAME glfw3) 120endif() 121set(GLFW_LIB_NAME_SUFFIX "") 122 123set_target_properties(glfw PROPERTIES 124 OUTPUT_NAME ${GLFW_LIB_NAME} 125 VERSION ${GLFW_VERSION_MAJOR}.${GLFW_VERSION_MINOR} 126 SOVERSION ${GLFW_VERSION_MAJOR} 127 POSITION_INDEPENDENT_CODE ON 128 C_STANDARD 99 129 C_EXTENSIONS OFF 130 DEFINE_SYMBOL _GLFW_BUILD_DLL 131 FOLDER "GLFW3") 132 133target_include_directories(glfw PUBLIC 134 "$<BUILD_INTERFACE:${GLFW_SOURCE_DIR}/include>" 135 "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>") 136target_include_directories(glfw PRIVATE 137 "${GLFW_SOURCE_DIR}/src" 138 "${GLFW_BINARY_DIR}/src") 139target_link_libraries(glfw PRIVATE Threads::Threads) 140 141if (GLFW_BUILD_WIN32) 142 list(APPEND glfw_PKG_LIBS "-lgdi32") 143endif() 144 145if (GLFW_BUILD_COCOA) 146 target_link_libraries(glfw PRIVATE "-framework Cocoa" 147 "-framework IOKit" 148 "-framework CoreFoundation" 149 "-framework QuartzCore") 150 151 set(glfw_PKG_DEPS "") 152 set(glfw_PKG_LIBS "-framework Cocoa -framework IOKit -framework CoreFoundation -framework QuartzCore") 153endif() 154 155if (GLFW_BUILD_WAYLAND) 156 include(FindPkgConfig) 157 158 pkg_check_modules(Wayland REQUIRED 159 wayland-client>=0.2.7 160 wayland-cursor>=0.2.7 161 wayland-egl>=0.2.7 162 xkbcommon>=0.5.0) 163 164 target_include_directories(glfw PRIVATE ${Wayland_INCLUDE_DIRS}) 165 166 if (NOT CMAKE_SYSTEM_NAME STREQUAL "Linux") 167 find_package(EpollShim) 168 if (EPOLLSHIM_FOUND) 169 target_include_directories(glfw PRIVATE ${EPOLLSHIM_INCLUDE_DIRS}) 170 target_link_libraries(glfw PRIVATE ${EPOLLSHIM_LIBRARIES}) 171 endif() 172 endif() 173endif() 174 175if (GLFW_BUILD_X11) 176 find_package(X11 REQUIRED) 177 target_include_directories(glfw PRIVATE "${X11_X11_INCLUDE_PATH}") 178 179 # Check for XRandR (modern resolution switching and gamma control) 180 if (NOT X11_Xrandr_INCLUDE_PATH) 181 message(FATAL_ERROR "RandR headers not found; install libxrandr development package") 182 endif() 183 target_include_directories(glfw PRIVATE "${X11_Xrandr_INCLUDE_PATH}") 184 185 # Check for Xinerama (legacy multi-monitor support) 186 if (NOT X11_Xinerama_INCLUDE_PATH) 187 message(FATAL_ERROR "Xinerama headers not found; install libxinerama development package") 188 endif() 189 target_include_directories(glfw PRIVATE "${X11_Xinerama_INCLUDE_PATH}") 190 191 # Check for Xkb (X keyboard extension) 192 if (NOT X11_Xkb_INCLUDE_PATH) 193 message(FATAL_ERROR "XKB headers not found; install X11 development package") 194 endif() 195 target_include_directories(glfw PRIVATE "${X11_Xkb_INCLUDE_PATH}") 196 197 # Check for Xcursor (cursor creation from RGBA images) 198 if (NOT X11_Xcursor_INCLUDE_PATH) 199 message(FATAL_ERROR "Xcursor headers not found; install libxcursor development package") 200 endif() 201 target_include_directories(glfw PRIVATE "${X11_Xcursor_INCLUDE_PATH}") 202 203 # Check for XInput (modern HID input) 204 if (NOT X11_Xi_INCLUDE_PATH) 205 message(FATAL_ERROR "XInput headers not found; install libxi development package") 206 endif() 207 target_include_directories(glfw PRIVATE "${X11_Xi_INCLUDE_PATH}") 208 209 # Check for X Shape (custom window input shape) 210 if (NOT X11_Xshape_INCLUDE_PATH) 211 message(FATAL_ERROR "X Shape headers not found; install libxext development package") 212 endif() 213 target_include_directories(glfw PRIVATE "${X11_Xshape_INCLUDE_PATH}") 214endif() 215 216if (UNIX AND NOT APPLE) 217 find_library(RT_LIBRARY rt) 218 mark_as_advanced(RT_LIBRARY) 219 if (RT_LIBRARY) 220 target_link_libraries(glfw PRIVATE "${RT_LIBRARY}") 221 list(APPEND glfw_PKG_LIBS "-lrt") 222 endif() 223 224 find_library(MATH_LIBRARY m) 225 mark_as_advanced(MATH_LIBRARY) 226 if (MATH_LIBRARY) 227 target_link_libraries(glfw PRIVATE "${MATH_LIBRARY}") 228 list(APPEND glfw_PKG_LIBS "-lm") 229 endif() 230 231 if (CMAKE_DL_LIBS) 232 target_link_libraries(glfw PRIVATE "${CMAKE_DL_LIBS}") 233 list(APPEND glfw_PKG_LIBS "-l${CMAKE_DL_LIBS}") 234 endif() 235endif() 236 237if (WIN32) 238 if (GLFW_USE_HYBRID_HPG) 239 target_compile_definitions(glfw PRIVATE _GLFW_USE_HYBRID_HPG) 240 endif() 241endif() 242 243# Enable a reasonable set of warnings 244# NOTE: The order matters here, Clang-CL matches both MSVC and Clang 245if (MSVC) 246 target_compile_options(glfw PRIVATE "/W3") 247elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR 248 CMAKE_C_COMPILER_ID STREQUAL "Clang" OR 249 CMAKE_C_COMPILER_ID STREQUAL "AppleClang") 250 251 target_compile_options(glfw PRIVATE "-Wall") 252endif() 253 254if (GLFW_BUILD_WIN32) 255 target_compile_definitions(glfw PRIVATE UNICODE _UNICODE) 256endif() 257 258# Workaround for the MS CRT deprecating parts of the standard library 259if (MSVC OR CMAKE_C_SIMULATE_ID STREQUAL "MSVC") 260 target_compile_definitions(glfw PRIVATE _CRT_SECURE_NO_WARNINGS) 261endif() 262 263# Workaround for -std=c99 on Linux disabling _DEFAULT_SOURCE (POSIX 2008 and more) 264if (CMAKE_SYSTEM_NAME STREQUAL "Linux") 265 target_compile_definitions(glfw PRIVATE _DEFAULT_SOURCE) 266endif() 267 268if (GLFW_BUILD_SHARED_LIBRARY) 269 if (WIN32) 270 if (MINGW) 271 # Remove the lib prefix on the DLL (but not the import library) 272 set_target_properties(glfw PROPERTIES PREFIX "") 273 274 # Add a suffix to the import library to avoid naming conflicts 275 set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.a") 276 else() 277 # Add a suffix to the import library to avoid naming conflicts 278 set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.lib") 279 endif() 280 set (GLFW_LIB_NAME_SUFFIX "dll") 281 282 target_compile_definitions(glfw INTERFACE GLFW_DLL) 283 endif() 284 285 if (MINGW) 286 # Enable link-time exploit mitigation features enabled by default on MSVC 287 include(CheckCCompilerFlag) 288 include(CMakePushCheckState) 289 290 # Compatibility with data execution prevention (DEP) 291 cmake_push_check_state() 292 set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat") 293 check_c_compiler_flag("" _GLFW_HAS_DEP) 294 if (_GLFW_HAS_DEP) 295 target_link_libraries(glfw PRIVATE "-Wl,--nxcompat") 296 endif() 297 cmake_pop_check_state() 298 299 # Compatibility with address space layout randomization (ASLR) 300 cmake_push_check_state() 301 set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase") 302 check_c_compiler_flag("" _GLFW_HAS_ASLR) 303 if (_GLFW_HAS_ASLR) 304 target_link_libraries(glfw PRIVATE "-Wl,--dynamicbase") 305 endif() 306 cmake_pop_check_state() 307 308 # Compatibility with 64-bit address space layout randomization (ASLR) 309 cmake_push_check_state() 310 set(CMAKE_REQUIRED_FLAGS "-Wl,--high-entropy-va") 311 check_c_compiler_flag("" _GLFW_HAS_64ASLR) 312 if (_GLFW_HAS_64ASLR) 313 target_link_libraries(glfw PRIVATE "-Wl,--high-entropy-va") 314 endif() 315 cmake_pop_check_state() 316 endif() 317 318 if (UNIX) 319 # Hide symbols not explicitly tagged for export from the shared library 320 target_compile_options(glfw PRIVATE "-fvisibility=hidden") 321 endif() 322endif() 323 324list(JOIN glfw_PKG_DEPS " " deps) 325list(JOIN glfw_PKG_LIBS " " libs) 326 327set(GLFW_PKG_CONFIG_REQUIRES_PRIVATE "${deps}" CACHE INTERNAL 328 "GLFW pkg-config Requires.private") 329set(GLFW_PKG_CONFIG_LIBS_PRIVATE "${libs}" CACHE INTERNAL 330 "GLFW pkg-config Libs.private") 331 332configure_file("${GLFW_SOURCE_DIR}/CMake/glfw3.pc.in" glfw3.pc @ONLY) 333 334if (GLFW_INSTALL) 335 install(TARGETS glfw 336 EXPORT glfwTargets 337 RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" 338 ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" 339 LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") 340endif() 341 342[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.