master
ブランチ master
ShaderPlayground / deps / glfw / src / CMakeLists.txt
8 KB、184行 生 Blame 履歴
1
2set(common_HEADERS internal.h mappings.h
3 "${GLFW_BINARY_DIR}/src/glfw_config.h"
4 "${GLFW_SOURCE_DIR}/include/GLFW/glfw3.h"
5 "${GLFW_SOURCE_DIR}/include/GLFW/glfw3native.h")
6set(common_SOURCES context.c init.c input.c monitor.c vulkan.c window.c)
7
8if (_GLFW_COCOA)
9 set(glfw_HEADERS ${common_HEADERS} cocoa_platform.h cocoa_joystick.h
10 posix_thread.h nsgl_context.h egl_context.h osmesa_context.h)
11 set(glfw_SOURCES ${common_SOURCES} cocoa_init.m cocoa_joystick.m
12 cocoa_monitor.m cocoa_window.m cocoa_time.c posix_thread.c
13 nsgl_context.m egl_context.c osmesa_context.c)
14elseif (_GLFW_WIN32)
15 set(glfw_HEADERS ${common_HEADERS} win32_platform.h win32_joystick.h
16 wgl_context.h egl_context.h osmesa_context.h)
17 set(glfw_SOURCES ${common_SOURCES} win32_init.c win32_joystick.c
18 win32_monitor.c win32_time.c win32_thread.c win32_window.c
19 wgl_context.c egl_context.c osmesa_context.c)
20elseif (_GLFW_X11)
21 set(glfw_HEADERS ${common_HEADERS} x11_platform.h xkb_unicode.h posix_time.h
22 posix_thread.h glx_context.h egl_context.h osmesa_context.h)
23 set(glfw_SOURCES ${common_SOURCES} x11_init.c x11_monitor.c x11_window.c
24 xkb_unicode.c posix_time.c posix_thread.c glx_context.c
25 egl_context.c osmesa_context.c)
26elseif (_GLFW_WAYLAND)
27 set(glfw_HEADERS ${common_HEADERS} wl_platform.h
28 posix_time.h posix_thread.h xkb_unicode.h egl_context.h
29 osmesa_context.h)
30 set(glfw_SOURCES ${common_SOURCES} wl_init.c wl_monitor.c wl_window.c
31 posix_time.c posix_thread.c xkb_unicode.c
32 egl_context.c osmesa_context.c)
33
34 ecm_add_wayland_client_protocol(glfw_SOURCES
35 PROTOCOL
36 "${WAYLAND_PROTOCOLS_PKGDATADIR}/stable/xdg-shell/xdg-shell.xml"
37 BASENAME xdg-shell)
38 ecm_add_wayland_client_protocol(glfw_SOURCES
39 PROTOCOL
40 "${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml"
41 BASENAME xdg-decoration)
42 ecm_add_wayland_client_protocol(glfw_SOURCES
43 PROTOCOL
44 "${WAYLAND_PROTOCOLS_PKGDATADIR}/stable/viewporter/viewporter.xml"
45 BASENAME viewporter)
46 ecm_add_wayland_client_protocol(glfw_SOURCES
47 PROTOCOL
48 "${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/relative-pointer/relative-pointer-unstable-v1.xml"
49 BASENAME relative-pointer-unstable-v1)
50 ecm_add_wayland_client_protocol(glfw_SOURCES
51 PROTOCOL
52 "${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/pointer-constraints/pointer-constraints-unstable-v1.xml"
53 BASENAME pointer-constraints-unstable-v1)
54 ecm_add_wayland_client_protocol(glfw_SOURCES
55 PROTOCOL
56 "${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml"
57 BASENAME idle-inhibit-unstable-v1)
58elseif (_GLFW_OSMESA)
59 set(glfw_HEADERS ${common_HEADERS} null_platform.h null_joystick.h
60 posix_time.h posix_thread.h osmesa_context.h)
61 set(glfw_SOURCES ${common_SOURCES} null_init.c null_monitor.c null_window.c
62 null_joystick.c posix_time.c posix_thread.c osmesa_context.c)
63endif()
64
65if (_GLFW_X11 OR _GLFW_WAYLAND)
66 if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
67 set(glfw_HEADERS ${glfw_HEADERS} linux_joystick.h)
68 set(glfw_SOURCES ${glfw_SOURCES} linux_joystick.c)
69 else()
70 set(glfw_HEADERS ${glfw_HEADERS} null_joystick.h)
71 set(glfw_SOURCES ${glfw_SOURCES} null_joystick.c)
72 endif()
73endif()
74
75if (APPLE)
76 # For some reason CMake didn't know about .m until version 3.16
77 set_source_files_properties(cocoa_init.m cocoa_joystick.m cocoa_monitor.m
78 cocoa_window.m nsgl_context.m PROPERTIES
79 LANGUAGE C)
80endif()
81
82add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS})
83set_target_properties(glfw PROPERTIES
84 OUTPUT_NAME ${GLFW_LIB_NAME}
85 VERSION ${GLFW_VERSION_MAJOR}.${GLFW_VERSION_MINOR}
86 SOVERSION ${GLFW_VERSION_MAJOR}
87 POSITION_INDEPENDENT_CODE ON
88 FOLDER "GLFW3")
89
90if (${CMAKE_VERSION} VERSION_EQUAL "3.1.0" OR
91 ${CMAKE_VERSION} VERSION_GREATER "3.1.0")
92
93 set_target_properties(glfw PROPERTIES C_STANDARD 99)
94else()
95 # Remove this fallback when removing support for CMake version less than 3.1
96 target_compile_options(glfw PRIVATE
97 "$<$<C_COMPILER_ID:AppleClang>:-std=c99>"
98 "$<$<C_COMPILER_ID:Clang>:-std=c99>"
99 "$<$<C_COMPILER_ID:GNU>:-std=c99>")
100endif()
101
102target_compile_definitions(glfw PRIVATE _GLFW_USE_CONFIG_H)
103target_include_directories(glfw PUBLIC
104 "$<BUILD_INTERFACE:${GLFW_SOURCE_DIR}/include>"
105 "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
106target_include_directories(glfw PRIVATE
107 "${GLFW_SOURCE_DIR}/src"
108 "${GLFW_BINARY_DIR}/src"
109 ${glfw_INCLUDE_DIRS})
110target_link_libraries(glfw PRIVATE ${glfw_LIBRARIES})
111
112if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR
113 "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR
114 "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")
115
116 # Make GCC and Clang warn about declarations that VS 2010 and 2012 won't
117 # accept for all source files that VS will build
118 set_source_files_properties(context.c init.c input.c monitor.c vulkan.c
119 window.c win32_init.c win32_joystick.c
120 win32_monitor.c win32_time.c win32_thread.c
121 win32_window.c wgl_context.c egl_context.c
122 osmesa_context.c PROPERTIES
123 COMPILE_FLAGS -Wdeclaration-after-statement)
124
125 # Enable a reasonable set of warnings (no, -Wextra is not reasonable)
126 target_compile_options(glfw PRIVATE "-Wall")
127endif()
128
129if (WIN32)
130 target_compile_definitions(glfw PRIVATE _UNICODE)
131endif()
132
133# HACK: When building on MinGW, WINVER and UNICODE need to be defined before
134# the inclusion of stddef.h (by glfw3.h), which is itself included before
135# win32_platform.h. We define them here until a saner solution can be found
136# NOTE: MinGW-w64 and Visual C++ do /not/ need this hack.
137if (MINGW)
138 target_compile_definitions(glfw PRIVATE UNICODE WINVER=0x0501)
139endif()
140
141if (BUILD_SHARED_LIBS)
142 if (WIN32)
143 if (MINGW)
144 # Remove the dependency on the shared version of libgcc
145 # NOTE: MinGW-w64 has the correct default but MinGW needs this
146 target_link_libraries(glfw PRIVATE "-static-libgcc")
147
148 # Remove the lib prefix on the DLL (but not the import library)
149 set_target_properties(glfw PROPERTIES PREFIX "")
150
151 # Add a suffix to the import library to avoid naming conflicts
152 set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.a")
153 else()
154 # Add a suffix to the import library to avoid naming conflicts
155 set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.lib")
156 endif()
157
158 target_compile_definitions(glfw INTERFACE GLFW_DLL)
159 elseif (APPLE)
160 # Add -fno-common to work around a bug in Apple's GCC
161 target_compile_options(glfw PRIVATE "-fno-common")
162
163 set_target_properties(glfw PROPERTIES
164 INSTALL_NAME_DIR "${CMAKE_INSTALL_LIBDIR}")
165 endif()
166
167 if (UNIX)
168 # Hide symbols not explicitly tagged for export from the shared library
169 target_compile_options(glfw PRIVATE "-fvisibility=hidden")
170 endif()
171endif()
172
173if (MSVC)
174 target_compile_definitions(glfw PRIVATE _CRT_SECURE_NO_WARNINGS)
175endif()
176
177if (GLFW_INSTALL)
178 install(TARGETS glfw
179 EXPORT glfwTargets
180 RUNTIME DESTINATION "bin"
181 ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
182 LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
183endif()
184