github.com/Konstantin8105/c4go@v0.0.0-20240505174241-768bb1c65a51/tests/raylib/external/glfw/src/CMakeLists.txt (about)

     1  
     2  add_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
    12  if (APPLE)
    13      target_sources(glfw PRIVATE cocoa_time.h cocoa_time.c posix_thread.h
    14                                  posix_module.c posix_thread.c)
    15  elseif (WIN32)
    16      target_sources(glfw PRIVATE win32_time.h win32_thread.h win32_module.c
    17                                  win32_time.c win32_thread.c)
    18  else()
    19      target_sources(glfw PRIVATE posix_time.h posix_thread.h posix_module.c
    20                                  posix_time.c posix_thread.c)
    21  endif()
    22  
    23  add_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  
    30  set_target_properties(update_mappings PROPERTIES FOLDER "GLFW3")
    31  
    32  if (GLFW_BUILD_COCOA)
    33      target_compile_definitions(glfw PRIVATE _GLFW_COCOA)
    34      target_sources(glfw PRIVATE cocoa_platform.h cocoa_joystick.h cocoa_init.m
    35                                  cocoa_joystick.m cocoa_monitor.m cocoa_window.m
    36                                  nsgl_context.m)
    37  endif()
    38  
    39  if (GLFW_BUILD_WIN32)
    40      target_compile_definitions(glfw PRIVATE _GLFW_WIN32)
    41      target_sources(glfw PRIVATE win32_platform.h win32_joystick.h win32_init.c
    42                                  win32_joystick.c win32_monitor.c win32_window.c
    43                                  wgl_context.c)
    44  endif()
    45  
    46  if (GLFW_BUILD_X11)
    47      target_compile_definitions(glfw PRIVATE _GLFW_X11)
    48      target_sources(glfw PRIVATE x11_platform.h xkb_unicode.h x11_init.c
    49                                  x11_monitor.c x11_window.c xkb_unicode.c
    50                                  glx_context.c)
    51  endif()
    52  
    53  if (GLFW_BUILD_WAYLAND)
    54      target_compile_definitions(glfw PRIVATE _GLFW_WAYLAND)
    55      target_sources(glfw PRIVATE wl_platform.h xkb_unicode.h wl_init.c
    56                                  wl_monitor.c wl_window.c xkb_unicode.c)
    57  endif()
    58  
    59  if (GLFW_BUILD_X11 OR GLFW_BUILD_WAYLAND)
    60      if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
    61          target_sources(glfw PRIVATE linux_joystick.h linux_joystick.c)
    62      endif()
    63      target_sources(glfw PRIVATE posix_poll.h posix_poll.c)
    64  endif()
    65  
    66  if (GLFW_BUILD_WAYLAND)
    67      include(CheckIncludeFiles)
    68      include(CheckFunctionExists)
    69      check_function_exists(memfd_create HAVE_MEMFD_CREATE)
    70      if (HAVE_MEMFD_CREATE)
    71          target_compile_definitions(glfw PRIVATE HAVE_MEMFD_CREATE)
    72      endif()
    73  
    74      find_program(WAYLAND_SCANNER_EXECUTABLE NAMES wayland-scanner)
    75  
    76      include(FindPkgConfig)
    77      pkg_check_modules(WAYLAND_PROTOCOLS REQUIRED wayland-protocols>=1.15)
    78      pkg_get_variable(WAYLAND_PROTOCOLS_BASE wayland-protocols pkgdatadir)
    79      pkg_get_variable(WAYLAND_CLIENT_PKGDATADIR wayland-client pkgdatadir)
    80  
    81      macro(wayland_generate protocol_file output_file)
    82          add_custom_command(OUTPUT "${output_file}.h"
    83              COMMAND "${WAYLAND_SCANNER_EXECUTABLE}" client-header "${protocol_file}" "${output_file}.h"
    84              DEPENDS "${protocol_file}"
    85              VERBATIM)
    86  
    87          add_custom_command(OUTPUT "${output_file}-code.h"
    88              COMMAND "${WAYLAND_SCANNER_EXECUTABLE}" private-code "${protocol_file}" "${output_file}-code.h"
    89              DEPENDS "${protocol_file}"
    90              VERBATIM)
    91  
    92          target_sources(glfw PRIVATE "${output_file}.h" "${output_file}-code.h")
    93      endmacro()
    94  
    95      wayland_generate(
    96          "${WAYLAND_CLIENT_PKGDATADIR}/wayland.xml"
    97          "${GLFW_BINARY_DIR}/src/wayland-client-protocol")
    98      wayland_generate(
    99          "${WAYLAND_PROTOCOLS_BASE}/stable/xdg-shell/xdg-shell.xml"
   100          "${GLFW_BINARY_DIR}/src/wayland-xdg-shell-client-protocol")
   101      wayland_generate(
   102          "${WAYLAND_PROTOCOLS_BASE}/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml"
   103          "${GLFW_BINARY_DIR}/src/wayland-xdg-decoration-client-protocol")
   104      wayland_generate(
   105          "${WAYLAND_PROTOCOLS_BASE}/stable/viewporter/viewporter.xml"
   106          "${GLFW_BINARY_DIR}/src/wayland-viewporter-client-protocol")
   107      wayland_generate(
   108          "${WAYLAND_PROTOCOLS_BASE}/unstable/relative-pointer/relative-pointer-unstable-v1.xml"
   109          "${GLFW_BINARY_DIR}/src/wayland-relative-pointer-unstable-v1-client-protocol")
   110      wayland_generate(
   111          "${WAYLAND_PROTOCOLS_BASE}/unstable/pointer-constraints/pointer-constraints-unstable-v1.xml"
   112          "${GLFW_BINARY_DIR}/src/wayland-pointer-constraints-unstable-v1-client-protocol")
   113      wayland_generate(
   114          "${WAYLAND_PROTOCOLS_BASE}/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml"
   115          "${GLFW_BINARY_DIR}/src/wayland-idle-inhibit-unstable-v1-client-protocol")
   116  endif()
   117  
   118  if (WIN32 AND GLFW_BUILD_SHARED_LIBRARY)
   119      configure_file(glfw.rc.in glfw.rc @ONLY)
   120      target_sources(glfw PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/glfw.rc")
   121  endif()
   122  
   123  if (UNIX AND GLFW_BUILD_SHARED_LIBRARY)
   124      # On Unix-like systems, shared libraries can use the soname system.
   125      set(GLFW_LIB_NAME glfw)
   126  else()
   127      set(GLFW_LIB_NAME glfw3)
   128  endif()
   129  
   130  set_target_properties(glfw PROPERTIES
   131                        OUTPUT_NAME ${GLFW_LIB_NAME}
   132                        VERSION ${GLFW_VERSION_MAJOR}.${GLFW_VERSION_MINOR}
   133                        SOVERSION ${GLFW_VERSION_MAJOR}
   134                        POSITION_INDEPENDENT_CODE ON
   135                        C_STANDARD 99
   136                        C_EXTENSIONS OFF
   137                        DEFINE_SYMBOL _GLFW_BUILD_DLL
   138                        FOLDER "GLFW3")
   139  
   140  target_include_directories(glfw PUBLIC
   141                             "$<BUILD_INTERFACE:${GLFW_SOURCE_DIR}/include>"
   142                             "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
   143  target_include_directories(glfw PRIVATE
   144                             "${GLFW_SOURCE_DIR}/src"
   145                             "${GLFW_BINARY_DIR}/src")
   146  target_link_libraries(glfw PRIVATE Threads::Threads)
   147  
   148  # Workaround for CMake not knowing about .m files before version 3.16
   149  if (CMAKE_VERSION VERSION_LESS "3.16" AND APPLE)
   150      set_source_files_properties(cocoa_init.m cocoa_joystick.m cocoa_monitor.m
   151                                  cocoa_window.m nsgl_context.m PROPERTIES
   152                                  LANGUAGE C)
   153  endif()
   154  
   155  if (GLFW_BUILD_WIN32)
   156      list(APPEND glfw_PKG_LIBS "-lgdi32")
   157  endif()
   158  
   159  if (GLFW_BUILD_COCOA)
   160      target_link_libraries(glfw PRIVATE "-framework Cocoa"
   161                                         "-framework IOKit"
   162                                         "-framework CoreFoundation")
   163  
   164      set(glfw_PKG_DEPS "")
   165      set(glfw_PKG_LIBS "-framework Cocoa -framework IOKit -framework CoreFoundation")
   166  endif()
   167  
   168  if (GLFW_BUILD_WAYLAND)
   169      pkg_check_modules(Wayland REQUIRED
   170          wayland-client>=0.2.7
   171          wayland-cursor>=0.2.7
   172          wayland-egl>=0.2.7
   173          xkbcommon>=0.5.0)
   174  
   175      target_include_directories(glfw PRIVATE ${Wayland_INCLUDE_DIRS})
   176  
   177      if (NOT CMAKE_SYSTEM_NAME STREQUAL "Linux")
   178          find_package(EpollShim)
   179          if (EPOLLSHIM_FOUND)
   180              target_include_directories(glfw PRIVATE ${EPOLLSHIM_INCLUDE_DIRS})
   181              target_link_libraries(glfw PRIVATE ${EPOLLSHIM_LIBRARIES})
   182          endif()
   183      endif()
   184  endif()
   185  
   186  if (GLFW_BUILD_X11)
   187      find_package(X11 REQUIRED)
   188      target_include_directories(glfw PRIVATE "${X11_X11_INCLUDE_PATH}")
   189  
   190      # Check for XRandR (modern resolution switching and gamma control)
   191      if (NOT X11_Xrandr_INCLUDE_PATH)
   192          message(FATAL_ERROR "RandR headers not found; install libxrandr development package")
   193      endif()
   194      target_include_directories(glfw PRIVATE "${X11_Xrandr_INCLUDE_PATH}")
   195  
   196      # Check for Xinerama (legacy multi-monitor support)
   197      if (NOT X11_Xinerama_INCLUDE_PATH)
   198          message(FATAL_ERROR "Xinerama headers not found; install libxinerama development package")
   199      endif()
   200      target_include_directories(glfw PRIVATE "${X11_Xinerama_INCLUDE_PATH}")
   201  
   202      # Check for Xkb (X keyboard extension)
   203      if (NOT X11_Xkb_INCLUDE_PATH)
   204          message(FATAL_ERROR "XKB headers not found; install X11 development package")
   205      endif()
   206      target_include_directories(glfw PRIVATE "${X11_Xkb_INCLUDE_PATH}")
   207  
   208      # Check for Xcursor (cursor creation from RGBA images)
   209      if (NOT X11_Xcursor_INCLUDE_PATH)
   210          message(FATAL_ERROR "Xcursor headers not found; install libxcursor development package")
   211      endif()
   212      target_include_directories(glfw PRIVATE "${X11_Xcursor_INCLUDE_PATH}")
   213  
   214      # Check for XInput (modern HID input)
   215      if (NOT X11_Xi_INCLUDE_PATH)
   216          message(FATAL_ERROR "XInput headers not found; install libxi development package")
   217      endif()
   218      target_include_directories(glfw PRIVATE "${X11_Xi_INCLUDE_PATH}")
   219  
   220      # Check for X Shape (custom window input shape)
   221      if (NOT X11_Xshape_INCLUDE_PATH)
   222          message(FATAL_ERROR "X Shape headers not found; install libxext development package")
   223      endif()
   224      target_include_directories(glfw PRIVATE "${X11_Xshape_INCLUDE_PATH}")
   225  endif()
   226  
   227  if (UNIX AND NOT APPLE)
   228      find_library(RT_LIBRARY rt)
   229      mark_as_advanced(RT_LIBRARY)
   230      if (RT_LIBRARY)
   231          target_link_libraries(glfw PRIVATE "${RT_LIBRARY}")
   232          list(APPEND glfw_PKG_LIBS "-lrt")
   233      endif()
   234  
   235      find_library(MATH_LIBRARY m)
   236      mark_as_advanced(MATH_LIBRARY)
   237      if (MATH_LIBRARY)
   238          target_link_libraries(glfw PRIVATE "${MATH_LIBRARY}")
   239          list(APPEND glfw_PKG_LIBS "-lm")
   240      endif()
   241  
   242      if (CMAKE_DL_LIBS)
   243          target_link_libraries(glfw PRIVATE "${CMAKE_DL_LIBS}")
   244          list(APPEND glfw_PKG_LIBS "-l${CMAKE_DL_LIBS}")
   245      endif()
   246  endif()
   247  
   248  # Make GCC warn about declarations that VS 2010 and 2012 won't accept for all
   249  # source files that VS will build (Clang ignores this because we set -std=c99)
   250  if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
   251      set_source_files_properties(context.c init.c input.c monitor.c platform.c vulkan.c
   252                                  window.c null_init.c null_joystick.c null_monitor.c
   253                                  null_window.c win32_init.c win32_joystick.c win32_module.c
   254                                  win32_monitor.c win32_time.c win32_thread.c win32_window.c
   255                                  wgl_context.c egl_context.c osmesa_context.c PROPERTIES
   256                                  COMPILE_FLAGS -Wdeclaration-after-statement)
   257  endif()
   258  
   259  if (WIN32)
   260      if (GLFW_USE_HYBRID_HPG)
   261          target_compile_definitions(glfw PRIVATE _GLFW_USE_HYBRID_HPG)
   262      endif()
   263  endif()
   264  
   265  # Enable a reasonable set of warnings
   266  # NOTE: The order matters here, Clang-CL matches both MSVC and Clang
   267  if (MSVC)
   268      target_compile_options(glfw PRIVATE "/W3")
   269  elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR
   270          CMAKE_C_COMPILER_ID STREQUAL "Clang" OR
   271          CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
   272  
   273      target_compile_options(glfw PRIVATE "-Wall")
   274  endif()
   275  
   276  if (GLFW_BUILD_WIN32)
   277      target_compile_definitions(glfw PRIVATE UNICODE _UNICODE)
   278  endif()
   279  
   280  # HACK: When building on MinGW, WINVER and UNICODE need to be defined before
   281  # the inclusion of stddef.h (by glfw3.h), which is itself included before
   282  # win32_platform.h.  We define them here until a saner solution can be found
   283  # NOTE: MinGW-w64 and Visual C++ do /not/ need this hack.
   284  if (MINGW)
   285      target_compile_definitions(glfw PRIVATE WINVER=0x0501)
   286  endif()
   287  
   288  # Workaround for legacy MinGW not providing XInput and DirectInput
   289  if (MINGW)
   290      include(CheckIncludeFile)
   291      check_include_file(dinput.h DINPUT_H_FOUND)
   292      check_include_file(xinput.h XINPUT_H_FOUND)
   293      if (NOT DINPUT_H_FOUND OR NOT XINPUT_H_FOUND)
   294          target_include_directories(glfw PRIVATE "${GLFW_SOURCE_DIR}/deps/mingw")
   295      endif()
   296  endif()
   297  
   298  # Workaround for the MS CRT deprecating parts of the standard library
   299  if (MSVC OR CMAKE_C_SIMULATE_ID STREQUAL "MSVC")
   300      target_compile_definitions(glfw PRIVATE _CRT_SECURE_NO_WARNINGS)
   301  endif()
   302  
   303  # Workaround for VS 2008 not shipping with stdint.h
   304  if (MSVC90)
   305      target_include_directories(glfw PUBLIC "${GLFW_SOURCE_DIR}/deps/vs2008")
   306  endif()
   307  
   308  # Check for the DirectX 9 SDK as it is not included with VS 2008
   309  if (MSVC90)
   310      include(CheckIncludeFile)
   311      check_include_file(dinput.h DINPUT_H_FOUND)
   312      if (NOT DINPUT_H_FOUND)
   313          message(FATAL_ERROR "DirectX 9 headers not found; install DirectX 9 SDK")
   314      endif()
   315  endif()
   316  
   317  # Workaround for -std=c99 on Linux disabling _DEFAULT_SOURCE (POSIX 2008 and more)
   318  if (GLFW_BUILD_X11 OR GLFW_BUILD_WAYLAND)
   319      if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
   320          target_compile_definitions(glfw PRIVATE _DEFAULT_SOURCE)
   321      endif()
   322  endif()
   323  
   324  if (GLFW_BUILD_SHARED_LIBRARY)
   325      if (WIN32)
   326          if (MINGW)
   327              # Remove the dependency on the shared version of libgcc
   328              # NOTE: MinGW-w64 has the correct default but MinGW needs this
   329              target_link_libraries(glfw PRIVATE "-static-libgcc")
   330  
   331              # Remove the lib prefix on the DLL (but not the import library)
   332              set_target_properties(glfw PROPERTIES PREFIX "")
   333  
   334              # Add a suffix to the import library to avoid naming conflicts
   335              set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.a")
   336          else()
   337              # Add a suffix to the import library to avoid naming conflicts
   338              set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.lib")
   339          endif()
   340  
   341          target_compile_definitions(glfw INTERFACE GLFW_DLL)
   342      endif()
   343  
   344      if (MINGW)
   345          # Enable link-time exploit mitigation features enabled by default on MSVC
   346          include(CheckCCompilerFlag)
   347  
   348          # Compatibility with data execution prevention (DEP)
   349          set(CMAKE_REQUIRED_FLAGS "-Wl,--nxcompat")
   350          check_c_compiler_flag("" _GLFW_HAS_DEP)
   351          if (_GLFW_HAS_DEP)
   352              target_link_libraries(glfw PRIVATE "-Wl,--nxcompat")
   353          endif()
   354  
   355          # Compatibility with address space layout randomization (ASLR)
   356          set(CMAKE_REQUIRED_FLAGS "-Wl,--dynamicbase")
   357          check_c_compiler_flag("" _GLFW_HAS_ASLR)
   358          if (_GLFW_HAS_ASLR)
   359              target_link_libraries(glfw PRIVATE "-Wl,--dynamicbase")
   360          endif()
   361  
   362          # Compatibility with 64-bit address space layout randomization (ASLR)
   363          set(CMAKE_REQUIRED_FLAGS "-Wl,--high-entropy-va")
   364          check_c_compiler_flag("" _GLFW_HAS_64ASLR)
   365          if (_GLFW_HAS_64ASLR)
   366              target_link_libraries(glfw PRIVATE "-Wl,--high-entropy-va")
   367          endif()
   368  
   369          # Clear flags again to avoid breaking later tests
   370          set(CMAKE_REQUIRED_FLAGS)
   371      endif()
   372  
   373      if (UNIX)
   374          # Hide symbols not explicitly tagged for export from the shared library
   375          target_compile_options(glfw PRIVATE "-fvisibility=hidden")
   376      endif()
   377  endif()
   378  
   379  foreach(arg ${glfw_PKG_DEPS})
   380      string(APPEND deps " ${arg}")
   381  endforeach()
   382  foreach(arg ${glfw_PKG_LIBS})
   383      string(APPEND libs " ${arg}")
   384  endforeach()
   385  
   386  set(GLFW_PKG_CONFIG_REQUIRES_PRIVATE "${deps}" CACHE INTERNAL
   387      "GLFW pkg-config Requires.private")
   388  set(GLFW_PKG_CONFIG_LIBS_PRIVATE "${libs}" CACHE INTERNAL
   389      "GLFW pkg-config Libs.private")
   390  
   391  configure_file("${GLFW_SOURCE_DIR}/CMake/glfw3.pc.in" glfw3.pc @ONLY)
   392  
   393  if (GLFW_INSTALL)
   394      install(TARGETS glfw
   395              EXPORT glfwTargets
   396              RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
   397              ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
   398              LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
   399  endif()
   400