CMakeLists.txt 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. cmake_minimum_required(VERSION 3.16...3.28 FATAL_ERROR)
  2. project(GLFW VERSION 3.5.0 LANGUAGES C HOMEPAGE_URL "https://www.glfw.org/")
  3. set_property(GLOBAL PROPERTY USE_FOLDERS ON)
  4. string(COMPARE EQUAL "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}" GLFW_STANDALONE)
  5. option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
  6. option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" ${GLFW_STANDALONE})
  7. option(GLFW_BUILD_TESTS "Build the GLFW test programs" ${GLFW_STANDALONE})
  8. option(GLFW_BUILD_DOCS "Build the GLFW documentation" ON)
  9. option(GLFW_INSTALL "Generate installation target" ON)
  10. include(GNUInstallDirs)
  11. include(CMakeDependentOption)
  12. if (GLFW_USE_OSMESA)
  13. message(FATAL_ERROR "GLFW_USE_OSMESA has been removed; set the GLFW_PLATFORM init hint")
  14. endif()
  15. if (DEFINED GLFW_USE_WAYLAND AND UNIX AND NOT APPLE)
  16. message(FATAL_ERROR
  17. "GLFW_USE_WAYLAND has been removed; delete the CMake cache and set GLFW_BUILD_WAYLAND and GLFW_BUILD_X11 instead")
  18. endif()
  19. cmake_dependent_option(GLFW_BUILD_WIN32 "Build support for Win32" ON "WIN32" OFF)
  20. cmake_dependent_option(GLFW_BUILD_COCOA "Build support for Cocoa" ON "APPLE" OFF)
  21. cmake_dependent_option(GLFW_BUILD_X11 "Build support for X11" ON "UNIX;NOT APPLE" OFF)
  22. cmake_dependent_option(GLFW_BUILD_WAYLAND "Build support for Wayland" ON "UNIX;NOT APPLE" OFF)
  23. cmake_dependent_option(GLFW_USE_HYBRID_HPG "Force use of high-performance GPU on hybrid systems" OFF
  24. "WIN32" OFF)
  25. cmake_dependent_option(USE_MSVC_RUNTIME_LIBRARY_DLL "Use MSVC runtime library DLL" ON
  26. "MSVC" OFF)
  27. set(GLFW_LIBRARY_TYPE "${GLFW_LIBRARY_TYPE}" CACHE STRING
  28. "Library type override for GLFW (SHARED, STATIC, OBJECT, or empty to follow BUILD_SHARED_LIBS)")
  29. if (GLFW_LIBRARY_TYPE)
  30. string(COMPARE EQUAL "${GLFW_LIBRARY_TYPE}" "SHARED" GLFW_BUILD_SHARED_LIBRARY)
  31. else()
  32. set(GLFW_BUILD_SHARED_LIBRARY ${BUILD_SHARED_LIBS})
  33. endif()
  34. list(APPEND CMAKE_MODULE_PATH "${GLFW_SOURCE_DIR}/CMake/modules")
  35. find_package(Threads REQUIRED)
  36. #--------------------------------------------------------------------
  37. # Report backend selection
  38. #--------------------------------------------------------------------
  39. if (GLFW_BUILD_WIN32)
  40. message(STATUS "Including Win32 support")
  41. endif()
  42. if (GLFW_BUILD_COCOA)
  43. message(STATUS "Including Cocoa support")
  44. endif()
  45. if (GLFW_BUILD_WAYLAND)
  46. message(STATUS "Including Wayland support")
  47. endif()
  48. if (GLFW_BUILD_X11)
  49. message(STATUS "Including X11 support")
  50. endif()
  51. #--------------------------------------------------------------------
  52. # Apply Microsoft C runtime library option
  53. # This is here because it also applies to tests and examples
  54. #--------------------------------------------------------------------
  55. if (MSVC AND NOT USE_MSVC_RUNTIME_LIBRARY_DLL)
  56. set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
  57. endif()
  58. #--------------------------------------------------------------------
  59. # Create generated files
  60. #--------------------------------------------------------------------
  61. include(CMakePackageConfigHelpers)
  62. set(GLFW_CONFIG_PATH "${CMAKE_INSTALL_LIBDIR}/cmake/glfw3")
  63. configure_package_config_file(CMake/glfw3Config.cmake.in
  64. src/glfw3Config.cmake
  65. INSTALL_DESTINATION "${GLFW_CONFIG_PATH}"
  66. NO_CHECK_REQUIRED_COMPONENTS_MACRO)
  67. write_basic_package_version_file(src/glfw3ConfigVersion.cmake
  68. VERSION ${GLFW_VERSION}
  69. COMPATIBILITY SameMajorVersion)
  70. #--------------------------------------------------------------------
  71. # Add subdirectories
  72. #--------------------------------------------------------------------
  73. add_subdirectory(src)
  74. if (GLFW_BUILD_EXAMPLES)
  75. add_subdirectory(examples)
  76. endif()
  77. if (GLFW_BUILD_TESTS)
  78. add_subdirectory(tests)
  79. endif()
  80. if (GLFW_BUILD_DOCS)
  81. add_subdirectory(docs)
  82. endif()
  83. #--------------------------------------------------------------------
  84. # Install files other than the library
  85. # The library is installed by src/CMakeLists.txt
  86. #--------------------------------------------------------------------
  87. if (GLFW_INSTALL)
  88. install(DIRECTORY include/GLFW DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  89. FILES_MATCHING PATTERN glfw3.h PATTERN glfw3native.h)
  90. install(FILES "${GLFW_BINARY_DIR}/src/glfw3Config.cmake"
  91. "${GLFW_BINARY_DIR}/src/glfw3ConfigVersion.cmake"
  92. DESTINATION "${GLFW_CONFIG_PATH}")
  93. install(EXPORT glfwTargets FILE glfw3Targets.cmake
  94. EXPORT_LINK_INTERFACE_LIBRARIES
  95. DESTINATION "${GLFW_CONFIG_PATH}")
  96. install(FILES "${GLFW_BINARY_DIR}/src/glfw3.pc"
  97. DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
  98. # Only generate this target if no higher-level project already has
  99. if (NOT TARGET uninstall)
  100. configure_file(CMake/cmake_uninstall.cmake.in
  101. cmake_uninstall.cmake IMMEDIATE @ONLY)
  102. add_custom_target(uninstall
  103. "${CMAKE_COMMAND}" -P
  104. "${GLFW_BINARY_DIR}/cmake_uninstall.cmake")
  105. set_target_properties(uninstall PROPERTIES FOLDER "GLFW3")
  106. endif()
  107. endif()