2 set(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")
6 set(common_SOURCES context.c init.c input.c monitor.c vulkan.c window.c)
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)
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)
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)
26 elseif (_GLFW_WAYLAND)
27 set(glfw_HEADERS ${common_HEADERS} wl_platform.h
28 posix_time.h posix_thread.h xkb_unicode.h egl_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)
34 ecm_add_wayland_client_protocol(glfw_SOURCES
36 "${WAYLAND_PROTOCOLS_PKGDATADIR}/stable/xdg-shell/xdg-shell.xml"
38 ecm_add_wayland_client_protocol(glfw_SOURCES
40 "${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml"
41 BASENAME xdg-decoration)
42 ecm_add_wayland_client_protocol(glfw_SOURCES
44 "${WAYLAND_PROTOCOLS_PKGDATADIR}/stable/viewporter/viewporter.xml"
46 ecm_add_wayland_client_protocol(glfw_SOURCES
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
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
56 "${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml"
57 BASENAME idle-inhibit-unstable-v1)
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)
65 if (_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)
70 set(glfw_HEADERS ${glfw_HEADERS} null_joystick.h)
71 set(glfw_SOURCES ${glfw_SOURCES} null_joystick.c)
76 # For some reason, CMake doesn't know about .m
77 set_source_files_properties(${glfw_SOURCES} PROPERTIES LANGUAGE C)
80 # Make GCC and Clang warn about declarations that VS 2010 and 2012 won't accept
81 # for all source files that VS will build
82 if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR
83 "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR
84 "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")
87 set(windows_SOURCES ${glfw_SOURCES})
89 set(windows_SOURCES ${common_SOURCES})
91 set_source_files_properties(${windows_SOURCES} PROPERTIES
92 COMPILE_FLAGS -Wdeclaration-after-statement)
95 add_library(glfw_objlib OBJECT ${glfw_SOURCES} ${glfw_HEADERS})
96 add_library(glfw $<TARGET_OBJECTS:glfw_objlib>)
97 set_target_properties(glfw_objlib PROPERTIES POSITION_INDEPENDENT_CODE ON)
98 set_target_properties(glfw PROPERTIES
99 OUTPUT_NAME ${GLFW_LIB_NAME}
100 VERSION ${GLFW_VERSION_MAJOR}.${GLFW_VERSION_MINOR}
101 SOVERSION ${GLFW_VERSION_MAJOR}
104 if (${CMAKE_VERSION} VERSION_EQUAL "3.1.0" OR
105 ${CMAKE_VERSION} VERSION_GREATER "3.1.0")
107 set_target_properties(glfw_objlib PROPERTIES C_STANDARD 99)
109 # Remove this fallback when removing support for CMake version less than 3.1
110 target_compile_options(glfw_objlib PRIVATE
111 "$<$<C_COMPILER_ID:AppleClang>:-std=c99>"
112 "$<$<C_COMPILER_ID:Clang>:-std=c99>"
113 "$<$<C_COMPILER_ID:GNU>:-std=c99>")
116 target_compile_definitions(glfw_objlib PRIVATE _GLFW_USE_CONFIG_H)
117 target_include_directories(glfw_objlib PUBLIC
118 "$<BUILD_INTERFACE:${GLFW_SOURCE_DIR}/include>"
119 "$<INSTALL_INTERFACE:${CMAKE_INSTALL_FULL_INCLUDEDIR}>")
120 target_include_directories(glfw PUBLIC
121 "$<BUILD_INTERFACE:${GLFW_SOURCE_DIR}/include>"
122 "$<INSTALL_INTERFACE:${CMAKE_INSTALL_FULL_INCLUDEDIR}>")
123 target_include_directories(glfw_objlib PRIVATE
124 "${GLFW_SOURCE_DIR}/src"
125 "${GLFW_BINARY_DIR}/src"
126 ${glfw_INCLUDE_DIRS})
128 # HACK: When building on MinGW, WINVER and UNICODE need to be defined before
129 # the inclusion of stddef.h (by glfw3.h), which is itself included before
130 # win32_platform.h. We define them here until a saner solution can be found
131 # NOTE: MinGW-w64 and Visual C++ do /not/ need this hack.
132 target_compile_definitions(glfw_objlib PRIVATE
133 "$<$<BOOL:${MINGW}>:UNICODE;WINVER=0x0501>")
135 # Enable a reasonable set of warnings (no, -Wextra is not reasonable)
136 target_compile_options(glfw_objlib PRIVATE
137 "$<$<C_COMPILER_ID:AppleClang>:-Wall>"
138 "$<$<C_COMPILER_ID:Clang>:-Wall>"
139 "$<$<C_COMPILER_ID:GNU>:-Wall>")
141 if (BUILD_SHARED_LIBS)
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_options(glfw PRIVATE "-static-libgcc")
148 # Remove the lib prefix on the DLL (but not the import library)
149 set_target_properties(glfw PROPERTIES PREFIX "")
151 # Add a suffix to the import library to avoid naming conflicts
152 set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.a")
154 # Add a suffix to the import library to avoid naming conflicts
155 set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.lib")
158 target_compile_definitions(glfw_objlib INTERFACE GLFW_DLL)
160 # Add -fno-common to work around a bug in Apple's GCC
161 target_compile_options(glfw_objlib PRIVATE "-fno-common")
163 set_target_properties(glfw PROPERTIES
164 INSTALL_NAME_DIR "${CMAKE_INSTALL_LIBDIR}")
168 # Hide symbols not explicitly tagged for export from the shared library
169 target_compile_options(glfw_objlib PRIVATE "-fvisibility=hidden")
172 target_link_libraries(glfw PRIVATE ${glfw_LIBRARIES})
174 target_link_libraries(glfw INTERFACE ${glfw_LIBRARIES})
178 target_compile_definitions(glfw_objlib PRIVATE _CRT_SECURE_NO_WARNINGS)
184 RUNTIME DESTINATION "bin"
185 ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
186 LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")