|
|
commit 5417ea5f1f33f62e2511bda74477da05dce900a3
Author: Jordan Williams <jordan@jwillikers.com>
AuthorDate: Sun Apr 14 12:07:15 2024 -0500
Commit: GitHub <noreply@github.com>
CommitDate: Sun Apr 14 19:07:15 2024 +0200
CMake: Use imported targets for PkgConfig packages (#954)
This carries include directories and the required link flags.
Several libraries brought in through pkg_check_modules aren't linked correctly using the _LDFLAGS variables.
Instead, they link the libraries directly with `-l`.
This is problematic because it doesn't properly pull in the actual directory of the library being linked when it is not in a system library directory.
Likewise, the necessary include directories for several of these targets aren't properly set either.
Linking against the imported targets automatically pulls in the necessary include directories.
CMake/options.cmake | 37 +++++++++++++++++++------------------
CMake/variables.cmake | 4 ++--
src/CMakeLists.txt | 18 +++++++++---------
3 files changed, 30 insertions(+), 29 deletions(-)
diff --git CMake/options.cmake CMake/options.cmake
index fb7ce56..45ece76 100644
--- CMake/options.cmake
+++ CMake/options.cmake
@@ -273,10 +273,10 @@ if(UNIX)
option(FLTK_BACKEND_WAYLAND "support the Wayland backend" ON)
endif(NOT APPLE)
if(FLTK_BACKEND_WAYLAND)
- pkg_check_modules(WLDCLIENT wayland-client>=1.18)
- pkg_check_modules(WLDCURSOR wayland-cursor)
- pkg_check_modules(WLDPROTO wayland-protocols>=1.15)
- pkg_check_modules(XKBCOMMON xkbcommon)
+ pkg_check_modules(WLDCLIENT IMPORTED_TARGET wayland-client>=1.18)
+ pkg_check_modules(WLDCURSOR IMPORTED_TARGET wayland-cursor)
+ pkg_check_modules(WLDPROTO IMPORTED_TARGET wayland-protocols>=1.15)
+ pkg_check_modules(XKBCOMMON IMPORTED_TARGET xkbcommon)
if(NOT(WLDCLIENT_FOUND AND WLDCURSOR_FOUND AND WLDPROTO_FOUND AND XKBCOMMON_FOUND))
message(STATUS "Not all software modules 'wayland-client>=1.18 wayland-cursor wayland-protocols>=1.15 xkbcommon' are present")
message(STATUS "Consequently, FLTK_BACKEND_WAYLAND is turned off.")
@@ -333,7 +333,7 @@ if(UNIX)
unset(FLTK_USE_PANGO CACHE)
set(FLTK_USE_PANGO TRUE CACHE BOOL "use lib Pango")
if(FLTK_USE_SYSTEM_LIBDECOR)
- pkg_check_modules(SYSTEM_LIBDECOR libdecor-0>0.2.2 QUIET)
+ pkg_check_modules(SYSTEM_LIBDECOR IMPORTED_TARGET libdecor-0>0.2.2 QUIET)
if(NOT SYSTEM_LIBDECOR_FOUND)
message(STATUS "Warning: system libdecor doesn't satisfy version > 0.2.2,")
message(STATUS " using bundled libdecor library instead.")
@@ -601,13 +601,14 @@ endif()
if(FLTK_BUILD_GL)
if(FLTK_BACKEND_WAYLAND)
- pkg_check_modules(WLD_EGL wayland-egl)
- pkg_check_modules(PKG_EGL egl)
- pkg_check_modules(PKG_GL gl)
- if(NOT (WLD_EGL_FOUND AND PKG_EGL_FOUND AND PKG_GL_FOUND))
- message(STATUS "Modules 'wayland-egl, egl, and gl' are required to build for the Wayland backend.")
+ pkg_check_modules(WLD_EGL IMPORTED_TARGET wayland-egl)
+ pkg_check_modules(PKG_EGL IMPORTED_TARGET egl)
+ pkg_check_modules(PKG_GL IMPORTED_TARGET gl)
+ pkg_check_modules(PKG_GLU IMPORTED_TARGET glu)
+ if(NOT (WLD_EGL_FOUND AND PKG_EGL_FOUND AND PKG_GL_FOUND AND PKG_GLU_FOUND))
+ message(STATUS "Modules 'wayland-egl, egl, gl, and glu' are required to build for the Wayland backend.")
message(FATAL_ERROR "*** Aborting ***")
- endif(NOT (WLD_EGL_FOUND AND PKG_EGL_FOUND AND PKG_GL_FOUND))
+ endif(NOT (WLD_EGL_FOUND AND PKG_EGL_FOUND AND PKG_GL_FOUND AND PKG_GLU_FOUND))
endif(FLTK_BACKEND_WAYLAND)
if(FLTK_BACKEND_X11)
set(OPENGL_FOUND TRUE)
@@ -655,7 +656,7 @@ if(OPENGL_FOUND)
elseif(APPLE AND NOT FLTK_BACKEND_X11)
set(GLLIBS "-framework OpenGL")
elseif(FLTK_BACKEND_WAYLAND)
- set(GLLIBS "-lwayland-egl -lEGL -lGLU -lGL")
+ set(GLLIBS PkgConfig::WLD_EGL PkgConfig::PKG_EGL PkgConfig::PKG_GLU PkgConfig::PKG_GL)
else()
set(GLLIBS "-lGLU -lGL")
endif(WIN32)
@@ -825,11 +826,11 @@ endif(USE_PANGOXFT)
#######################################################################
if((X11_Xft_FOUND OR NOT USE_PANGOXFT) AND FLTK_USE_PANGO)
- pkg_check_modules(CAIRO cairo)
+ pkg_check_modules(CAIRO IMPORTED_TARGET cairo)
if(USE_PANGOXFT)
- pkg_check_modules(PANGOXFT pangoxft)
+ pkg_check_modules(PANGOXFT IMPORTED_TARGET pangoxft)
endif(USE_PANGOXFT)
- pkg_check_modules(PANGOCAIRO pangocairo)
+ pkg_check_modules(PANGOCAIRO IMPORTED_TARGET pangocairo)
if((PANGOXFT_FOUND OR NOT USE_PANGOXFT) AND PANGOCAIRO_FOUND AND CAIRO_FOUND)
if(USE_PANGOXFT)
@@ -860,9 +861,9 @@ if((X11_Xft_FOUND OR NOT USE_PANGOXFT) AND FLTK_USE_PANGO)
# add required libraries to fltk-config ...
if(USE_PANGOXFT)
- list(APPEND FLTK_LDLIBS ${PANGOXFT_LDFLAGS})
+ list(APPEND FLTK_LDLIBS PkgConfig::PANGOXFT)
endif(USE_PANGOXFT)
- list(APPEND FLTK_LDLIBS ${PANGOCAIRO_LDFLAGS})
+ list(APPEND FLTK_LDLIBS PkgConfig::PANGOCAIRO)
list(REMOVE_DUPLICATES FLTK_LDLIBS)
# *FIXME* Libraries should not be added explicitly if possible
@@ -936,7 +937,7 @@ if(FLTK_BACKEND_WAYLAND)
# Note: Disable FLTK_USE_LIBDECOR_GTK to get cairo titlebars rather than GTK
if(FLTK_USE_LIBDECOR_GTK)
- pkg_check_modules(GTK gtk+-3.0)
+ pkg_check_modules(GTK IMPORTED_TARGET gtk+-3.0)
if(GTK_FOUND)
list(APPEND FLTK_BUILD_INCLUDE_DIRECTORIES ${GTK_INCLUDE_DIRS})
else()
diff --git CMake/variables.cmake CMake/variables.cmake
index cbf6ffd..20a36ed 100644
--- CMake/variables.cmake
+++ CMake/variables.cmake
@@ -45,9 +45,9 @@ if(WIN32)
elseif(APPLE AND NOT FLTK_BACKEND_X11)
list(APPEND FLTK_LDLIBS ${FLTK_COCOA_FRAMEWORKS})
elseif(FLTK_BACKEND_WAYLAND)
- list(APPEND FLTK_LDLIBS "-lwayland-cursor -lwayland-client -lxkbcommon -ldbus-1")
+ list(APPEND FLTK_LDLIBS PkgConfig::WLDCURSOR PkgConfig::WLDCLIENT PkgConfig::XKBCOMMON PkgConfig::DBUS)
if(USE_SYSTEM_LIBDECOR)
- list(APPEND FLTK_LDLIBS "-ldecor-0")
+ list(APPEND FLTK_LDLIBS PkgConfig::SYSTEM_LIBDECOR)
endif(USE_SYSTEM_LIBDECOR)
else()
list(APPEND FLTK_LDLIBS -lm)
diff --git src/CMakeLists.txt src/CMakeLists.txt
index b12880c..326fb5d 100644
--- src/CMakeLists.txt
+++ src/CMakeLists.txt
@@ -535,7 +535,7 @@ if(FLTK_USE_X11)
endif(FLTK_USE_X11)
if(FLTK_BACKEND_WAYLAND)
- pkg_check_modules(DBUS dbus-1)
+ pkg_check_modules(DBUS IMPORTED_TARGET dbus-1)
set(IDIRS "${CMAKE_CURRENT_BINARY_DIR}")
set(CDEFS "_GNU_SOURCE;HAVE_MEMFD_CREATE;HAVE_MKOSTEMP;HAVE_POSIX_FALLOCATE")
set(COPTS "-fPIC")
@@ -676,10 +676,10 @@ endif(HAVE_XRENDER)
if(USE_PANGO)
### FIXME ### This needs to use the PKG_* variables directly
- list(APPEND OPTIONAL_LIBS ${HAVE_LIB_PANGO} ${HAVE_LIB_PANGOCAIRO})
- list(APPEND OPTIONAL_LIBS ${HAVE_LIB_CAIRO} ${HAVE_LIB_GOBJECT})
+ list(APPEND OPTIONAL_LIBS ${HAVE_LIB_PANGO} PkgConfig::PANGOCAIRO)
+ list(APPEND OPTIONAL_LIBS PkgConfig::CAIRO ${HAVE_LIB_GOBJECT})
if(USE_PANGOXFT)
- list(APPEND OPTIONAL_LIBS ${HAVE_LIB_PANGOXFT})
+ list(APPEND OPTIONAL_LIBS PkgConfig::PANGOXFT)
endif(USE_PANGOXFT)
endif(USE_PANGO)
@@ -754,16 +754,16 @@ if(UNIX AND FLTK_BACKEND_WAYLAND)
endif()
if(FLTK_USE_GL)
- list(APPEND OPTIONAL_LIBS "-lwayland-egl -lEGL")
+ list(APPEND OPTIONAL_LIBS PkgConfig::WLD_EGL PkgConfig::PKG_EGL)
endif(FLTK_USE_GL)
if(USE_SYSTEM_LIBDECOR)
- list(APPEND OPTIONAL_LIBS "-ldecor-0")
+ list(APPEND OPTIONAL_LIBS PkgConfig::SYSTEM_LIBDECOR)
elseif(GTK_FOUND AND FLTK_USE_LIBDECOR_GTK)
- list(APPEND OPTIONAL_LIBS ${GTK_LDFLAGS} )
+ list(APPEND OPTIONAL_LIBS PkgConfig::GTK)
endif(USE_SYSTEM_LIBDECOR)
- list(APPEND OPTIONAL_LIBS "-lwayland-cursor -lwayland-client -lxkbcommon -ldl")
+ list(APPEND OPTIONAL_LIBS PkgConfig::WLDCURSOR PkgConfig::WLDCLIENT PkgConfig::XKBCOMMON -ldl)
if(DBUS_FOUND)
- list(APPEND OPTIONAL_LIBS "${DBUS_LDFLAGS}")
+ list(APPEND OPTIONAL_LIBS PkgConfig::DBUS)
endif(DBUS_FOUND)
endif(UNIX AND FLTK_BACKEND_WAYLAND)
[ Direct Link to Message ] | |
|
| |