From 98711282f2f1dddafa38fa408642a3535faba57f Mon Sep 17 00:00:00 2001 From: Clifford Yapp <238416+starseeker@users.noreply.github.com> Date: Fri, 4 Oct 2024 11:52:17 -0400 Subject: [PATCH] Make a stab at replacing FindASSETIMPORT and using the built-in export targets instead. --- misc/CMake/BRLCAD_Find_Package.cmake | 38 +++++++- misc/CMake/BRLCAD_Summary.cmake | 2 +- misc/CMake/CMakeLists.txt | 1 - misc/CMake/FindASSETIMPORT.cmake | 92 ------------------- src/libgcv/plugins/assetimport/CMakeLists.txt | 37 ++++---- src/libged/facetize/CMakeLists.txt | 8 +- src/libged/facetize/subprocess/CMakeLists.txt | 7 +- src/librt/CMakeLists.txt | 14 +-- 8 files changed, 71 insertions(+), 128 deletions(-) delete mode 100644 misc/CMake/FindASSETIMPORT.cmake diff --git a/misc/CMake/BRLCAD_Find_Package.cmake b/misc/CMake/BRLCAD_Find_Package.cmake index 17444f35cd..0c1e90d4f0 100644 --- a/misc/CMake/BRLCAD_Find_Package.cmake +++ b/misc/CMake/BRLCAD_Find_Package.cmake @@ -88,14 +88,41 @@ macro(BRLCAD_Find_Package pkg_name) get_property(cv_new DIRECTORY PROPERTY CACHE_VARIABLES) # Using the list of variables that were already set before the find_package - # call, trim the new list down to just the newly set variables. + # call, trim the new list down to just the newly set variables. This is + # one possible source of paths, but we also need this to clear the cache + # versions of the results. We want find_package to re-run on each configure + # as a clean test of the current state of the system, and to do that we only + # allow the values from a find_package to persist in the current working + # CMake state. To prevent their being cached (the default CMake behavior) + # we need to manually intervene and clear them. list(REMOVE_ITEM cv_new ${cv_ctrl}) + + # If find_package is using an imported target, get the location from + # the target. + set(brlcad_find_package_tloc) + if (TARGET ${pkg_name}::${pkg_name}) + # TODO - we may need to check CONFIG versions of this property as well. + get_target_property(brlcad_find_package_tloc ${pkg_name}::${pkg_name} LOCATION) + list(APPEND cv_new brlcad_find_package_tloc) + endif (TARGET ${pkg_name}::${pkg_name}) + + if (BRLCAD_FIND_DEBUG_MODE) + message("new cache items: ${cv_new}") + endif (BRLCAD_FIND_DEBUG_MODE) + set(is_bundled FALSE) foreach(nc ${cv_new}) + if (BRLCAD_FIND_DEBUG_MODE) + message("Checking ${nc}: ${${nc}}") + endif (BRLCAD_FIND_DEBUG_MODE) + # We don't know what vars were set, but check each one that was set # for a local path. If we find one, we have a bundled package is_subpath("${CMAKE_BINARY_DIR}" "${${nc}}" LOCAL_TEST) if(LOCAL_TEST) + if (BRLCAD_FIND_DEBUG_MODE) + message(" - Local path found") + endif (BRLCAD_FIND_DEBUG_MODE) set(is_bundled TRUE) endif(LOCAL_TEST) @@ -125,12 +152,15 @@ macro(BRLCAD_Find_Package pkg_name) if(is_bundled) set(${pkg_upper}_STATUS "Bundled" CACHE STRING "${pkg_name} bundled status") else(is_bundled) - if(${pkg_name}_FOUND) + if(${pkg_name}_FOUND OR ${pkg_upper}_FOUND) set(${pkg_upper}_STATUS "System" CACHE STRING "${pkg_name} bundled status") - else(${pkg_name}_FOUND) + else() set(${pkg_upper}_STATUS "NotFound" CACHE STRING "${pkg_name} bundled status") - endif(${pkg_name}_FOUND) + endif() endif(is_bundled) + if (BRLCAD_FIND_DEBUG_MODE) + message("${pkg_upper}_STATUS: ${${pkg_upper}_STATUS}") + endif (BRLCAD_FIND_DEBUG_MODE) endmacro() # Local Variables: diff --git a/misc/CMake/BRLCAD_Summary.cmake b/misc/CMake/BRLCAD_Summary.cmake index 580358aed7..41e176ac98 100644 --- a/misc/CMake/BRLCAD_Summary.cmake +++ b/misc/CMake/BRLCAD_Summary.cmake @@ -250,7 +250,7 @@ function(BRLCAD_Summary) endif(ER_REQUIRED_VARS) endfunction(EXT_REPORT blabel bvar) - ext_report("Asset Import Library" ASSETIMPORT_STATUS REQUIRED_VARS "BRLCAD_ENABLE_ASSETIMPORT") + ext_report("Asset Import Library" ASSIMP_STATUS REQUIRED_VARS "BRLCAD_ENABLE_ASSETIMPORT") ext_report("Eigen" EIGEN3_INCLUDE_DIR) ext_report("Geogram" GEOGRAM_STATUS) ext_report("Geospatial Data Abstraction Library" GDAL_STATUS REQUIRED_VARS "BRLCAD_ENABLE_GDAL") diff --git a/misc/CMake/CMakeLists.txt b/misc/CMake/CMakeLists.txt index 057a3c6c4b..cdc7a1fb1d 100644 --- a/misc/CMake/CMakeLists.txt +++ b/misc/CMake/CMakeLists.txt @@ -28,7 +28,6 @@ set( FindADAPTAGRAMS.cmake FindASTYLE.cmake FindAppleseed.cmake - FindASSETIMPORT.cmake FindBlosc.cmake FindBSON.cmake FindFontconfig.cmake diff --git a/misc/CMake/FindASSETIMPORT.cmake b/misc/CMake/FindASSETIMPORT.cmake deleted file mode 100644 index ad9930681e..0000000000 --- a/misc/CMake/FindASSETIMPORT.cmake +++ /dev/null @@ -1,92 +0,0 @@ -# -# This file is modeled after appleseed. -# Visit https://appleseedhq.net/ for additional information and resources. -# -# This software is released under the MIT license. -# -# Copyright (c) 2014-2018 Esteban Tovagliari, The appleseedhq Organization -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# - -### -# - Find ASSETIMPORT -# Find the native ASSETIMPORT includes and library -# -# ASSETIMPORT_INCLUDE_DIR - where to find include headers -# ASSETIMPORT_LIBRARIES - List of libraries when using assetimport. -# -### -# - helpful cmake flags when building -# -# ASSETIMPORT_ROOT - path to assetimport root if it is built outside of /usr -# -#============================================================================= -set(_ASSETIMPORT_SEARCHES) - -# Search ASSETIMPORT_ROOT first if it is set. -if(ASSETIMPORT_ROOT) - set(_ASSETIMPORT_SEARCH_ROOT PATHS ${ASSETIMPORT_ROOT} NO_DEFAULT_PATH) - list(APPEND _ASSETIMPORT_SEARCHES _ASSETIMPORT_SEARCH_ROOT) -endif() - -set(ASSETIMPORT_NAMES assimp assimpd) - -# Try each search configuration. -foreach(search ${_ASSETIMPORT_SEARCHES}) - find_path( - ASSETIMPORT_INCLUDE_DIR - NAMES assimp/postprocess.h assimp/scene.h assimp/version.h assimp/config.h assimp/cimport.h ${${search}} - PATH_SUFFIXES include - ) - find_library(ASSETIMPORT_LIBRARY NAMES ${ASSETIMPORT_NAMES} ${${search}} PATH_SUFFIXES lib lib64 bin) -endforeach() - -if(NOT ASSETIMPORT_LIBRARY OR NOT ASSETIMPORT_INCLUDE_DIR) - # Try a more generic search - find_path( - ASSETIMPORT_INCLUDE_DIR - NAMES assimp/postprocess.h assimp/scene.h assimp/version.h assimp/config.h assimp/cimport.h - PATH_SUFFIXES include - ) - find_library(ASSETIMPORT_LIBRARY NAMES ${ASSETIMPORT_NAMES} PATH_SUFFIXES lib lib64 bin) -endif(NOT ASSETIMPORT_LIBRARY OR NOT ASSETIMPORT_INCLUDE_DIR) - -# Handle the QUIETLY and REQUIRED arguments and set assetimport_FOUND. -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(ASSETIMPORT REQUIRED_VARS ASSETIMPORT_LIBRARY ASSETIMPORT_INCLUDE_DIR) - -# Set the output variables. -if(ASSETIMPORT_FOUND) - set(ASSETIMPORT_LIBRARY "${ASSETIMPORT_LIBRARY}" CACHE PATH "Asset Import Library") - set(ASSETIMPORT_INCLUDE_DIRS ${ASSETIMPORT_INCLUDE_DIR}) - set(ASSETIMPORT_LIBRARIES ${ASSETIMPORT_LIBRARY}) -else() - set(ASSETIMPORT_INCLUDE_DIRS) - set(ASSETIMPORT_LIBRARIES) -endif() - -mark_as_advanced(ASSETIMPORT_INCLUDE_DIR ASSETIMPORT_LIBRARY) - -# Local Variables: -# tab-width: 8 -# mode: cmake -# indent-tabs-mode: t -# End: -# ex: shiftwidth=2 tabstop=8 diff --git a/src/libgcv/plugins/assetimport/CMakeLists.txt b/src/libgcv/plugins/assetimport/CMakeLists.txt index ef33b6bacc..7b3835a0f4 100644 --- a/src/libgcv/plugins/assetimport/CMakeLists.txt +++ b/src/libgcv/plugins/assetimport/CMakeLists.txt @@ -1,24 +1,25 @@ set(ASSETIMPORT_SRCS assetimport_read.cpp assetimport_write.cpp) -brlcad_find_package(ASSETIMPORT) +brlcad_find_package(assimp) -if(BRLCAD_ENABLE_ASSETIMPORT AND ASSETIMPORT_LIBRARY AND ASSETIMPORT_INCLUDE_DIR) - message("assetimport plugin FOUND and ENABLED") - include_directories(SYSTEM ${ASSETIMPORT_INCLUDE_DIR}) - - gcv_plugin_library(gcv-assetimport SHARED ${ASSETIMPORT_SRCS}) - target_link_libraries( - gcv-assetimport - libgcv - libwdb - librt - libbu - ${ASSETIMPORT_LIBRARY} - ) - set_property(TARGET gcv-assetimport APPEND PROPERTY COMPILE_DEFINITIONS BRLCADBUILD HAVE_CONFIG_H) - validate_style(gcv-assetimport "${ASSETIMPORT_SRCS}") - plugin_setup(gcv-assetimport gcv) -endif(BRLCAD_ENABLE_ASSETIMPORT AND ASSETIMPORT_LIBRARY AND ASSETIMPORT_INCLUDE_DIR) +if(BRLCAD_ENABLE_ASSETIMPORT) + if(TARGET assimp::assimp) + gcv_plugin_library(gcv-assetimport SHARED ${ASSETIMPORT_SRCS}) + target_link_libraries( + gcv-assetimport + libgcv + libwdb + librt + libbu + assimp::assimp + ) + set_property(TARGET gcv-assetimport APPEND PROPERTY COMPILE_DEFINITIONS BRLCADBUILD HAVE_CONFIG_H) + validate_style(gcv-assetimport "${ASSETIMPORT_SRCS}") + plugin_setup(gcv-assetimport gcv) + else() + message("Warning - Asset Import support enabled, but Asset Import Library not found - disabling GCV plugin\n") + endif() +endif(BRLCAD_ENABLE_ASSETIMPORT) cmakefiles( ${ASSETIMPORT_SRCS} diff --git a/src/libged/facetize/CMakeLists.txt b/src/libged/facetize/CMakeLists.txt index 52a30e1997..403c410843 100644 --- a/src/libged/facetize/CMakeLists.txt +++ b/src/libged/facetize/CMakeLists.txt @@ -1,5 +1,7 @@ brlcad_find_package(MANIFOLD REQUIRED) -brlcad_find_package(ASSETIMPORT) +message("starting") +brlcad_find_package(assimp) +message("done") set(FACETIZE_LOCAL_INCLUDE_DIRS) @@ -7,8 +9,8 @@ if(MANIFOLD_LIBRARIES) list(APPEND FACETIZE_LOCAL_INCLUDE_DIRS ${MANIFOLD_INCLUDE_DIRS}) add_definitions(-DUSE_MANIFOLD) - if(ASSETIMPORT_LIBRARY) - list(APPEND FACETIZE_LOCAL_INCLUDE_DIRS ${ASSETIMPORT_INCLUDE_DIR}) + if(TARGET assimp::assimp) + set(ASSETIMPORT_LIBRARIES assimp::assimp) add_definitions(-DUSE_ASSETIMPORT) endif(ASSETIMPORT_LIBRARY) endif(MANIFOLD_LIBRARIES) diff --git a/src/libged/facetize/subprocess/CMakeLists.txt b/src/libged/facetize/subprocess/CMakeLists.txt index b3e8abf519..38e83c663c 100644 --- a/src/libged/facetize/subprocess/CMakeLists.txt +++ b/src/libged/facetize/subprocess/CMakeLists.txt @@ -12,15 +12,16 @@ set( brlcad_find_package(MANIFOLD REQUIRED) -brlcad_find_package(ASSETIMPORT) -if(ASSETIMPORT_LIBRARIES) +brlcad_find_package(assimp) +if(TARGET assimp::assimp) add_definitions(-DUSE_ASSETIMPORT) + set(ASSETIMPORT_LIBRARIES assimp::assimp) endif(ASSETIMPORT_LIBRARIES) brlcad_find_package(GEOGRAM REQUIRED SYSPATTERN geogram) add_definitions(-DUSE_GEOGRAM) -set(INCLUDE_DIRS ${GEOGRAM_INCLUDE_DIR} ${MANIFOLD_INCLUDE_DIRS} ${ASSETIMPORT_INCLUDE_DIR}) +set(INCLUDE_DIRS ${GEOGRAM_INCLUDE_DIR} ${MANIFOLD_INCLUDE_DIRS}) ged_subprocess_library(facetize_process SHARED ${GED_TESS_SRCS}) target_include_directories(facetize_process SYSTEM PRIVATE ${INCLUDE_DIRS}) diff --git a/src/librt/CMakeLists.txt b/src/librt/CMakeLists.txt index e775df23ba..535254ab05 100644 --- a/src/librt/CMakeLists.txt +++ b/src/librt/CMakeLists.txt @@ -2,14 +2,19 @@ brlcad_find_package(MANIFOLD REQUIRED) brlcad_find_package(OPENNURBS REQUIRED SYSPATTERN openNURBS) brlcad_find_package(REGEX REQUIRED) if(BRLCAD_ENABLE_ASSETIMPORT) - brlcad_find_package(ASSETIMPORT) + # TODO - see if we can use tinygltf to write out the glb file ourselves - + # Manifold's assimp integration is convenient for producing glb files, which + # are needed if we're going to submit problem cases upstream, but using it + # introduces an additional large dependency just for a debugging output... + brlcad_find_package(assimp) endif(BRLCAD_ENABLE_ASSETIMPORT) brlcad_find_package(GEOGRAM REQUIRED SYSPATTERN geogram) add_definitions(-DUSE_GEOGRAM) -if(ASSETIMPORT_LIBRARIES) +if(TARGET assimp::assimp) add_definitions(-DUSE_ASSETIMPORT) -endif(ASSETIMPORT_LIBRARIES) + set(ASSETIMPORT_LIBRARIES assimp::assimp) +endif(TARGET assimp::assimp) if(NOT BRLCAD_ENABLE_GCT) brlcad_find_package(MMESH REQUIRED) @@ -388,9 +393,6 @@ set( ${GEOGRAM_INCLUDE_DIR} ${MANIFOLD_INCLUDE_DIRS} ${MMESH_INCLUDE_DIR} - ${ASSETIMPORT_INCLUDE_DIR} - ${MANIFOLD_INCLUDE_DIRS} - ${ASSETIMPORT_INCLUDE_DIR} ) # FIXME: needs materialX # ${CMAKE_CURRENT_SOURCE_DIR}/../../../MaterialXSource/source