Compare commits

...
1 Commits
Author SHA1 Message Date
Clifford Yapp 0d8b619114 See if we can use Config.cmake approach to find_package for zlib and png.
Depends on the bext zlib CMake logic being patched to provide the
necessary files.  Once this proves out, we should be able to avoid
patching a lot of bext dependency builds to add custom FindZLIB.cmake
and FindPNG.cmake modules - instead we can just make sure
CMAKE_FIND_PACKAGE_PREFER_CONFIG is set to ON.
2026-07-09 18:39:44 +00:00
6 changed files with 24 additions and 391 deletions
+19 -6
View File
@@ -1066,6 +1066,9 @@ endfunction(brlcad_bext_process)
# it's more complicated.
#####################################################################
# Prefer the Config.cmake file, if it can be found
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
# Not all packages will define all of these, but it shouldn't matter -
# an unset of an unused variable shouldn't be harmful
function(find_package_reset pname trigger_var)
@@ -1103,17 +1106,27 @@ macro(find_package_zlib)
else()
find_package(ZLIB)
endif()
if(ZLIB_FOUND AND ZLIB_LIBRARIES)
list(GET ZLIB_LIBRARIES 0 ZLIB_FILE)
if (TARGET ZLIB::ZLIB)
get_target_property(ZLIB_FILE ZLIB::ZLIB LOCATION)
if (NOT ZLIB_FILE)
get_target_property(llibs ZLIB::ZLIB INTERFACE_LINK_LIBRARIES)
foreach(ll ${llibs})
if("${ll}" MATCHES "zlib::.*")
if (NOT ZLIB_FILE)
get_target_property(ZLIB_FILE ${ll} LOCATION)
endif()
endif()
endforeach(ll ${llibs})
endif()
is_subpath("${CMAKE_BINARY_DIR}" "${ZLIB_FILE}" ZLIB_LOCAL_TEST)
if(ZLIB_LOCAL_TEST)
set(Z_PREFIX_STR "brl_" CACHE STRING "Using local zlib" FORCE)
set(ZLIB_STATUS "Bundled" CACHE STRING "Zlib bundled status" FORCE)
else()
set(ZLIB_STATUS "System" CACHE STRING "Zlib bundled status" FORCE)
set(ZLIB_STATUS "Bundled" CACHE STRING "zlib is bundled" FORCE)
else(ZLIB_LOCAL_TEST)
set(ZLIB_STATUS "System" CACHE STRING "zlib is system" FORCE)
endif(ZLIB_LOCAL_TEST)
else()
set(ZLIB_STATUS "NotFound" CACHE STRING "Zlib bundled status" FORCE)
set(ZLIB_STATUS "NotFound" CACHE STRING "zlib is not found" FORCE)
endif()
endmacro(find_package_zlib)
+3
View File
@@ -136,6 +136,9 @@ macro(brlcad_find_package pkg_name)
# otherwise, everything goes on to find package.
cmake_parse_arguments(F "NOINSTALL" "SYSPATTERN" "" ${ARGN})
# Prefer the Config.cmake file, if it can be found.
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
# If we have a bundled copy of this package, always use that. Packages we
# are not going to install are not copied to CMAKE_BINARY_DIR, so set the
# *_ROOT variable accordingly
+1
View File
@@ -276,6 +276,7 @@ function(BRLCAD_Summary)
ext_report("STEPcode" STEPCODE_STATUS REQUIRED_VARS "BRLCAD_ENABLE_STEP")
ext_report("Tcl" TCL_LIBRARY REQUIRED_VARS "BRLCAD_ENABLE_TCL")
ext_report("Tk" TK_LIBRARY REQUIRED_VARS "BRLCAD_ENABLE_TCL")
ext_report("UtahRLE" UTAHRLE_STATUS)
ext_report("Zlib" ZLIB_STATUS)
# Find the maximum label length
+1 -2
View File
@@ -50,7 +50,6 @@ set(
FindOpenVDB.cmake
FindPERPLEX.cmake
FindPkgMacros.cmake
FindPNG.cmake
FindPROJ4.cmake
FindRE2C.cmake
FindREGEX.cmake
@@ -64,7 +63,7 @@ set(
FindUUID.cmake
FindWix.cmake
FindXMLLINT.cmake
FindZLIB.cmake
FindXSLTPROC.cmake
NSIS.template.in
NSIS_silent.template.in
OpenVDBUtils.cmake
-193
View File
@@ -1,193 +0,0 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
FindPNG
-------
Find libpng, the official reference library for the PNG image format.
Imported targets
^^^^^^^^^^^^^^^^
.. versionadded:: 3.5
This module defines the following :prop_tgt:`IMPORTED` target:
``PNG::PNG``
The libpng library, if found.
Result variables
^^^^^^^^^^^^^^^^
This module will set the following variables in your project:
``PNG_INCLUDE_DIRS``
where to find png.h, etc.
``PNG_LIBRARIES``
the libraries to link against to use PNG.
``PNG_DEFINITIONS``
You should add_definitions(${PNG_DEFINITIONS}) before compiling code
that includes png library files.
``PNG_FOUND``
If false, do not try to use PNG.
``PNG_VERSION_STRING``
the version of the PNG library found (since CMake 2.8.8)
Obsolete variables
^^^^^^^^^^^^^^^^^^
The following variables may also be set, for backwards compatibility:
``PNG_LIBRARY``
where to find the PNG library.
``PNG_INCLUDE_DIR``
where to find the PNG headers (same as PNG_INCLUDE_DIRS)
Since PNG depends on the ZLib compression library, none of the above
will be defined unless ZLib can be found.
#]=======================================================================]
if(PNG_FIND_QUIETLY)
set(_FIND_ZLIB_ARG QUIET)
endif()
find_package(ZLIB ${_FIND_ZLIB_ARG})
if(ZLIB_FOUND)
find_path(PNG_PNG_INCLUDE_DIR png.h PATH_SUFFIXES include/libpng)
mark_as_advanced(PNG_PNG_INCLUDE_DIR)
list(APPEND PNG_NAMES png_brl libpng_brl png libpng)
unset(PNG_NAMES_DEBUG)
set(
_PNG_VERSION_SUFFIXES
17
16
15
14
12
)
if(PNG_FIND_VERSION MATCHES "^([0-9]+)\\.([0-9]+)(\\..*)?$")
set(_PNG_VERSION_SUFFIX_MIN "${CMAKE_MATCH_1}${CMAKE_MATCH_2}")
if(PNG_FIND_VERSION_EXACT)
set(_PNG_VERSION_SUFFIXES ${_PNG_VERSION_SUFFIX_MIN})
else()
string(
REGEX REPLACE
"${_PNG_VERSION_SUFFIX_MIN}.*"
"${_PNG_VERSION_SUFFIX_MIN}"
_PNG_VERSION_SUFFIXES
"${_PNG_VERSION_SUFFIXES}"
)
endif()
unset(_PNG_VERSION_SUFFIX_MIN)
endif()
foreach(v IN LISTS _PNG_VERSION_SUFFIXES)
list(
APPEND
PNG_NAMES
png_brl${v}
libpng_brl${v}
png${v}
libpng${v}
libpng${v}_static
)
list(
APPEND
PNG_NAMES_DEBUG
png_brl${v}d
libpng_brl${v}d
png${v}d
libpng${v}d
libpng${v}_staticd
)
endforeach()
unset(_PNG_VERSION_SUFFIXES)
# For compatibility with versions prior to this multi-config search, honor
# any PNG_LIBRARY that is already specified and skip the search.
if(NOT PNG_LIBRARY)
find_library(PNG_LIBRARY_RELEASE NAMES ${PNG_NAMES} NAMES_PER_DIR)
find_library(PNG_LIBRARY_DEBUG NAMES ${PNG_NAMES_DEBUG} NAMES_PER_DIR)
include(SelectLibraryConfigurations)
select_library_configurations(PNG)
mark_as_advanced(PNG_LIBRARY_RELEASE PNG_LIBRARY_DEBUG)
endif()
unset(PNG_NAMES)
unset(PNG_NAMES_DEBUG)
# Set by select_library_configurations(), but we want the one from
# find_package_handle_standard_args() below.
unset(PNG_FOUND)
if(PNG_LIBRARY AND PNG_PNG_INCLUDE_DIR)
# png.h includes zlib.h. Sigh.
set(PNG_INCLUDE_DIRS ${PNG_PNG_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR})
set(PNG_INCLUDE_DIR ${PNG_INCLUDE_DIRS}) # for backward compatibility
set(PNG_LIBRARIES ${PNG_LIBRARY} ${ZLIB_LIBRARY})
if((CMAKE_SYSTEM_NAME STREQUAL "Linux") AND ("${PNG_LIBRARY}" MATCHES "\\${CMAKE_STATIC_LIBRARY_SUFFIX}$"))
list(APPEND PNG_LIBRARIES m)
endif()
if(CYGWIN)
if(BUILD_SHARED_LIBS)
# No need to define PNG_USE_DLL here, because it's default for Cygwin.
else()
set(PNG_DEFINITIONS -DPNG_STATIC)
set(_PNG_COMPILE_DEFINITIONS PNG_STATIC)
endif()
endif()
if(NOT TARGET PNG::PNG)
add_library(PNG::PNG UNKNOWN IMPORTED GLOBAL)
set_target_properties(
PNG::PNG
PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "${_PNG_COMPILE_DEFINITIONS}"
INTERFACE_INCLUDE_DIRECTORIES "${PNG_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES ZLIB::ZLIB
)
if((CMAKE_SYSTEM_NAME STREQUAL "Linux") AND ("${PNG_LIBRARY}" MATCHES "\\${CMAKE_STATIC_LIBRARY_SUFFIX}$"))
set_property(TARGET PNG::PNG APPEND PROPERTY INTERFACE_LINK_LIBRARIES m)
endif()
if(EXISTS "${PNG_LIBRARY}")
set_target_properties(
PNG::PNG
PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" IMPORTED_LOCATION "${PNG_LIBRARY}"
)
endif()
if(EXISTS "${PNG_LIBRARY_RELEASE}")
set_property(TARGET PNG::PNG APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(
PNG::PNG
PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C" IMPORTED_LOCATION_RELEASE "${PNG_LIBRARY_RELEASE}"
)
endif()
if(EXISTS "${PNG_LIBRARY_DEBUG}")
set_property(TARGET PNG::PNG APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(
PNG::PNG
PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C" IMPORTED_LOCATION_DEBUG "${PNG_LIBRARY_DEBUG}"
)
endif()
endif()
unset(_PNG_COMPILE_DEFINITIONS)
endif()
if(PNG_PNG_INCLUDE_DIR AND EXISTS "${PNG_PNG_INCLUDE_DIR}/png.h")
file(STRINGS "${PNG_PNG_INCLUDE_DIR}/png.h" png_version_str REGEX "^#define[ \t]+PNG_LIBPNG_VER_STRING[ \t]+\".+\"")
string(
REGEX REPLACE
"^#define[ \t]+PNG_LIBPNG_VER_STRING[ \t]+\"([^\"]+)\".*"
"\\1"
PNG_VERSION_STRING
"${png_version_str}"
)
unset(png_version_str)
endif()
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(PNG REQUIRED_VARS PNG_LIBRARY PNG_PNG_INCLUDE_DIR VERSION_VAR PNG_VERSION_STRING)
-190
View File
@@ -1,190 +0,0 @@
#.rst:
# FindZLIB
# --------
#
# Find the native ZLIB includes and library.
#
# IMPORTED Targets
# ^^^^^^^^^^^^^^^^
#
# This module defines :prop_tgt:`IMPORTED` target ``ZLIB::ZLIB``, if
# ZLIB has been found.
#
# Result Variables
# ^^^^^^^^^^^^^^^^
#
# This module defines the following variables:
#
# ::
#
# ZLIB_INCLUDE_DIRS - where to find zlib.h, etc.
# ZLIB_LIBRARIES - List of libraries when using zlib.
# ZLIB_FOUND - True if zlib found.
#
# ::
#
# ZLIB_VERSION_STRING - The version of zlib found (x.y.z)
# ZLIB_VERSION_MAJOR - The major version of zlib
# ZLIB_VERSION_MINOR - The minor version of zlib
# ZLIB_VERSION_PATCH - The patch version of zlib
# ZLIB_VERSION_TWEAK - The tweak version of zlib
#
# Backward Compatibility
# ^^^^^^^^^^^^^^^^^^^^^^
#
# The following variable are provided for backward compatibility
#
# ::
#
# ZLIB_MAJOR_VERSION - The major version of zlib
# ZLIB_MINOR_VERSION - The minor version of zlib
# ZLIB_PATCH_VERSION - The patch version of zlib
#
# Hints
# ^^^^^
#
# A user may set ``ZLIB_ROOT`` to a zlib installation root to tell this
# module where to look.
#=============================================================================
# Copyright 2001-2011 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
set(_ZLIB_SEARCHES)
# Search ZLIB_ROOT first if it is set.
if(ZLIB_ROOT)
set(_ZLIB_SEARCH_ROOT PATHS ${ZLIB_ROOT} NO_DEFAULT_PATH)
list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_ROOT)
endif()
# Normal search.
set(_ZLIB_SEARCH_NORMAL PATHS "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Zlib;InstallPath]" "$ENV{PROGRAMFILES}/zlib")
list(APPEND _ZLIB_SEARCHES _ZLIB_SEARCH_NORMAL)
set(
ZLIB_NAMES
z_brl
z
zlib
zdll
zlib1
)
set(
ZLIB_NAMES_DEBUG
z_brld
zd
zlibd
zlibd1
)
# Try each search configuration.
foreach(search ${_ZLIB_SEARCHES})
find_path(ZLIB_INCLUDE_DIR NAMES zlib.h ${${search}} PATH_SUFFIXES include)
endforeach()
if(NOT ZLIB_LIBRARY)
if(WIN32)
if(DEFINED CMAKE_FIND_LIBRARY_PREFIXES)
set(_zlib_orig_prefixes "${CMAKE_FIND_LIBRARY_PREFIXES}")
else()
set(_zlib_orig_prefixes)
endif()
if(DEFINED CMAKE_FIND_LIBRARY_SUFFIXES)
set(_zlib_orig_suffixes "${CMAKE_FIND_LIBRARY_SUFFIXES}")
else()
set(_zlib_orig_suffixes)
endif()
list(APPEND CMAKE_FIND_LIBRARY_PREFIXES "" "lib")
list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".dll.a")
endif()
foreach(search ${_ZLIB_SEARCHES})
find_library(ZLIB_LIBRARY_RELEASE NAMES ${ZLIB_NAMES} NAMES_PER_DIR ${${search}} PATH_SUFFIXES lib)
find_library(ZLIB_LIBRARY_DEBUG NAMES ${ZLIB_NAMES_DEBUG} NAMES_PER_DIR ${${search}} PATH_SUFFIXES lib)
endforeach()
if(WIN32)
if(DEFINED _zlib_orig_suffixes)
set(CMAKE_FIND_LIBRARY_SUFFIXES "${_zlib_orig_suffixes}")
else()
set(CMAKE_FIND_LIBRARY_SUFFIXES)
endif()
if(DEFINED _zlib_orig_prefixes)
set(CMAKE_FIND_LIBRARY_PREFIXES "${_zlib_orig_prefixes}")
else()
set(CMAKE_FIND_LIBRARY_PREFIXES)
endif()
unset(_zlib_orig_prefixes)
unset(_zlib_orig_suffixes)
endif()
include(SelectLibraryConfigurations)
select_library_configurations(ZLIB)
endif()
mark_as_advanced(ZLIB_LIBRARY ZLIB_LIBRARY_RELEASE ZLIB_LIBRARY_DEBUG ZLIB_INCLUDE_DIR)
if(ZLIB_INCLUDE_DIR AND EXISTS "${ZLIB_INCLUDE_DIR}/zlib.h")
file(STRINGS "${ZLIB_INCLUDE_DIR}/zlib.h" ZLIB_H REGEX "^#define ZLIB_VERSION \"[^\"]*\"$")
string(REGEX REPLACE "^.*ZLIB_VERSION \"([0-9]+).*$" "\\1" ZLIB_VERSION_MAJOR "${ZLIB_H}")
string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_MINOR "${ZLIB_H}")
string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_PATCH "${ZLIB_H}")
set(ZLIB_VERSION_STRING "${ZLIB_VERSION_MAJOR}.${ZLIB_VERSION_MINOR}.${ZLIB_VERSION_PATCH}")
# only append a TWEAK version if it exists:
set(ZLIB_VERSION_TWEAK "")
if("${ZLIB_H}" MATCHES "ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+)")
set(ZLIB_VERSION_TWEAK "${CMAKE_MATCH_1}")
set(ZLIB_VERSION_STRING "${ZLIB_VERSION_STRING}.${ZLIB_VERSION_TWEAK}")
endif()
set(ZLIB_MAJOR_VERSION "${ZLIB_VERSION_MAJOR}")
set(ZLIB_MINOR_VERSION "${ZLIB_VERSION_MINOR}")
set(ZLIB_PATCH_VERSION "${ZLIB_VERSION_PATCH}")
endif()
# handle the QUIETLY and REQUIRED arguments and set ZLIB_FOUND to TRUE if
# all listed variables are TRUE
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(ZLIB REQUIRED_VARS ZLIB_LIBRARY ZLIB_INCLUDE_DIR VERSION_VAR ZLIB_VERSION_STRING)
if(ZLIB_FOUND)
set(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR})
if(NOT ZLIB_LIBRARIES)
set(ZLIB_LIBRARIES ${ZLIB_LIBRARY})
endif()
if(NOT TARGET ZLIB::ZLIB)
add_library(ZLIB::ZLIB UNKNOWN IMPORTED GLOBAL)
set_target_properties(
ZLIB::ZLIB
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${ZLIB_INCLUDE_DIRS}"
)
if(ZLIB_LIBRARY_RELEASE)
set_property(TARGET ZLIB::ZLIB APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(ZLIB::ZLIB PROPERTIES IMPORTED_LOCATION_RELEASE "${ZLIB_LIBRARY_RELEASE}")
endif()
if(ZLIB_LIBRARY_DEBUG)
set_property(TARGET ZLIB::ZLIB APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(ZLIB::ZLIB PROPERTIES IMPORTED_LOCATION_DEBUG "${ZLIB_LIBRARY_DEBUG}")
endif()
if(NOT ZLIB_LIBRARY_RELEASE AND NOT ZLIB_LIBRARY_DEBUG)
set_target_properties(ZLIB::ZLIB PROPERTIES IMPORTED_LOCATION "${ZLIB_LIBRARY}")
endif()
endif()
endif()