mirror of
https://github.com/glfw/glfw.git
synced 2025-10-04 13:46:37 +00:00
add object library support for parent projects
- Transitive dependency management via `target_link_libraries` with object libraries introduced in CMake 3.12. - Update a few minor elements related to switching to new CMake.
This commit is contained in:
parent
d25248343e
commit
3988fc18ba
@ -1,13 +1,9 @@
|
|||||||
cmake_minimum_required(VERSION 3.0)
|
cmake_minimum_required(VERSION 3.12)
|
||||||
|
|
||||||
project(GLFW VERSION 3.4.0 LANGUAGES C)
|
project(GLFW VERSION 3.4.0 LANGUAGES C)
|
||||||
|
|
||||||
set(CMAKE_LEGACY_CYGWIN_WIN32 OFF)
|
set(CMAKE_LEGACY_CYGWIN_WIN32 OFF)
|
||||||
|
|
||||||
if (POLICY CMP0054)
|
|
||||||
cmake_policy(SET CMP0054 NEW)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (POLICY CMP0077)
|
if (POLICY CMP0077)
|
||||||
cmake_policy(SET CMP0077 NEW)
|
cmake_policy(SET CMP0077 NEW)
|
||||||
endif()
|
endif()
|
||||||
|
@ -92,7 +92,19 @@ if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR
|
|||||||
COMPILE_FLAGS -Wdeclaration-after-statement)
|
COMPILE_FLAGS -Wdeclaration-after-statement)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS})
|
add_library(glfw-objects OBJECT ${glfw_SOURCES} ${glfw_HEADERS})
|
||||||
|
add_library(glfw "")
|
||||||
|
target_link_libraries(glfw PUBLIC glfw-objects)
|
||||||
|
|
||||||
|
# XCode bug: need at least one "real" source file. See:
|
||||||
|
# https://cmake.org/Bug/view.php?id=14044
|
||||||
|
# https://cmake.org/cmake/help/latest/command/add_library.html#object-libraries
|
||||||
|
if (XCODE)
|
||||||
|
set(glfw_xcode_dummy "${CMAKE_CURRENT_BINARY_DIR}/xcode_dummy.c")
|
||||||
|
file(WRITE ${glfw_xcode_dummy} "")
|
||||||
|
target_sources(glfw PRIVATE ${glfw_xcode_dummy})
|
||||||
|
endif()
|
||||||
|
|
||||||
set_target_properties(glfw PROPERTIES
|
set_target_properties(glfw PROPERTIES
|
||||||
OUTPUT_NAME ${GLFW_LIB_NAME}
|
OUTPUT_NAME ${GLFW_LIB_NAME}
|
||||||
VERSION ${GLFW_VERSION_MAJOR}.${GLFW_VERSION_MINOR}
|
VERSION ${GLFW_VERSION_MAJOR}.${GLFW_VERSION_MINOR}
|
||||||
@ -100,11 +112,11 @@ set_target_properties(glfw PROPERTIES
|
|||||||
POSITION_INDEPENDENT_CODE ON
|
POSITION_INDEPENDENT_CODE ON
|
||||||
FOLDER "GLFW3")
|
FOLDER "GLFW3")
|
||||||
|
|
||||||
target_compile_definitions(glfw PRIVATE _GLFW_USE_CONFIG_H)
|
target_compile_definitions(glfw-objects PRIVATE _GLFW_USE_CONFIG_H)
|
||||||
target_include_directories(glfw PUBLIC
|
target_include_directories(glfw-objects PUBLIC
|
||||||
"$<BUILD_INTERFACE:${GLFW_SOURCE_DIR}/include>"
|
"$<BUILD_INTERFACE:${GLFW_SOURCE_DIR}/include>"
|
||||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
|
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
|
||||||
target_include_directories(glfw PRIVATE
|
target_include_directories(glfw-objects PRIVATE
|
||||||
"${GLFW_SOURCE_DIR}/src"
|
"${GLFW_SOURCE_DIR}/src"
|
||||||
"${GLFW_BINARY_DIR}/src"
|
"${GLFW_BINARY_DIR}/src"
|
||||||
${glfw_INCLUDE_DIRS})
|
${glfw_INCLUDE_DIRS})
|
||||||
@ -113,11 +125,11 @@ target_include_directories(glfw PRIVATE
|
|||||||
# the inclusion of stddef.h (by glfw3.h), which is itself included before
|
# the inclusion of stddef.h (by glfw3.h), which is itself included before
|
||||||
# win32_platform.h. We define them here until a saner solution can be found
|
# win32_platform.h. We define them here until a saner solution can be found
|
||||||
# NOTE: MinGW-w64 and Visual C++ do /not/ need this hack.
|
# NOTE: MinGW-w64 and Visual C++ do /not/ need this hack.
|
||||||
target_compile_definitions(glfw PRIVATE
|
target_compile_definitions(glfw-objects PRIVATE
|
||||||
"$<$<BOOL:${MINGW}>:UNICODE;WINVER=0x0501>")
|
"$<$<BOOL:${MINGW}>:UNICODE;WINVER=0x0501>")
|
||||||
|
|
||||||
# Enable a reasonable set of warnings (no, -Wextra is not reasonable)
|
# Enable a reasonable set of warnings (no, -Wextra is not reasonable)
|
||||||
target_compile_options(glfw PRIVATE
|
target_compile_options(glfw-objects PRIVATE
|
||||||
"$<$<C_COMPILER_ID:AppleClang>:-Wall>"
|
"$<$<C_COMPILER_ID:AppleClang>:-Wall>"
|
||||||
"$<$<C_COMPILER_ID:Clang>:-Wall>"
|
"$<$<C_COMPILER_ID:Clang>:-Wall>"
|
||||||
"$<$<C_COMPILER_ID:GNU>:-Wall>")
|
"$<$<C_COMPILER_ID:GNU>:-Wall>")
|
||||||
@ -139,19 +151,23 @@ if (BUILD_SHARED_LIBS)
|
|||||||
set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.lib")
|
set_target_properties(glfw PROPERTIES IMPORT_SUFFIX "dll.lib")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_compile_definitions(glfw INTERFACE GLFW_DLL)
|
target_compile_definitions(glfw-objects INTERFACE GLFW_DLL)
|
||||||
elseif (APPLE)
|
elseif (APPLE)
|
||||||
# Add -fno-common to work around a bug in Apple's GCC
|
# Add -fno-common to work around a bug in Apple's GCC
|
||||||
target_compile_options(glfw PRIVATE "-fno-common")
|
target_compile_options(glfw-objects PRIVATE "-fno-common")
|
||||||
|
|
||||||
set_target_properties(glfw PROPERTIES
|
set_target_properties(glfw PROPERTIES
|
||||||
INSTALL_NAME_DIR "${CMAKE_INSTALL_LIBDIR}")
|
INSTALL_NAME_DIR "${CMAKE_INSTALL_LIBDIR}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (UNIX)
|
# Hide symbols not explicitly tagged for export from the shared library.
|
||||||
# Hide symbols not explicitly tagged for export from the shared library
|
# Results in e.g., -fvisibility=hidden for gcc/clang. Requires PIC code.
|
||||||
target_compile_options(glfw PRIVATE "-fvisibility=hidden")
|
set_target_properties(glfw-objects glfw
|
||||||
endif()
|
PROPERTIES
|
||||||
|
C_VISIBILITY_PRESET "hidden"
|
||||||
|
VISIBILITY_INLINES_HIDDEN ON
|
||||||
|
POSITION_INDEPENDENT_CODE ON
|
||||||
|
)
|
||||||
|
|
||||||
target_link_libraries(glfw PRIVATE ${glfw_LIBRARIES})
|
target_link_libraries(glfw PRIVATE ${glfw_LIBRARIES})
|
||||||
else()
|
else()
|
||||||
@ -159,11 +175,11 @@ else()
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
target_compile_definitions(glfw PRIVATE _CRT_SECURE_NO_WARNINGS)
|
target_compile_definitions(glfw-objects PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (GLFW_INSTALL)
|
if (GLFW_INSTALL)
|
||||||
install(TARGETS glfw
|
install(TARGETS glfw glfw-objects
|
||||||
EXPORT glfwTargets
|
EXPORT glfwTargets
|
||||||
RUNTIME DESTINATION "bin"
|
RUNTIME DESTINATION "bin"
|
||||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||||
|
Loading…
Reference in New Issue
Block a user