Improve libpng header search (notably on macOS)

Fix usage of internal cache variables so users can switch between
system and builtin libpng reliably.
This commit is contained in:
Albrecht Schlosser 2022-04-03 23:34:09 +02:00
parent 9a7af11108
commit 5a8b9d9130
2 changed files with 27 additions and 8 deletions

View File

@ -435,11 +435,33 @@ if (OPTION_USE_SYSTEM_LIBPNG)
endif ()
if (OPTION_USE_SYSTEM_LIBPNG AND PNG_FOUND)
set (FLTK_USE_BUILTIN_PNG FALSE)
set (FLTK_PNG_LIBRARIES ${PNG_LIBRARIES})
include_directories (${PNG_INCLUDE_DIR})
include_directories (${PNG_INCLUDE_DIRS})
add_definitions (${PNG_DEFINITIONS})
else()
set (_INCLUDE_SAVED ${CMAKE_REQUIRED_INCLUDES})
list (APPEND CMAKE_REQUIRED_INCLUDES ${PNG_INCLUDE_DIRS})
# FIXME - Force search! Maybe use cache to check for option changes?
unset (HAVE_PNG_H CACHE)
unset (HAVE_LIBPNG_PNG_H CACHE)
check_include_files (png.h HAVE_PNG_H)
mark_as_advanced (HAVE_PNG_H)
if (NOT HAVE_PNG_H)
check_include_files (libpng/png.h HAVE_LIBPNG_PNG_H)
mark_as_advanced (HAVE_LIBPNG_PNG_H)
endif ()
set (CMAKE_REQUIRED_INCLUDES ${_INCLUDE_SAVED})
unset (_INCLUDE_SAVED)
else ()
if (OPTION_USE_SYSTEM_LIBPNG)
message (STATUS "cannot find system png library - using built-in\n")
endif ()
@ -450,11 +472,10 @@ else()
set (HAVE_PNG_H 1)
set (HAVE_PNG_GET_VALID 1)
set (HAVE_PNG_SET_TRNS_TO_ALPHA 1)
set (HAVE_LIBPNG_PNG_H 0)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/png)
endif ()
set (HAVE_LIBPNG 1)
#######################################################################
if (X11_Xinerama_FOUND)
option (OPTION_USE_XINERAMA "use lib Xinerama" ON)

View File

@ -52,10 +52,8 @@ include (FindPkgConfig)
fl_find_header (HAVE_ALSA_ASOUNDLIB_H alsa/asoundlib.h)
fl_find_header (HAVE_DLFCN_H dlfcn.h)
fl_find_header (HAVE_GL_GLU_H GL/glu.h)
fl_find_header (HAVE_LIBPNG_PNG_H libpng/png.h)
fl_find_header (HAVE_LOCALE_H locale.h)
fl_find_header (HAVE_OPENGL_GLU_H OpenGL/glu.h)
fl_find_header (HAVE_PNG_H png.h)
fl_find_header (HAVE_STDIO_H stdio.h)
fl_find_header (HAVE_STRINGS_H strings.h)
fl_find_header (HAVE_SYS_SELECT_H sys/select.h)
@ -128,8 +126,8 @@ endif (NOT HAVE_DIRENT_H)
mark_as_advanced (HAVE_ALSA_ASOUNDLIB_H HAVE_DIRENT_H HAVE_DLFCN_H)
mark_as_advanced (HAVE_GL_GLU_H)
mark_as_advanced (HAVE_LIBPNG_PNG_H HAVE_LOCALE_H HAVE_NDIR_H)
mark_as_advanced (HAVE_OPENGL_GLU_H HAVE_PNG_H)
mark_as_advanced (HAVE_OPENGL_GLU_H)
mark_as_advanced (HAVE_LOCALE_H HAVE_NDIR_H)
mark_as_advanced (HAVE_PTHREAD_H HAVE_PTHREAD_MUTEX_RECURSIVE)
mark_as_advanced (HAVE_STDIO_H HAVE_STRINGS_H HAVE_SYS_DIR_H)
mark_as_advanced (HAVE_SYS_NDIR_H HAVE_SYS_SELECT_H)