• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2set(common_HEADERS internal.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_tls.h nsgl_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_tls.c
13                     nsgl_context.m)
14elseif (_GLFW_WIN32)
15    set(glfw_HEADERS ${common_HEADERS} win32_platform.h win32_joystick.h
16                     wgl_context.h egl_context.h)
17    set(glfw_SOURCES ${common_SOURCES} win32_init.c win32_joystick.c
18                     win32_monitor.c win32_time.c win32_tls.c win32_window.c
19                     wgl_context.c egl_context.c)
20elseif (_GLFW_X11)
21    set(glfw_HEADERS ${common_HEADERS} x11_platform.h xkb_unicode.h
22                     linux_joystick.h posix_time.h posix_tls.h glx_context.h
23                     egl_context.h)
24    set(glfw_SOURCES ${common_SOURCES} x11_init.c x11_monitor.c x11_window.c
25                     xkb_unicode.c linux_joystick.c posix_time.c posix_tls.c
26                     glx_context.c egl_context.c)
27elseif (_GLFW_WAYLAND)
28    set(glfw_HEADERS ${common_HEADERS} wl_platform.h linux_joystick.h
29                     posix_time.h posix_tls.h xkb_unicode.h egl_context.h)
30    set(glfw_SOURCES ${common_SOURCES} wl_init.c wl_monitor.c wl_window.c
31                     linux_joystick.c posix_time.c posix_tls.c xkb_unicode.c
32                     egl_context.c)
33
34    ecm_add_wayland_client_protocol(glfw_SOURCES
35        PROTOCOL
36        ${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/relative-pointer/relative-pointer-unstable-v1.xml
37        BASENAME relative-pointer-unstable-v1)
38    ecm_add_wayland_client_protocol(glfw_SOURCES
39        PROTOCOL
40        ${WAYLAND_PROTOCOLS_PKGDATADIR}/unstable/pointer-constraints/pointer-constraints-unstable-v1.xml
41        BASENAME pointer-constraints-unstable-v1)
42elseif (_GLFW_MIR)
43    set(glfw_HEADERS ${common_HEADERS} mir_platform.h linux_joystick.h
44                     posix_time.h posix_tls.h xkb_unicode.h egl_context.h)
45    set(glfw_SOURCES ${common_SOURCES} mir_init.c mir_monitor.c mir_window.c
46                     linux_joystick.c posix_time.c posix_tls.c xkb_unicode.c
47                     egl_context.c)
48endif()
49
50if (APPLE)
51    # For some reason, CMake doesn't know about .m
52    set_source_files_properties(${glfw_SOURCES} PROPERTIES LANGUAGE C)
53endif()
54
55add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS})
56set_target_properties(glfw PROPERTIES
57                      OUTPUT_NAME ${GLFW_LIB_NAME}
58                      VERSION ${GLFW_VERSION}
59                      SOVERSION ${GLFW_VERSION_MAJOR}
60                      POSITION_INDEPENDENT_CODE ON
61                      FOLDER "GLFW3")
62
63target_compile_definitions(glfw PRIVATE -D_GLFW_USE_CONFIG_H)
64target_include_directories(glfw PUBLIC
65                           $<BUILD_INTERFACE:${GLFW_SOURCE_DIR}/include>
66                           $<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>)
67target_include_directories(glfw PRIVATE
68                           "${GLFW_SOURCE_DIR}/src"
69                           "${GLFW_BINARY_DIR}/src"
70                           ${glfw_INCLUDE_DIRS})
71
72# HACK: When building on MinGW, WINVER and UNICODE need to be defined before
73# the inclusion of stddef.h (by glfw3.h), which is itself included before
74# win32_platform.h.  We define them here until a saner solution can be found
75# NOTE: MinGW-w64 and Visual C++ do /not/ need this hack.
76target_compile_definitions(glfw PRIVATE
77                           "$<$<BOOL:${MINGW}>:UNICODE;WINVER=0x0501>")
78
79# Enable a reasonable set of warnings (no, -Wextra is not reasonable)
80target_compile_options(glfw PRIVATE
81                       "$<$<C_COMPILER_ID:Clang>:-Wall>"
82                       "$<$<C_COMPILER_ID:GNU>:-Wall>")
83
84if (BUILD_SHARED_LIBS)
85    if (WIN32)
86        if (MINGW)
87            # Remove the lib prefix on the DLL (but not the import library
88            set_target_properties(glfw PROPERTIES PREFIX "")
89
90            # Add a suffix to the import library to avoid naming conflicts
91            set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.a")
92        else()
93            # Add a suffix to the import library to avoid naming conflicts
94            set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.lib")
95        endif()
96    elseif (APPLE)
97        # Add -fno-common to work around a bug in Apple's GCC
98        target_compile_options(glfw PRIVATE "-fno-common")
99
100        set_target_properties(glfw PROPERTIES
101                              INSTALL_NAME_DIR "lib${LIB_SUFFIX}")
102    elseif (UNIX)
103        # Hide symbols not explicitly tagged for export from the shared library
104        target_compile_options(glfw PRIVATE "-fvisibility=hidden")
105    endif()
106
107    target_compile_definitions(glfw INTERFACE -DGLFW_DLL)
108    target_link_libraries(glfw PRIVATE ${glfw_LIBRARIES})
109else()
110    target_link_libraries(glfw INTERFACE ${glfw_LIBRARIES})
111endif()
112
113if (MSVC)
114    target_compile_definitions(glfw PRIVATE _CRT_SECURE_NO_WARNINGS)
115endif()
116
117if (GLFW_INSTALL)
118    install(TARGETS glfw EXPORT glfwTargets DESTINATION lib${LIB_SUFFIX})
119endif()
120
121