From af7d6c2589489c2b623bc8cb2ed870a1863cf062 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Mon, 14 Aug 2023 22:41:30 -0600 Subject: [PATCH] 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. --- cmake/Macros.cmake | 23 ++++------------------- src/SFML/Audio/CMakeLists.txt | 6 +++--- src/SFML/Graphics/CMakeLists.txt | 2 +- src/SFML/Window/CMakeLists.txt | 12 ++++++------ 4 files changed, 14 insertions(+), 29 deletions(-) diff --git a/cmake/Macros.cmake b/cmake/Macros.cmake index 947dfacf..41e4d874 100644 --- a/cmake/Macros.cmake +++ b/cmake/Macros.cmake @@ -381,32 +381,17 @@ endfunction() # 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 -# Usage: sfml_find_package(wanted_target_name -# [INCLUDE "OPENGL_INCLUDE_DIR"] -# [LINK "OPENGL_gl_LIBRARY"]) -function(sfml_find_package) - list(GET ARGN 0 target) - list(REMOVE_AT ARGN 0) - +# Usage: sfml_find_package(wanted_target_name [OPENGL_INCLUDE_DIR] [OPENGL_gl_LIBRARY]) +function(sfml_find_package target INCLUDE_DIRS LINK_LIBRARIES) if(TARGET ${target}) message(FATAL_ERROR "Target '${target}' is already defined") 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) add_library(${target} INTERFACE) - foreach(include_dir IN LISTS THIS_INCLUDE) - target_include_directories(${target} SYSTEM INTERFACE "$") - endforeach() - - foreach(link_item IN LISTS THIS_LINK) - target_link_libraries(${target} INTERFACE "$") - endforeach() + target_include_directories(${target} SYSTEM INTERFACE "$") + target_link_libraries(${target} INTERFACE "$") install(TARGETS ${target} EXPORT SFMLConfigExport) endfunction() diff --git a/src/SFML/Audio/CMakeLists.txt b/src/SFML/Audio/CMakeLists.txt index 50580748..6a768f2e 100644 --- a/src/SFML/Audio/CMakeLists.txt +++ b/src/SFML/Audio/CMakeLists.txt @@ -68,9 +68,9 @@ elseif(SFML_OS_ANDROID) endif() # find external libraries -sfml_find_package(OpenAL INCLUDE "OPENAL_INCLUDE_DIR" LINK "OPENAL_LIBRARY") -sfml_find_package(VORBIS INCLUDE "VORBIS_INCLUDE_DIRS" LINK "VORBIS_LIBRARIES") -sfml_find_package(FLAC INCLUDE "FLAC_INCLUDE_DIR" LINK "FLAC_LIBRARY") +sfml_find_package(OpenAL OPENAL_INCLUDE_DIR OPENAL_LIBRARY) +sfml_find_package(VORBIS VORBIS_INCLUDE_DIRS VORBIS_LIBRARIES) +sfml_find_package(FLAC FLAC_INCLUDE_DIR FLAC_LIBRARY) # avoids warnings in vorbisfile.h target_compile_definitions(VORBIS INTERFACE "OV_EXCLUDE_STATIC_CALLBACKS") diff --git a/src/SFML/Graphics/CMakeLists.txt b/src/SFML/Graphics/CMakeLists.txt index 984f997c..ab0a38f0 100644 --- a/src/SFML/Graphics/CMakeLists.txt +++ b/src/SFML/Graphics/CMakeLists.txt @@ -117,7 +117,7 @@ elseif(SFML_OS_IOS) target_link_libraries(sfml-graphics PRIVATE z bz2) 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) # on some platforms (e.g. Raspberry Pi 3 armhf), GCC requires linking libatomic to use features diff --git a/src/SFML/Window/CMakeLists.txt b/src/SFML/Window/CMakeLists.txt index 696cd2b3..97656ebb 100644 --- a/src/SFML/Window/CMakeLists.txt +++ b/src/SFML/Window/CMakeLists.txt @@ -278,9 +278,9 @@ sfml_add_library(Window # DRM libraries if(SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_OPENBSD OR SFML_OS_NETBSD) 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) - 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) else() find_package(X11 REQUIRED COMPONENTS Xrandr Xcursor) @@ -311,12 +311,12 @@ endif() if(SFML_OS_IOS) target_link_libraries(sfml-window PRIVATE "-framework OpenGLES") elseif(SFML_OS_ANDROID) - sfml_find_package(GLES INCLUDE "GLES_INCLUDE_DIR" LINK "GLES_LIBRARY") - sfml_find_package(EGL INCLUDE "EGL_INCLUDE_DIR" LINK "EGL_LIBRARY") + sfml_find_package(GLES GLES_INCLUDE_DIR GLES_LIBRARY) + sfml_find_package(EGL EGL_INCLUDE_DIR EGL_LIBRARY) target_link_libraries(sfml-window PRIVATE EGL) target_link_libraries(sfml-window PRIVATE GLES) 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) endif() @@ -329,7 +329,7 @@ if(SFML_OS_WINDOWS AND NOT SFML_COMPILER_MSVC) endif() 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) elseif(SFML_OS_WINDOWS) target_link_libraries(sfml-window PRIVATE winmm gdi32)