1b877906bSopenharmony_cicmake_minimum_required(VERSION 3.4...3.28 FATAL_ERROR)
2b877906bSopenharmony_ci
3b877906bSopenharmony_ciproject(GLFW VERSION 3.5.0 LANGUAGES C)
4b877906bSopenharmony_ci
5b877906bSopenharmony_ciif (POLICY CMP0069)
6b877906bSopenharmony_ci    cmake_policy(SET CMP0069 NEW)
7b877906bSopenharmony_ciendif()
8b877906bSopenharmony_ci
9b877906bSopenharmony_ciif (POLICY CMP0077)
10b877906bSopenharmony_ci    cmake_policy(SET CMP0077 NEW)
11b877906bSopenharmony_ciendif()
12b877906bSopenharmony_ci
13b877906bSopenharmony_ciset_property(GLOBAL PROPERTY USE_FOLDERS ON)
14b877906bSopenharmony_ci
15b877906bSopenharmony_cistring(COMPARE EQUAL "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}" GLFW_STANDALONE)
16b877906bSopenharmony_ci
17b877906bSopenharmony_cioption(BUILD_SHARED_LIBS "Build shared libraries" OFF)
18b877906bSopenharmony_cioption(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" ${GLFW_STANDALONE})
19b877906bSopenharmony_cioption(GLFW_BUILD_TESTS "Build the GLFW test programs" ${GLFW_STANDALONE})
20b877906bSopenharmony_cioption(GLFW_BUILD_DOCS "Build the GLFW documentation" ON)
21b877906bSopenharmony_cioption(GLFW_INSTALL "Generate installation target" ON)
22b877906bSopenharmony_ci
23b877906bSopenharmony_ciinclude(GNUInstallDirs)
24b877906bSopenharmony_ciinclude(CMakeDependentOption)
25b877906bSopenharmony_ci
26b877906bSopenharmony_ciif (GLFW_USE_OSMESA)
27b877906bSopenharmony_ci    message(FATAL_ERROR "GLFW_USE_OSMESA has been removed; set the GLFW_PLATFORM init hint")
28b877906bSopenharmony_ciendif()
29b877906bSopenharmony_ci
30b877906bSopenharmony_ciif (DEFINED GLFW_USE_WAYLAND AND UNIX AND NOT APPLE)
31b877906bSopenharmony_ci    message(FATAL_ERROR
32b877906bSopenharmony_ci        "GLFW_USE_WAYLAND has been removed; delete the CMake cache and set GLFW_BUILD_WAYLAND and GLFW_BUILD_X11 instead")
33b877906bSopenharmony_ciendif()
34b877906bSopenharmony_ci
35b877906bSopenharmony_cicmake_dependent_option(GLFW_BUILD_WIN32 "Build support for Win32" ON "WIN32" OFF)
36b877906bSopenharmony_cicmake_dependent_option(GLFW_BUILD_COCOA "Build support for Cocoa" ON "APPLE" OFF)
37b877906bSopenharmony_cicmake_dependent_option(GLFW_BUILD_X11 "Build support for X11" ON "UNIX;NOT APPLE" OFF)
38b877906bSopenharmony_cicmake_dependent_option(GLFW_BUILD_WAYLAND "Build support for Wayland" ON "UNIX;NOT APPLE" OFF)
39b877906bSopenharmony_ci
40b877906bSopenharmony_cicmake_dependent_option(GLFW_USE_HYBRID_HPG "Force use of high-performance GPU on hybrid systems" OFF
41b877906bSopenharmony_ci                       "WIN32" OFF)
42b877906bSopenharmony_cicmake_dependent_option(USE_MSVC_RUNTIME_LIBRARY_DLL "Use MSVC runtime library DLL" ON
43b877906bSopenharmony_ci                       "MSVC" OFF)
44b877906bSopenharmony_ci
45b877906bSopenharmony_ciset(GLFW_LIBRARY_TYPE "${GLFW_LIBRARY_TYPE}" CACHE STRING
46b877906bSopenharmony_ci    "Library type override for GLFW (SHARED, STATIC, OBJECT, or empty to follow BUILD_SHARED_LIBS)")
47b877906bSopenharmony_ci
48b877906bSopenharmony_ciif (GLFW_LIBRARY_TYPE)
49b877906bSopenharmony_ci    if (GLFW_LIBRARY_TYPE STREQUAL "SHARED")
50b877906bSopenharmony_ci        set(GLFW_BUILD_SHARED_LIBRARY TRUE)
51b877906bSopenharmony_ci    else()
52b877906bSopenharmony_ci        set(GLFW_BUILD_SHARED_LIBRARY FALSE)
53b877906bSopenharmony_ci    endif()
54b877906bSopenharmony_cielse()
55b877906bSopenharmony_ci    set(GLFW_BUILD_SHARED_LIBRARY ${BUILD_SHARED_LIBS})
56b877906bSopenharmony_ciendif()
57b877906bSopenharmony_ci
58b877906bSopenharmony_cilist(APPEND CMAKE_MODULE_PATH "${GLFW_SOURCE_DIR}/CMake/modules")
59b877906bSopenharmony_ci
60b877906bSopenharmony_cifind_package(Threads REQUIRED)
61b877906bSopenharmony_ci
62b877906bSopenharmony_ci#--------------------------------------------------------------------
63b877906bSopenharmony_ci# Report backend selection
64b877906bSopenharmony_ci#--------------------------------------------------------------------
65b877906bSopenharmony_ciif (GLFW_BUILD_WIN32)
66b877906bSopenharmony_ci    message(STATUS "Including Win32 support")
67b877906bSopenharmony_ciendif()
68b877906bSopenharmony_ciif (GLFW_BUILD_COCOA)
69b877906bSopenharmony_ci    message(STATUS "Including Cocoa support")
70b877906bSopenharmony_ciendif()
71b877906bSopenharmony_ciif (GLFW_BUILD_WAYLAND)
72b877906bSopenharmony_ci    message(STATUS "Including Wayland support")
73b877906bSopenharmony_ciendif()
74b877906bSopenharmony_ciif (GLFW_BUILD_X11)
75b877906bSopenharmony_ci    message(STATUS "Including X11 support")
76b877906bSopenharmony_ciendif()
77b877906bSopenharmony_ci
78b877906bSopenharmony_ci#--------------------------------------------------------------------
79b877906bSopenharmony_ci# Apply Microsoft C runtime library option
80b877906bSopenharmony_ci# This is here because it also applies to tests and examples
81b877906bSopenharmony_ci#--------------------------------------------------------------------
82b877906bSopenharmony_ciif (MSVC AND NOT USE_MSVC_RUNTIME_LIBRARY_DLL)
83b877906bSopenharmony_ci    if (CMAKE_VERSION VERSION_LESS 3.15)
84b877906bSopenharmony_ci        foreach (flag CMAKE_C_FLAGS
85b877906bSopenharmony_ci                      CMAKE_C_FLAGS_DEBUG
86b877906bSopenharmony_ci                      CMAKE_C_FLAGS_RELEASE
87b877906bSopenharmony_ci                      CMAKE_C_FLAGS_MINSIZEREL
88b877906bSopenharmony_ci                      CMAKE_C_FLAGS_RELWITHDEBINFO)
89b877906bSopenharmony_ci
90b877906bSopenharmony_ci            if (flag MATCHES "/MD")
91b877906bSopenharmony_ci                string(REGEX REPLACE "/MD" "/MT" ${flag} "${${flag}}")
92b877906bSopenharmony_ci            endif()
93b877906bSopenharmony_ci            if (flag MATCHES "/MDd")
94b877906bSopenharmony_ci                string(REGEX REPLACE "/MDd" "/MTd" ${flag} "${${flag}}")
95b877906bSopenharmony_ci            endif()
96b877906bSopenharmony_ci
97b877906bSopenharmony_ci        endforeach()
98b877906bSopenharmony_ci    else()
99b877906bSopenharmony_ci        set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
100b877906bSopenharmony_ci    endif()
101b877906bSopenharmony_ciendif()
102b877906bSopenharmony_ci
103b877906bSopenharmony_ci#--------------------------------------------------------------------
104b877906bSopenharmony_ci# Create generated files
105b877906bSopenharmony_ci#--------------------------------------------------------------------
106b877906bSopenharmony_ciinclude(CMakePackageConfigHelpers)
107b877906bSopenharmony_ci
108b877906bSopenharmony_ciset(GLFW_CONFIG_PATH "${CMAKE_INSTALL_LIBDIR}/cmake/glfw3")
109b877906bSopenharmony_ci
110b877906bSopenharmony_ciconfigure_package_config_file(CMake/glfw3Config.cmake.in
111b877906bSopenharmony_ci                              src/glfw3Config.cmake
112b877906bSopenharmony_ci                              INSTALL_DESTINATION "${GLFW_CONFIG_PATH}"
113b877906bSopenharmony_ci                              NO_CHECK_REQUIRED_COMPONENTS_MACRO)
114b877906bSopenharmony_ci
115b877906bSopenharmony_ciwrite_basic_package_version_file(src/glfw3ConfigVersion.cmake
116b877906bSopenharmony_ci                                 VERSION ${GLFW_VERSION}
117b877906bSopenharmony_ci                                 COMPATIBILITY SameMajorVersion)
118b877906bSopenharmony_ci
119b877906bSopenharmony_ci#--------------------------------------------------------------------
120b877906bSopenharmony_ci# Add subdirectories
121b877906bSopenharmony_ci#--------------------------------------------------------------------
122b877906bSopenharmony_ciadd_subdirectory(src)
123b877906bSopenharmony_ci
124b877906bSopenharmony_ciif (GLFW_BUILD_EXAMPLES)
125b877906bSopenharmony_ci    add_subdirectory(examples)
126b877906bSopenharmony_ciendif()
127b877906bSopenharmony_ci
128b877906bSopenharmony_ciif (GLFW_BUILD_TESTS)
129b877906bSopenharmony_ci    add_subdirectory(tests)
130b877906bSopenharmony_ciendif()
131b877906bSopenharmony_ci
132b877906bSopenharmony_ciif (GLFW_BUILD_DOCS)
133b877906bSopenharmony_ci    add_subdirectory(docs)
134b877906bSopenharmony_ciendif()
135b877906bSopenharmony_ci
136b877906bSopenharmony_ci#--------------------------------------------------------------------
137b877906bSopenharmony_ci# Install files other than the library
138b877906bSopenharmony_ci# The library is installed by src/CMakeLists.txt
139b877906bSopenharmony_ci#--------------------------------------------------------------------
140b877906bSopenharmony_ciif (GLFW_INSTALL)
141b877906bSopenharmony_ci    install(DIRECTORY include/GLFW DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
142b877906bSopenharmony_ci            FILES_MATCHING PATTERN glfw3.h PATTERN glfw3native.h)
143b877906bSopenharmony_ci
144b877906bSopenharmony_ci    install(FILES "${GLFW_BINARY_DIR}/src/glfw3Config.cmake"
145b877906bSopenharmony_ci                  "${GLFW_BINARY_DIR}/src/glfw3ConfigVersion.cmake"
146b877906bSopenharmony_ci            DESTINATION "${GLFW_CONFIG_PATH}")
147b877906bSopenharmony_ci
148b877906bSopenharmony_ci    install(EXPORT glfwTargets FILE glfw3Targets.cmake
149b877906bSopenharmony_ci            EXPORT_LINK_INTERFACE_LIBRARIES
150b877906bSopenharmony_ci            DESTINATION "${GLFW_CONFIG_PATH}")
151b877906bSopenharmony_ci    install(FILES "${GLFW_BINARY_DIR}/src/glfw3.pc"
152b877906bSopenharmony_ci            DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
153b877906bSopenharmony_ci
154b877906bSopenharmony_ci    # Only generate this target if no higher-level project already has
155b877906bSopenharmony_ci    if (NOT TARGET uninstall)
156b877906bSopenharmony_ci        configure_file(CMake/cmake_uninstall.cmake.in
157b877906bSopenharmony_ci                       cmake_uninstall.cmake IMMEDIATE @ONLY)
158b877906bSopenharmony_ci
159b877906bSopenharmony_ci        add_custom_target(uninstall
160b877906bSopenharmony_ci                          "${CMAKE_COMMAND}" -P
161b877906bSopenharmony_ci                          "${GLFW_BINARY_DIR}/cmake_uninstall.cmake")
162b877906bSopenharmony_ci        set_target_properties(uninstall PROPERTIES FOLDER "GLFW3")
163b877906bSopenharmony_ci    endif()
164b877906bSopenharmony_ciendif()
165b877906bSopenharmony_ci
166