mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
Prefer using IMPORTED
targets where possible
My goal is to reduce our need on sfml_find_package until it can finally be removed. It's preferred to simply use find_package to find 3rd party projects. I had to add IMPORTED targets to some of our find modules so that we could get away from using INTERFACE libraries for external code. That also implied that our find moduels need to be installed so that users have access to them when processing SFML's config module.
This commit is contained in:
parent
af7d6c2589
commit
f0e72be285
@ -259,6 +259,9 @@ if(NOT SFML_BUILD_FRAMEWORKS)
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
COMPONENT devel
|
||||
FILES_MATCHING PATTERN "*.hpp" PATTERN "*.inl")
|
||||
install(DIRECTORY cmake/Modules/
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/SFML
|
||||
COMPONENT devel)
|
||||
|
||||
if(SFML_GENERATE_PDB)
|
||||
install(DIRECTORY ${PROJECT_BINARY_DIR}/lib/
|
||||
|
@ -16,3 +16,8 @@ find_library(DRM_LIBRARY NAMES drm)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(DRM DEFAULT_MSG DRM_LIBRARY DRM_INCLUDE_DIR)
|
||||
|
||||
add_library(DRM::DRM IMPORTED UNKNOWN)
|
||||
set_target_properties(DRM::DRM PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES ${DRM_INCLUDE_DIR}/libdrm
|
||||
IMPORTED_LOCATION ${DRM_LIBRARY})
|
||||
|
@ -12,3 +12,8 @@ find_library(EGL_LIBRARY NAMES EGL)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(EGL DEFAULT_MSG EGL_LIBRARY EGL_INCLUDE_DIR)
|
||||
|
||||
add_library(EGL::EGL IMPORTED UNKNOWN)
|
||||
set_target_properties(EGL::EGL PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES ${EGL_INCLUDE_DIR}
|
||||
IMPORTED_LOCATION ${EGL_LIBRARY})
|
||||
|
@ -16,3 +16,8 @@ find_library(GBM_LIBRARY NAMES gbm)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(GBM DEFAULT_MSG GBM_LIBRARY GBM_INCLUDE_DIR)
|
||||
|
||||
add_library(GBM::GBM IMPORTED UNKNOWN)
|
||||
set_target_properties(GBM::GBM PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES ${GBM_INCLUDE_DIR}
|
||||
IMPORTED_LOCATION ${GBM_LIBRARY})
|
||||
|
@ -12,3 +12,8 @@ find_library(GLES_LIBRARY NAMES GLESv1_CM)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(GLES DEFAULT_MSG GLES_LIBRARY GLES_INCLUDE_DIR)
|
||||
|
||||
add_library(GLES::GLES IMPORTED UNKNOWN)
|
||||
set_target_properties(GLES::GLES PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES ${GLES_INCLUDE_DIR}
|
||||
IMPORTED_LOCATION ${GLES_LIBRARY})
|
||||
|
@ -50,4 +50,12 @@ else()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(UDev DEFAULT_MSG UDEV_INCLUDE_DIR UDEV_LIBRARIES)
|
||||
|
||||
mark_as_advanced(UDEV_INCLUDE_DIR UDEV_LIBRARIES)
|
||||
|
||||
add_library(UDev::UDev IMPORTED UNKNOWN)
|
||||
set_target_properties(UDev::UDev PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES ${UDEV_INCLUDE_DIR}
|
||||
IMPORTED_LOCATION ${UDEV_LIBRARIES})
|
||||
|
@ -1,5 +1,7 @@
|
||||
# in case of static linking, we must also define the list of all the dependencies of SFML libraries
|
||||
if(SFML_STATIC_LIBRARIES)
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
include(CMakeFindDependencyMacro)
|
||||
|
||||
# detect the OS
|
||||
@ -44,20 +46,21 @@ if(SFML_STATIC_LIBRARIES)
|
||||
list(FIND SFML_FIND_COMPONENTS "Window" FIND_SFML_WINDOW_COMPONENT_INDEX)
|
||||
if(FIND_SFML_WINDOW_COMPONENT_INDEX GREATER -1)
|
||||
if(FIND_SFML_USE_DRM)
|
||||
sfml_bind_dependency(TARGET DRM FRIENDLY_NAME "drm" SEARCH_NAMES "drm")
|
||||
sfml_bind_dependency(TARGET GBM FRIENDLY_NAME "gbm" SEARCH_NAMES "gbm")
|
||||
find_dependency(DRM)
|
||||
find_dependency(GBM)
|
||||
elseif(FIND_SFML_OS_LINUX OR FIND_SFML_OS_FREEBSD)
|
||||
find_dependency(X11 REQUIRED COMPONENTS Xrandr Xcursor)
|
||||
endif()
|
||||
|
||||
if(FIND_SFML_OS_LINUX)
|
||||
sfml_bind_dependency(TARGET UDev FRIENDLY_NAME "UDev" SEARCH_NAMES "udev" "libudev")
|
||||
find_dependency(UDev)
|
||||
endif()
|
||||
|
||||
if(FIND_SFML_OS_WINDOWS)
|
||||
set_property(TARGET OpenGL APPEND PROPERTY INTERFACE_LINK_LIBRARIES "OpenGL32")
|
||||
elseif(NOT FIND_SFML_OS_IOS)
|
||||
sfml_bind_dependency(TARGET OpenGL FRIENDLY_NAME "OpenGL" SEARCH_NAMES "OpenGL" "GL")
|
||||
if(NOT FIND_SFML_OS_IOS)
|
||||
if(NOT OpenGL_GL_PREFERENCE)
|
||||
set(OpenGL_GL_PREFERENCE "LEGACY")
|
||||
endif()
|
||||
find_dependency(OpenGL COMPONENTS OpenGL)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
@ -278,10 +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 DRM_INCLUDE_DIR DRM_LIBRARY)
|
||||
target_include_directories(sfml-window PRIVATE ${DRM_INCLUDE_DIR}/libdrm)
|
||||
sfml_find_package(GBM GBM_INCLUDE_DIR GBM_LIBRARY)
|
||||
target_link_libraries(sfml-window PRIVATE drm gbm EGL)
|
||||
find_package(DRM REQUIRED)
|
||||
find_package(GBM REQUIRED)
|
||||
target_link_libraries(sfml-window PRIVATE DRM::DRM GBM::GBM EGL)
|
||||
else()
|
||||
find_package(X11 REQUIRED COMPONENTS Xrandr Xcursor)
|
||||
target_link_libraries(sfml-window PRIVATE X11::X11 X11::Xrandr X11::Xcursor)
|
||||
@ -311,13 +310,12 @@ endif()
|
||||
if(SFML_OS_IOS)
|
||||
target_link_libraries(sfml-window PRIVATE "-framework OpenGLES")
|
||||
elseif(SFML_OS_ANDROID)
|
||||
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)
|
||||
find_package(EGL REQUIRED)
|
||||
find_package(GLES REQUIRED)
|
||||
target_link_libraries(sfml-window PRIVATE EGL::EGL GLES::GLES)
|
||||
else()
|
||||
sfml_find_package(OpenGL OPENGL_INCLUDE_DIR OPENGL_gl_LIBRARY)
|
||||
target_link_libraries(sfml-window PRIVATE OpenGL)
|
||||
find_package(OpenGL REQUIRED COMPONENTS OpenGL)
|
||||
target_link_libraries(sfml-window PRIVATE OpenGL::GL)
|
||||
endif()
|
||||
|
||||
if(SFML_OS_WINDOWS AND NOT SFML_COMPILER_MSVC)
|
||||
@ -329,8 +327,8 @@ if(SFML_OS_WINDOWS AND NOT SFML_COMPILER_MSVC)
|
||||
endif()
|
||||
|
||||
if(SFML_OS_LINUX)
|
||||
sfml_find_package(UDev UDEV_INCLUDE_DIR UDEV_LIBRARIES)
|
||||
target_link_libraries(sfml-window PRIVATE UDev dl)
|
||||
find_package(UDev REQUIRED)
|
||||
target_link_libraries(sfml-window PRIVATE UDev::UDev dl)
|
||||
elseif(SFML_OS_WINDOWS)
|
||||
target_link_libraries(sfml-window PRIVATE winmm gdi32)
|
||||
elseif(SFML_OS_FREEBSD)
|
||||
|
Loading…
Reference in New Issue
Block a user