Fix and improve generation of fltk-config (#954 and more)

Parts of this commit fix the usage of CMake targets in the generation
process of fltk-config modified by PR #954.

The rest improves handling of variables used to generate fltk-config,
removes obsolete comments, documents variables like GLLIBS etc. which
had to be done anyway.
This commit is contained in:
Albrecht Schlosser 2024-04-14 19:05:39 +02:00
parent 5417ea5f1f
commit b4cf1a9824
4 changed files with 49 additions and 64 deletions

View File

@ -605,11 +605,14 @@ if(FLTK_BUILD_GL)
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 AND PKG_GLU_FOUND))
endif()
endif(FLTK_BACKEND_WAYLAND)
if(FLTK_BACKEND_X11)
set(OPENGL_FOUND TRUE)
find_library(OPENGL_LIB GL)
@ -628,7 +631,7 @@ if(FLTK_BUILD_GL)
set(HAVE_GL_GLU_H ${HAVE_OPENGL_GLU_H})
endif(APPLE)
endif(FLTK_BACKEND_X11)
else()
else(FLTK_BUILD_GL)
set(OPENGL_FOUND FALSE)
set(HAVE_GL FALSE)
set(HAVE_GL_GLU_H FALSE)
@ -641,24 +644,32 @@ mark_as_advanced(OPENGL_LIB) # internal cache variable, not relevant for users
# from the cache above. It has been marked "advanced" before in resources.cmake.
mark_as_advanced(HAVE_GL_GLU_H)
# Note: GLLIBS is a CMake 'list' and is used exclusively to generate fltk-config !
# FIXME, this should be improved!
# We should probably deduct this from OPENGL_LIBRARIES but it turned
# out to be difficult since FindOpenGL seems to return different
# syntax depending on the platform (and maybe also CMake version).
# Hence we use the following code...
set(GLLIBS)
set(FLTK_GL_FOUND FALSE)
if(OPENGL_FOUND)
set(FLTK_GL_FOUND TRUE)
find_path(OPENGL_GLU_INCLUDE_DIR NAMES GL/glu.h OpenGL/glu.h HINTS ${OPENGL_INCLUDE_DIR} ${X11_INCLUDE_DIR})
set(CMAKE_REQUIRED_INCLUDES ${OPENGL_INCLUDE_DIR}/GL ${OPENGL_GLU_INCLUDE_DIR})
# Set GLLIBS (used in fltk-config).
# We should probably deduct this from OPENGL_LIBRARIES but it turned
# out to be difficult since FindOpenGL seems to return different
# syntax depending on the platform (and maybe also CMake version).
# Hence we use the following code...
if(WIN32)
set(GLLIBS "-lglu32 -lopengl32")
list(APPEND GLLIBS -lglu32 -lopengl32)
elseif(APPLE AND NOT FLTK_BACKEND_X11)
set(GLLIBS "-framework OpenGL")
list(APPEND GLLIBS "-framework OpenGL")
elseif(FLTK_BACKEND_WAYLAND)
set(GLLIBS PkgConfig::WLD_EGL PkgConfig::PKG_EGL PkgConfig::PKG_GLU PkgConfig::PKG_GL)
foreach(_lib WLD_EGL PKG_EGL PKG_GLU PKG_GL)
list(APPEND GLLIBS ${${_lib}_LDFLAGS})
endforeach(_lib )
else()
set(GLLIBS "-lGLU -lGL")
list(APPEND GLLIBS -lGLU -lGL)
endif(WIN32)
# check if function glXGetProcAddressARB exists
@ -667,11 +678,6 @@ if(OPENGL_FOUND)
check_function_exists(glXGetProcAddressARB HAVE_GLXGETPROCADDRESSARB)
set(CMAKE_REQUIRED_LIBRARIES ${TEMP_REQUIRED_LIBRARIES})
unset(TEMP_REQUIRED_LIBRARIES)
set(FLTK_GL_FOUND TRUE)
else()
set(FLTK_GL_FOUND FALSE)
set(GLLIBS)
endif(OPENGL_FOUND)
#######################################################################
@ -861,10 +867,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 PkgConfig::PANGOXFT)
list(APPEND FLTK_LDLIBS ${PANGOXFT_LDFLAGS})
endif(USE_PANGOXFT)
list(APPEND FLTK_LDLIBS PkgConfig::PANGOCAIRO)
list(REMOVE_DUPLICATES FLTK_LDLIBS)
list(APPEND FLTK_LDLIBS ${PANGOCAIRO_LDFLAGS})
# *FIXME* Libraries should not be added explicitly if possible
if(FLTK_BACKEND_WAYLAND AND FLTK_USE_LIBDECOR_GTK AND NOT USE_SYSTEM_LIBDECOR)
@ -874,8 +879,6 @@ if((X11_Xft_FOUND OR NOT USE_PANGOXFT) AND FLTK_USE_PANGO)
list(APPEND FLTK_LDLIBS -lX11)
endif()
list(REMOVE_DUPLICATES FLTK_LDLIBS)
if(APPLE)
get_filename_component(PANGO_L_PATH ${HAVE_LIB_PANGO} PATH)
set(LDFLAGS "${LDFLAGS} -L${PANGO_L_PATH}")

