Simplify sfml_find_package
All in service of hopefully removing sfml_find_package one day since that will simplify packaging SFML and better set us up for adopting a package manager.
This commit is contained in:
parent
62c376ffa5
commit
af7d6c2589
@ -381,32 +381,17 @@ endfunction()
|
|||||||
|
|
||||||
# Find the requested package and make an INTERFACE library from it
|
# Find the requested package and make an INTERFACE library from it
|
||||||
# The created INTERFACE library is tagged for export to be part of the generated SFMLConfig
|
# The created INTERFACE library is tagged for export to be part of the generated SFMLConfig
|
||||||
# Usage: sfml_find_package(wanted_target_name
|
# Usage: sfml_find_package(wanted_target_name [OPENGL_INCLUDE_DIR] [OPENGL_gl_LIBRARY])
|
||||||
# [INCLUDE "OPENGL_INCLUDE_DIR"]
|
function(sfml_find_package target INCLUDE_DIRS LINK_LIBRARIES)
|
||||||
# [LINK "OPENGL_gl_LIBRARY"])
|
|
||||||
function(sfml_find_package)
|
|
||||||
list(GET ARGN 0 target)
|
|
||||||
list(REMOVE_AT ARGN 0)
|
|
||||||
|
|
||||||
if(TARGET ${target})
|
if(TARGET ${target})
|
||||||
message(FATAL_ERROR "Target '${target}' is already defined")
|
message(FATAL_ERROR "Target '${target}' is already defined")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
cmake_parse_arguments(THIS "" "" "INCLUDE;LINK" ${ARGN})
|
|
||||||
if(THIS_UNPARSED_ARGUMENTS)
|
|
||||||
message(FATAL_ERROR "Unknown arguments when calling sfml_find_package: ${THIS_UNPARSED_ARGUMENTS}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
find_package(${target} REQUIRED)
|
find_package(${target} REQUIRED)
|
||||||
add_library(${target} INTERFACE)
|
add_library(${target} INTERFACE)
|
||||||
|
|
||||||
foreach(include_dir IN LISTS THIS_INCLUDE)
|
target_include_directories(${target} SYSTEM INTERFACE "$<BUILD_INTERFACE:${${INCLUDE_DIRS}}>")
|
||||||
target_include_directories(${target} SYSTEM INTERFACE "$<BUILD_INTERFACE:${${include_dir}}>")
|
target_link_libraries(${target} INTERFACE "$<BUILD_INTERFACE:${${LINK_LIBRARIES}}>")
|
||||||
endforeach()
|
|
||||||
|
|
||||||
foreach(link_item IN LISTS THIS_LINK)
|
|
||||||
target_link_libraries(${target} INTERFACE "$<BUILD_INTERFACE:${${link_item}}>")
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
install(TARGETS ${target} EXPORT SFMLConfigExport)
|
install(TARGETS ${target} EXPORT SFMLConfigExport)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
@ -68,9 +68,9 @@ elseif(SFML_OS_ANDROID)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# find external libraries
|
# find external libraries
|
||||||
sfml_find_package(OpenAL INCLUDE "OPENAL_INCLUDE_DIR" LINK "OPENAL_LIBRARY")
|
sfml_find_package(OpenAL OPENAL_INCLUDE_DIR OPENAL_LIBRARY)
|
||||||
sfml_find_package(VORBIS INCLUDE "VORBIS_INCLUDE_DIRS" LINK "VORBIS_LIBRARIES")
|
sfml_find_package(VORBIS VORBIS_INCLUDE_DIRS VORBIS_LIBRARIES)
|
||||||
sfml_find_package(FLAC INCLUDE "FLAC_INCLUDE_DIR" LINK "FLAC_LIBRARY")
|
sfml_find_package(FLAC FLAC_INCLUDE_DIR FLAC_LIBRARY)
|
||||||
|
|
||||||
# avoids warnings in vorbisfile.h
|
# avoids warnings in vorbisfile.h
|
||||||
target_compile_definitions(VORBIS INTERFACE "OV_EXCLUDE_STATIC_CALLBACKS")
|
target_compile_definitions(VORBIS INTERFACE "OV_EXCLUDE_STATIC_CALLBACKS")
|
||||||
|
@ -117,7 +117,7 @@ elseif(SFML_OS_IOS)
|
|||||||
target_link_libraries(sfml-graphics PRIVATE z bz2)
|
target_link_libraries(sfml-graphics PRIVATE z bz2)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
sfml_find_package(Freetype INCLUDE "FREETYPE_INCLUDE_DIRS" LINK "FREETYPE_LIBRARY")
|
sfml_find_package(Freetype FREETYPE_INCLUDE_DIRS FREETYPE_LIBRARY)
|
||||||
target_link_libraries(sfml-graphics PRIVATE Freetype)
|
target_link_libraries(sfml-graphics PRIVATE Freetype)
|
||||||
|
|
||||||
# on some platforms (e.g. Raspberry Pi 3 armhf), GCC requires linking libatomic to use <atomic> features
|
# on some platforms (e.g. Raspberry Pi 3 armhf), GCC requires linking libatomic to use <atomic> features
|
||||||
|
@ -278,9 +278,9 @@ sfml_add_library(Window
|
|||||||
# DRM libraries
|
# DRM libraries
|
||||||
if(SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_OPENBSD OR SFML_OS_NETBSD)
|
if(SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_OPENBSD OR SFML_OS_NETBSD)
|
||||||
if(SFML_USE_DRM)
|
if(SFML_USE_DRM)
|
||||||
sfml_find_package(DRM INCLUDE "DRM_INCLUDE_DIR" LINK "DRM_LIBRARY")
|
sfml_find_package(DRM DRM_INCLUDE_DIR DRM_LIBRARY)
|
||||||
target_include_directories(sfml-window PRIVATE ${DRM_INCLUDE_DIR}/libdrm)
|
target_include_directories(sfml-window PRIVATE ${DRM_INCLUDE_DIR}/libdrm)
|
||||||
sfml_find_package(GBM INCLUDE "GBM_INCLUDE_DIR" LINK "GBM_LIBRARY")
|
sfml_find_package(GBM GBM_INCLUDE_DIR GBM_LIBRARY)
|
||||||
target_link_libraries(sfml-window PRIVATE drm gbm EGL)
|
target_link_libraries(sfml-window PRIVATE drm gbm EGL)
|
||||||
else()
|
else()
|
||||||
find_package(X11 REQUIRED COMPONENTS Xrandr Xcursor)
|
find_package(X11 REQUIRED COMPONENTS Xrandr Xcursor)
|
||||||
@ -311,12 +311,12 @@ endif()
|
|||||||
if(SFML_OS_IOS)
|
if(SFML_OS_IOS)
|
||||||
target_link_libraries(sfml-window PRIVATE "-framework OpenGLES")
|
target_link_libraries(sfml-window PRIVATE "-framework OpenGLES")
|
||||||
elseif(SFML_OS_ANDROID)
|
elseif(SFML_OS_ANDROID)
|
||||||
sfml_find_package(GLES INCLUDE "GLES_INCLUDE_DIR" LINK "GLES_LIBRARY")
|
sfml_find_package(GLES GLES_INCLUDE_DIR GLES_LIBRARY)
|
||||||
sfml_find_package(EGL INCLUDE "EGL_INCLUDE_DIR" LINK "EGL_LIBRARY")
|
sfml_find_package(EGL EGL_INCLUDE_DIR EGL_LIBRARY)
|
||||||
target_link_libraries(sfml-window PRIVATE EGL)
|
target_link_libraries(sfml-window PRIVATE EGL)
|
||||||
target_link_libraries(sfml-window PRIVATE GLES)
|
target_link_libraries(sfml-window PRIVATE GLES)
|
||||||
else()
|
else()
|
||||||
sfml_find_package(OpenGL INCLUDE "OPENGL_INCLUDE_DIR" LINK "OPENGL_gl_LIBRARY")
|
sfml_find_package(OpenGL OPENGL_INCLUDE_DIR OPENGL_gl_LIBRARY)
|
||||||
target_link_libraries(sfml-window PRIVATE OpenGL)
|
target_link_libraries(sfml-window PRIVATE OpenGL)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@ -329,7 +329,7 @@ if(SFML_OS_WINDOWS AND NOT SFML_COMPILER_MSVC)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(SFML_OS_LINUX)
|
if(SFML_OS_LINUX)
|
||||||
sfml_find_package(UDev INCLUDE "UDEV_INCLUDE_DIR" LINK "UDEV_LIBRARIES")
|
sfml_find_package(UDev UDEV_INCLUDE_DIR UDEV_LIBRARIES)
|
||||||
target_link_libraries(sfml-window PRIVATE UDev dl)
|
target_link_libraries(sfml-window PRIVATE UDev dl)
|
||||||
elseif(SFML_OS_WINDOWS)
|
elseif(SFML_OS_WINDOWS)
|
||||||
target_link_libraries(sfml-window PRIVATE winmm gdi32)
|
target_link_libraries(sfml-window PRIVATE winmm gdi32)
|
||||||
|
Loading…
Reference in New Issue
Block a user