Skip to content

Commit

Permalink
CMake: add target_include_directories() for optional libs (#954)
Browse files Browse the repository at this point in the history
This ensures that header files for libraries found by `pkg-config`
(pkg_check_modules) in non-system directories will be found by the
compiler during the compilation of the FLTK library.

This issue has been reported in PR #954 related to builds with Conan
where some header files are not in system locations.
  • Loading branch information
Albrecht Schlosser committed Apr 21, 2024
1 parent 43ab34d commit 89b9575
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -638,12 +638,17 @@ endif()
#
# Prepare optional libs for shared and static FLTK libraries.
#
# Note: 'OPTIONAL_LIBS' is a CMake 'list' but must not contain arbitrary
# Notes:
# - 'OPTIONAL_LIBS' is a CMake 'list' but must not contain arbitrary
# CMake targets because these targets would be propagated to
# consumer projects. The macro below simplifies adding link
# libraries of such targets to 'OPTIONAL_LIBS'.
# - 'OPTIONAL_INCLUDES' is a similar CMake list that defines additional
# include directories.
#
# This macro appends link libraries to 'OPTIONAL_LIBS' and include
# directories to 'OPTIONAL_INCLUDES'.
#
# This macro appends interface targets to 'OPTIONAL_LIBS'.
# Input:
# 'targets' may be a CMake list of targets or a single target.
# It must be quoted if multiple targets are to be added in
Expand All @@ -654,14 +659,19 @@ endif()
macro(append_optional_libs targets)
foreach(_target ${targets})
get_target_property(_link_libraries ${_target} INTERFACE_LINK_LIBRARIES)
get_target_property(_include_dirs ${_target} INTERFACE_INCLUDE_DIRECTORIES)
list(APPEND OPTIONAL_LIBS ${_link_libraries})
list(APPEND OPTIONAL_LIBS )
if(_include_dirs)
list(APPEND OPTIONAL_INCLUDES ${_include_dirs})
endif()
endforeach()
unset(_target)
unset(_link_libraries)
unset(_include_dirs)
endmacro()

set(OPTIONAL_LIBS)
set(OPTIONAL_INCLUDES)

if(LIB_dl)
list(APPEND OPTIONAL_LIBS ${LIB_dl})
Expand Down Expand Up @@ -796,11 +806,13 @@ if(UNIX AND FLTK_BACKEND_WAYLAND)
endif(UNIX AND FLTK_BACKEND_WAYLAND)

list(REMOVE_DUPLICATES OPTIONAL_LIBS)
list(REMOVE_DUPLICATES OPTIONAL_INCLUDES)

#######################################################################

fl_add_library(fltk STATIC "${STATIC_FILES}")
target_link_libraries(fltk PRIVATE ${OPTIONAL_LIBS})
target_include_directories(fltk PRIVATE ${OPTIONAL_INCLUDES})

#######################################################################

Expand Down Expand Up @@ -851,6 +863,7 @@ if(FLTK_BUILD_SHARED_LIBS AND NOT MSVC)

fl_add_library(fltk SHARED "${SHARED_FILES}")
target_link_libraries(fltk-shared PRIVATE ${OPTIONAL_LIBS})
target_include_directories(fltk-shared PRIVATE ${OPTIONAL_INCLUDES})

###################################################################

Expand Down Expand Up @@ -920,6 +933,7 @@ if(FLTK_BUILD_SHARED_LIBS AND MSVC)

fl_add_library(fltk SHARED "${SOURCES}")
target_link_libraries(fltk-shared PRIVATE ${OPTIONAL_LIBS})
target_include_directories(fltk-shared PRIVATE ${OPTIONAL_INCLUDES})

if(FLTK_USE_BUNDLED_JPEG)
target_link_libraries(fltk-shared PUBLIC fltk::jpeg-shared)
Expand Down

0 comments on commit 89b9575

Please sign in to comment.