View File

@ -83,10 +83,8 @@ set(FLTK_BUILD_INCLUDE_DIRECTORIES)
set(FLTK_LDLIBS "")
set(FLTK_LIBRARIES "")
set(GLLIBS "")
set(IMAGELIBS "")
set(LDFLAGS "")
set(LIBS "")
set(LINK_LIBS "")
set(STATICIMAGELIBS "")

View File

@ -24,7 +24,6 @@ if(DEBUG_VARIABLES_CMAKE)
fl_debug_var(CMAKE_DL_LIBS)
fl_debug_var(CMAKE_EXE_LINKER_FLAGS)
fl_debug_var(LDFLAGS)
fl_debug_var(LIBS)
fl_debug_var(GLLIBS)
fl_debug_var(IMAGELIBS)
fl_debug_var(STATICIMAGELIBS)
@ -45,9 +44,11 @@ if(WIN32)
elseif(APPLE AND NOT FLTK_BACKEND_X11)
list(APPEND FLTK_LDLIBS ${FLTK_COCOA_FRAMEWORKS})
elseif(FLTK_BACKEND_WAYLAND)
list(APPEND FLTK_LDLIBS PkgConfig::WLDCURSOR PkgConfig::WLDCLIENT PkgConfig::XKBCOMMON PkgConfig::DBUS)
foreach(_lib WLDCURSOR WLDCLIENT XKBCOMMON DBUS)
list(APPEND FLTK_LDLIBS "${${_lib}_LDFLAGS}")
endforeach()
if(USE_SYSTEM_LIBDECOR)
list(APPEND FLTK_LDLIBS PkgConfig::SYSTEM_LIBDECOR)
list(APPEND FLTK_LDLIBS ${SYSTEM_LIBDECOR_LDFLAGS})
endif(USE_SYSTEM_LIBDECOR)
else()
list(APPEND FLTK_LDLIBS -lm)
@ -115,6 +116,17 @@ else()
endif(LIB_zlib)
endif(FLTK_USE_BUNDLED_ZLIB)
# remove duplicates from CMake "list" variables for fltk-config
list(REMOVE_DUPLICATES GLLIBS)
list(REMOVE_DUPLICATES FLTK_LDLIBS)
list(REMOVE_DUPLICATES IMAGELIBS)
list(REMOVE_DUPLICATES STATICIMAGELIBS)
# convert CMake lists to strings with spaces for fltk-config
string(REPLACE ";" " " GLLIBS "${GLLIBS}")
string(REPLACE ";" " " LIBS "${FLTK_LDLIBS}")
string(REPLACE ";" " " IMAGELIBS "${IMAGELIBS}")
string(REPLACE ";" " " STATICIMAGELIBS "${STATICIMAGELIBS}")
@ -136,12 +148,6 @@ endforeach(arg ${FLTK_CFLAGS})
set(CXXFLAGS "${CFLAGS}")
foreach(arg ${FLTK_LDLIBS})
set(LINK_LIBS "${LINK_LIBS} ${arg}")
endforeach(arg ${FLTK_LDLIBS})
set(LIBS "${LINK_LIBS}")
if(${CMAKE_SYSTEM_NAME} STREQUAL "AIX")
set(SHAREDSUFFIX "_s")
else()
@ -154,11 +160,11 @@ if(DEBUG_VARIABLES_CMAKE)
fl_debug_var(CMAKE_DL_LIBS)
fl_debug_var(CMAKE_EXE_LINKER_FLAGS)
fl_debug_var(LDFLAGS)
fl_debug_var(FLTK_LDLIBS)
fl_debug_var(LIBS)
fl_debug_var(GLLIBS)
fl_debug_var(IMAGELIBS)
fl_debug_var(STATICIMAGELIBS)
fl_debug_var(FLTK_LDLIBS)
fl_debug_var(LIB_jpeg)
fl_debug_var(LIB_png)
fl_debug_var(LIB_zlib)

