cmake: create SDL3::headers for include path + no exported CMake variables

This commit is contained in:
Anonymous Maarten
2023-01-21 00:55:44 +01:00
committed by Anonymous Maarten
parent 5690dfb65b
commit 93c25e650c
7 changed files with 102 additions and 85 deletions

View File

@@ -39,14 +39,9 @@ else()
return()
endif()
# For compatibility with autotools sdl3-config.cmake, provide SDL3_* variables.
set_and_check(SDL3_PREFIX "${CMAKE_CURRENT_LIST_DIR}/..")
set_and_check(SDL3_EXEC_PREFIX "${CMAKE_CURRENT_LIST_DIR}/..")
set_and_check(SDL3_INCLUDE_DIR "${SDL3_PREFIX}/include")
set(SDL3_INCLUDE_DIRS "${SDL3_INCLUDE_DIR};${SDL3_INCLUDE_DIR}/SDL3")
set_and_check(SDL3_BINDIR "${SDL3_PREFIX}/lib/${_sdl_arch_subdir}")
set_and_check(SDL3_LIBDIR "${SDL3_PREFIX}/lib/${_sdl_arch_subdir}")
set_and_check(_sdl3_prefix "${CMAKE_CURRENT_LIST_DIR}/..")
set(_sdl3_include_dirs "${_sdl3_prefix}/include;${_sdl3_prefix}/include/SDL3")
unset(_sdl3_prefix)
set(SDL3_LIBRARIES SDL3::SDL3)
set(SDL3TEST_LIBRARY SDL3::SDL3_test)
@@ -55,6 +50,16 @@ set(SDL3TEST_LIBRARY SDL3::SDL3_test)
# All targets are created, even when some might not be requested though COMPONENTS.
# This is done for compatibility with CMake generated SDL3-target.cmake files.
if(NOT TARGET SDL3::headers)
add_library(SDL3::headers INTERFACE IMPORTED)
set_target_properties(SDL3::SDL3
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${_sdl3_include_dirs}"
)
endif()
set(SDL3_headers_FOUND TRUE)
unset(_sdl3_include_dirs)
set(_sdl3_library "${SDL3_LIBDIR}/SDL3.lib")
set(_sdl3_dll_library "${SDL3_BINDIR}/SDL3.dll")
if(EXISTS "${_sdl3_library}" AND EXISTS "${_sdl3_dll_library}")
@@ -62,7 +67,7 @@ if(EXISTS "${_sdl3_library}" AND EXISTS "${_sdl3_dll_library}")
add_library(SDL3::SDL3 SHARED IMPORTED)
set_target_properties(SDL3::SDL3
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${SDL3_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "SDL3::headers"
IMPORTED_IMPLIB "${_sdl3_library}"
IMPORTED_LOCATION "${_sdl3_dll_library}"
COMPATIBLE_INTERFACE_BOOL "SDL3_SHARED"
@@ -82,7 +87,7 @@ if(EXISTS "${_sdl3test_library}")
add_library(SDL3::SDL3_test STATIC IMPORTED)
set_target_properties(SDL3::SDL3_test
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${SDL3_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "SDL3::headers"
IMPORTED_LOCATION "${_sdl3test_library}"
)
endif()