Skip to content

Commit

Permalink
See if we can use Config.cmake approach to find_package for zlib and …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
starseeker committed Oct 9, 2024
1 parent 5be73f8 commit 250e313
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 330 deletions.
31 changes: 26 additions & 5 deletions misc/CMake/BRLCAD_ExternalDeps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,9 @@ endfunction(brlcad_process_ext)
# 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)
Expand Down Expand Up @@ -969,11 +972,29 @@ macro(find_package_zlib)
else()
find_package(ZLIB)
endif()
list(GET ZLIB_LIBRARIES 0 ZLIB_FILE)
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)
endif(ZLIB_LOCAL_TEST)

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 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 is not found" FORCE)
endif()
endmacro(find_package_zlib)

# Eigen - linear algebra library
Expand Down
3 changes: 3 additions & 0 deletions misc/CMake/BRLCAD_Find_Package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
macro(BRLCAD_Find_Package pkg_name)
cmake_parse_arguments(F "REQUIRED;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
Expand Down
2 changes: 1 addition & 1 deletion misc/CMake/BRLCAD_Summary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ function(BRLCAD_Summary)
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_LIBRARY)
ext_report("Zlib" ZLIB_STATUS)

# Find the maximum label length
set(LABEL_LENGTH 0)
Expand Down
2 changes: 0 additions & 2 deletions misc/CMake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ set(
FindOpenVDB.cmake
FindPERPLEX.cmake
FindPkgMacros.cmake
FindPNG.cmake
FindPROJ4.cmake
FindRE2C.cmake
FindREGEX.cmake
Expand All @@ -67,7 +66,6 @@ set(
FindWix.cmake
FindXMLLINT.cmake
FindXSLTPROC.cmake
FindZLIB.cmake
NSIS.template.in
NSIS_silent.template.in
OpenVDBUtils.cmake
Expand Down
193 changes: 0 additions & 193 deletions misc/CMake/FindPNG.cmake

This file was deleted.

Loading

0 comments on commit 250e313

Please sign in to comment.