Add override variable for CMake library type

This adds the GLFW_LIBRARY_TYPE CMake cache variable, which allows users
and higher-level projects to set what type of library GLFW is built as.

When not empty, this value overrides the standard BUILD_SHARED_LIBS
option for GLFW while still allowing it to control the type of other
libraries in a larger project.

This also allows building GLFW as an object library without adding dummy
source files (as required by Xcode) or producing unused library
binaries.

Projects using CMake 3.12 or later can link the resulting GLFW object
library normally using target_link_libraries.

Fixes #279.
Related to #1307.
Closes #1497.
Closes #1574.
Closes #1928.
This commit is contained in:
Camilla Löwy
2021-07-06 23:12:05 +02:00
parent dffe203c17
commit d83849792b
4 changed files with 33 additions and 8 deletions
+4 -3
View File
@@ -1,5 +1,6 @@
add_library(glfw "${GLFW_SOURCE_DIR}/include/GLFW/glfw3.h"
add_library(glfw ${GLFW_LIBRARY_TYPE}
"${GLFW_SOURCE_DIR}/include/GLFW/glfw3.h"
"${GLFW_SOURCE_DIR}/include/GLFW/glfw3native.h"
internal.h mappings.h context.c init.c input.c monitor.c
vulkan.c window.c)
@@ -96,7 +97,7 @@ if (_GLFW_WAYLAND)
"${GLFW_BINARY_DIR}/src/wayland-idle-inhibit-unstable-v1-client-protocol")
endif()
if (WIN32 AND BUILD_SHARED_LIBS)
if (WIN32 AND GLFW_BUILD_SHARED_LIBRARY)
configure_file(glfw.rc.in glfw.rc @ONLY)
target_sources(glfw PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/glfw.rc")
endif()
@@ -201,7 +202,7 @@ if (_GLFW_X11 OR _GLFW_WAYLAND OR _GLFW_OSMESA)
endif()
endif()
if (BUILD_SHARED_LIBS)
if (GLFW_BUILD_SHARED_LIBRARY)
if (WIN32)
if (MINGW)
# Remove the dependency on the shared version of libgcc