View File

@ -631,9 +631,12 @@ endif()
#######################################################################
# prepare optional libs for shared and static FLTK libraries
# Prepare optional libs for shared and static FLTK libraries.
# Note: OPTIONAL_LIBS is a CMake 'list' and may contain CMake targets,
# i.e. it is only used for CMake stuff: target_link_libraries().
# FIXME: make this all more consistent (targets rather than libs).
set(OPTIONAL_LIBS)
set(OPTIONAL_LIBS) # init
if(LIB_dl)
list(APPEND OPTIONAL_LIBS ${LIB_dl})
@ -670,10 +673,6 @@ if(HAVE_XRENDER)
list(APPEND OPTIONAL_LIBS ${X11_Xrender_LIB})
endif(HAVE_XRENDER)
### if(FLTK_HAVE_CAIRO) # FLTK_OPTION_CAIRO_WINDOW or FLTK_OPTION_CAIRO_EXT or Wayland
### list(APPEND OPTIONAL_LIBS ${PKG_CAIRO_LIBRARIES})
### endif()
if(USE_PANGO)
### FIXME ### This needs to use the PKG_* variables directly
list(APPEND OPTIONAL_LIBS ${HAVE_LIB_PANGO} PkgConfig::PANGOCAIRO)
@ -772,10 +771,6 @@ endif(UNIX AND FLTK_BACKEND_WAYLAND)
fl_add_library(fltk STATIC "${STATIC_FILES}")
target_link_libraries(fltk PUBLIC ${OPTIONAL_LIBS})
### if(FLTK_HAVE_CAIRO OR FLTK_USE_CAIRO)
### target_link_directories(fltk PUBLIC ${PKG_CAIRO_LIBRARY_DIRS})
### endif()
#######################################################################
if(FLTK_BUILD_FORMS)
@ -798,10 +793,6 @@ fl_add_library(fltk_images STATIC "${IMGCPPFILES}")
target_link_libraries(fltk_images PUBLIC fltk::fltk)
target_link_libraries(fltk_images PRIVATE ${FLTK_IMAGE_LIBRARIES})
### target_link_libraries(fltk_images PUBLIC ${FLTK_JPEG_LIBRARIES})
### target_link_libraries(fltk_images PUBLIC ${FLTK_PNG_LIBRARIES})
### target_link_libraries(fltk_images PUBLIC ${FLTK_IMAGE_LIBRARIES})
if(FLTK_USE_BUNDLED_JPEG)
target_include_directories(fltk_images PUBLIC
$<BUILD_INTERFACE:${FLTK_SOURCE_DIR}/jpeg>
@ -825,17 +816,11 @@ endif(FLTK_USE_GL)
# Shared libraries, part 1: everything except Visual Studio (MSVC)
#######################################################################
### fl_debug_var(OPTIONAL_LIBS)
if(FLTK_BUILD_SHARED_LIBS AND NOT MSVC)
fl_add_library(fltk SHARED "${SHARED_FILES}")
target_link_libraries(fltk-shared PUBLIC ${OPTIONAL_LIBS})
### if(FLTK_HAVE_CAIRO OR FLTK_USE_CAIRO)
### target_link_directories(fltk-shared PUBLIC ${PKG_CAIRO_LIBRARY_DIRS})
### endif()
###################################################################
if(FLTK_BUILD_FORMS)
@ -845,12 +830,6 @@ if(FLTK_BUILD_SHARED_LIBS AND NOT MSVC)
###################################################################
### fl_debug_var(fltk_images)
### fl_debug_var(FLTK_JPEG_LIBRARIES)
### fl_debug_var(FLTK_PNG_LIBRARIES)
### fl_debug_var(FLTK_ZLIB_LIBRARIES)
### fl_debug_var(FLTK_IMAGE_LIBRARIES)
fl_add_library(fltk_images SHARED "${IMGCPPFILES}")
target_link_libraries(fltk_images-shared PUBLIC fltk::fltk-shared)
@ -859,7 +838,6 @@ if(FLTK_BUILD_SHARED_LIBS AND NOT MSVC)
target_link_libraries(fltk_images PUBLIC ${FLTK_IMAGE_LIBRARIES})
if(FLTK_USE_BUNDLED_JPEG)
## include_directories(${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(fltk_images-shared PUBLIC
$<BUILD_INTERFACE:${FLTK_SOURCE_DIR}/jpeg>
# $<INSTALL_INTERFACE:include>