diff --git a/cmake/modules/FindBlosc.cmake b/cmake/modules/FindBlosc.cmake new file mode 100644 index 0000000000..fedf1ad4d3 --- /dev/null +++ b/cmake/modules/FindBlosc.cmake @@ -0,0 +1,430 @@ +# Copyright Contributors to the OpenVDB Project +# SPDX-License-Identifier: Apache-2.0 +# +#[=======================================================================[.rst: + +FindBlosc +--------- + +Find Blosc include dirs and libraries + +Use this module by invoking find_package with the form:: + + find_package(Blosc + [version] [EXACT] # Minimum or EXACT version e.g. 1.5.0 + [REQUIRED] # Fail with error if Blosc is not found + ) + +IMPORTED Targets +^^^^^^^^^^^^^^^^ + +``Blosc::blosc`` + This module defines IMPORTED target Blosc::Blosc, if Blosc has been found. + +Result Variables +^^^^^^^^^^^^^^^^ + +This will define the following variables: + +``Blosc_FOUND`` + True if the system has the Blosc library. +``Blosc_VERSION`` + The version of the Blosc library which was found. +``Blosc_INCLUDE_DIRS`` + Include directories needed to use Blosc. +``Blosc_RELEASE_LIBRARIES`` + Libraries needed to link to the release version of Blosc. +``Blosc_RELEASE_LIBRARY_DIRS`` + Blosc release library directories. +``Blosc_DEBUG_LIBRARIES`` + Libraries needed to link to the debug version of Blosc. +``Blosc_DEBUG_LIBRARY_DIRS`` + Blosc debug library directories. + +Deprecated - use [RELEASE|DEBUG] variants: + +``Blosc_LIBRARIES`` + Libraries needed to link to Blosc. +``Blosc_LIBRARY_DIRS`` + Blosc library directories. + +Cache Variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``Blosc_INCLUDE_DIR`` + The directory containing ``blosc.h``. +``Blosc_LIBRARY`` + The path to the Blosc library. may include target_link_libraries() debug/optimized keywords +``Blosc_LIBRARY_RELEASE`` + The path to the Blosc release library. +``Blosc_LIBRARY_DEBUG`` + The path to the Blosc debug library. + +Hints +^^^^^ + +Instead of explicitly setting the cache variables, the following variables +may be provided to tell this module where to look. + +``Blosc_ROOT`` + Preferred installation prefix. +``BLOSC_INCLUDEDIR`` + Preferred include directory e.g. /include +``BLOSC_LIBRARYDIR`` + Preferred library directory e.g. /lib +``BLOSC_DEBUG_SUFFIX`` + Suffix of the debug version of blosc. Defaults to "_d", OR the empty string for VCPKG_TOOLCHAIN +``SYSTEM_LIBRARY_PATHS`` + Global list of library paths intended to be searched by and find_xxx call +``BLOSC_USE_STATIC_LIBS`` + Only search for static blosc libraries +``BLOSC_USE_EXTERNAL_SOURCES`` + Set to ON if Blosc has been built using external sources for LZ4, snappy, + zlib and zstd. Default is OFF. +``DISABLE_CMAKE_SEARCH_PATHS`` + Disable CMakes default search paths for find_xxx calls in this module + +#]=======================================================================] + +cmake_minimum_required(VERSION 3.18) +include(GNUInstallDirs) + +mark_as_advanced( + Blosc_INCLUDE_DIR + Blosc_LIBRARY +) + +set(_FIND_BLOSC_ADDITIONAL_OPTIONS "") +if(DISABLE_CMAKE_SEARCH_PATHS) + set(_FIND_BLOSC_ADDITIONAL_OPTIONS NO_DEFAULT_PATH) +endif() + +# Set _BLOSC_ROOT based on a user provided root var. Xxx_ROOT and ENV{Xxx_ROOT} +# are prioritised over the legacy capitalized XXX_ROOT variables for matching +# CMake 3.12 behaviour +# @todo deprecate -D and ENV BLOSC_ROOT from CMake 3.12 +if(Blosc_ROOT) + set(_BLOSC_ROOT ${Blosc_ROOT}) +elseif(DEFINED ENV{Blosc_ROOT}) + set(_BLOSC_ROOT $ENV{Blosc_ROOT}) +elseif(BLOSC_ROOT) + set(_BLOSC_ROOT ${BLOSC_ROOT}) +elseif(DEFINED ENV{BLOSC_ROOT}) + set(_BLOSC_ROOT $ENV{BLOSC_ROOT}) +endif() + +# Additionally try and use pkconfig to find blosc +if(USE_PKGCONFIG) + if(NOT DEFINED PKG_CONFIG_FOUND) + find_package(PkgConfig) + endif() + if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_Blosc QUIET blosc) + endif() +endif() + +# ------------------------------------------------------------------------ +# Search for blosc include DIR +# ------------------------------------------------------------------------ + +set(_BLOSC_INCLUDE_SEARCH_DIRS "") +list(APPEND _BLOSC_INCLUDE_SEARCH_DIRS + ${BLOSC_INCLUDEDIR} + ${_BLOSC_ROOT} + ${PC_Blosc_INCLUDE_DIRS} + ${SYSTEM_LIBRARY_PATHS} +) + +# Look for a standard blosc header file. +find_path(Blosc_INCLUDE_DIR blosc.h + ${_FIND_BLOSC_ADDITIONAL_OPTIONS} + PATHS ${_BLOSC_INCLUDE_SEARCH_DIRS} + PATH_SUFFIXES ${CMAKE_INSTALL_INCLUDEDIR} include +) + +if(EXISTS "${Blosc_INCLUDE_DIR}/blosc.h") + file(STRINGS "${Blosc_INCLUDE_DIR}/blosc.h" + _blosc_version_major_string REGEX "#define BLOSC_VERSION_MAJOR +[0-9]+ " + ) + string(REGEX REPLACE "#define BLOSC_VERSION_MAJOR +([0-9]+).*$" "\\1" + _blosc_version_major_string "${_blosc_version_major_string}" + ) + string(STRIP "${_blosc_version_major_string}" Blosc_VERSION_MAJOR) + + file(STRINGS "${Blosc_INCLUDE_DIR}/blosc.h" + _blosc_version_minor_string REGEX "#define BLOSC_VERSION_MINOR +[0-9]+ " + ) + string(REGEX REPLACE "#define BLOSC_VERSION_MINOR +([0-9]+).*$" "\\1" + _blosc_version_minor_string "${_blosc_version_minor_string}" + ) + string(STRIP "${_blosc_version_minor_string}" Blosc_VERSION_MINOR) + + file(STRINGS "${Blosc_INCLUDE_DIR}/blosc.h" + _blosc_version_release_string REGEX "#define BLOSC_VERSION_RELEASE +[0-9]+ " + ) + string(REGEX REPLACE "#define BLOSC_VERSION_RELEASE +([0-9]+).*$" "\\1" + _blosc_version_release_string "${_blosc_version_release_string}" + ) + string(STRIP "${_blosc_version_release_string}" Blosc_VERSION_RELEASE) + + unset(_blosc_version_major_string) + unset(_blosc_version_minor_string) + unset(_blosc_version_release_string) + + set(Blosc_VERSION ${Blosc_VERSION_MAJOR}.${Blosc_VERSION_MINOR}.${Blosc_VERSION_RELEASE}) +endif() + +# ------------------------------------------------------------------------ +# Search for blosc lib DIR +# ------------------------------------------------------------------------ + +set(_BLOSC_LIBRARYDIR_SEARCH_DIRS "") +list(APPEND _BLOSC_LIBRARYDIR_SEARCH_DIRS + ${BLOSC_LIBRARYDIR} + ${_BLOSC_ROOT} + ${PC_Blosc_LIBRARY_DIRS} + ${SYSTEM_LIBRARY_PATHS} +) + +set(Blosc_LIB_COMPONENTS "") +# NOTE: Search for debug version first (see vcpkg hack) +list(APPEND BLOSC_BUILD_TYPES DEBUG RELEASE) + +foreach(BUILD_TYPE ${BLOSC_BUILD_TYPES}) + set(_BLOSC_LIB_NAME blosc) + + set(_BLOSC_CMAKE_IGNORE_PATH ${CMAKE_IGNORE_PATH}) + if(VCPKG_TOOLCHAIN) + # Blosc is installed very strangely in VCPKG (debug/release libs have the + # same name, static build uses external deps, dll doesn't) and blosc itself + # comes with almost zero downstream CMake support for us to detect settings. + # We should not support external package managers in our own modules like + # this, but there doesn't seem to be a work around + if(NOT DEFINED BLOSC_DEBUG_SUFFIX) + set(BLOSC_DEBUG_SUFFIX "") + endif() + if(BUILD_TYPE STREQUAL RELEASE) + if(EXISTS ${Blosc_LIBRARY_DEBUG}) + get_filename_component(_BLOSC_DEBUG_DIR ${Blosc_LIBRARY_DEBUG} DIRECTORY) + list(APPEND CMAKE_IGNORE_PATH ${_BLOSC_DEBUG_DIR}) + endif() + endif() + endif() + + if(BUILD_TYPE STREQUAL DEBUG) + if(NOT DEFINED BLOSC_DEBUG_SUFFIX) + set(BLOSC_DEBUG_SUFFIX _d) + endif() + set(_BLOSC_LIB_NAME "${_BLOSC_LIB_NAME}${BLOSC_DEBUG_SUFFIX}") + endif() + + find_library(Blosc_LIBRARY_${BUILD_TYPE} ${_BLOSC_LIB_NAME} + ${_FIND_BLOSC_ADDITIONAL_OPTIONS} + PATHS ${_BLOSC_LIBRARYDIR_SEARCH_DIRS} + PATH_SUFFIXES ${CMAKE_INSTALL_LIBDIR} lib64 lib + ) + + list(APPEND Blosc_LIB_COMPONENTS ${Blosc_LIBRARY_${BUILD_TYPE}}) + set(CMAKE_IGNORE_PATH ${_BLOSC_CMAKE_IGNORE_PATH}) +endforeach() + +if(Blosc_LIBRARY_DEBUG AND Blosc_LIBRARY_RELEASE) + # if the generator is multi-config or if CMAKE_BUILD_TYPE is set for + # single-config generators, set optimized and debug libraries + get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + if(_isMultiConfig OR CMAKE_BUILD_TYPE) + set(Blosc_LIBRARY optimized ${Blosc_LIBRARY_RELEASE} debug ${Blosc_LIBRARY_DEBUG}) + else() + # For single-config generators where CMAKE_BUILD_TYPE has no value, + # just use the release libraries + set(Blosc_LIBRARY ${Blosc_LIBRARY_RELEASE}) + endif() + # FIXME: This probably should be set for both cases + set(Blosc_LIBRARIES optimized ${Blosc_LIBRARY_RELEASE} debug ${Blosc_LIBRARY_DEBUG}) +endif() + +# if only the release version was found, set the debug variable also to the release version +if(Blosc_LIBRARY_RELEASE AND NOT Blosc_LIBRARY_DEBUG) + set(Blosc_LIBRARY_DEBUG ${Blosc_LIBRARY_RELEASE}) + set(Blosc_LIBRARY ${Blosc_LIBRARY_RELEASE}) + set(Blosc_LIBRARIES ${Blosc_LIBRARY_RELEASE}) +endif() + +# if only the debug version was found, set the release variable also to the debug version +if(Blosc_LIBRARY_DEBUG AND NOT Blosc_LIBRARY_RELEASE) + set(Blosc_LIBRARY_RELEASE ${Blosc_LIBRARY_DEBUG}) + set(Blosc_LIBRARY ${Blosc_LIBRARY_DEBUG}) + set(Blosc_LIBRARIES ${Blosc_LIBRARY_DEBUG}) +endif() + +# If the debug & release library ends up being the same, omit the keywords +if("${Blosc_LIBRARY_RELEASE}" STREQUAL "${Blosc_LIBRARY_DEBUG}") + set(Blosc_LIBRARY ${Blosc_LIBRARY_RELEASE} ) + set(Blosc_LIBRARIES ${Blosc_LIBRARY_RELEASE} ) +endif() + +if(Blosc_LIBRARY) + set(Blosc_FOUND TRUE) +else() + set(Blosc_FOUND FALSE) +endif() + +# ------------------------------------------------------------------------ +# Cache and set Blosc_FOUND +# ------------------------------------------------------------------------ + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Blosc + FOUND_VAR Blosc_FOUND + REQUIRED_VARS + Blosc_LIBRARY + Blosc_INCLUDE_DIR + VERSION_VAR Blosc_VERSION +) + +if(NOT Blosc_FOUND) + if(Blosc_FIND_REQUIRED) + message(FATAL_ERROR "Unable to find Blosc") + endif() + return() +endif() + +# Partition release/debug lib vars + +set(Blosc_RELEASE_LIBRARIES ${Blosc_LIBRARY_RELEASE}) +get_filename_component(Blosc_RELEASE_LIBRARY_DIRS ${Blosc_RELEASE_LIBRARIES} DIRECTORY) +set(Blosc_DEBUG_LIBRARIES ${Blosc_LIBRARY_DEBUG}) +get_filename_component(Blosc_DEBUG_LIBRARY_DIRS ${Blosc_DEBUG_LIBRARIES} DIRECTORY) +set(Blosc_LIBRARIES ${Blosc_RELEASE_LIBRARIES}) +set(Blosc_LIBRARY_DIRS ${Blosc_RELEASE_LIBRARY_DIRS}) +set(Blosc_INCLUDE_DIRS ${Blosc_INCLUDE_DIR}) +set(Blosc_INCLUDE_DIRS ${Blosc_INCLUDE_DIR}) + +# Configure lib type. If XXX_USE_STATIC_LIBS, we always assume a static +# lib is in use. If win32, we can't mark the import .libs as shared, so +# these are always marked as UNKNOWN. Otherwise, infer from extension. +set(BLOSC_LIB_TYPE UNKNOWN) +if(BLOSC_USE_STATIC_LIBS) + set(BLOSC_LIB_TYPE STATIC) +elseif(UNIX) + get_filename_component(_BLOSC_EXT ${Blosc_LIBRARY_RELEASE} EXT) + if(_BLOSC_EXT STREQUAL ".a") + set(BLOSC_LIB_TYPE STATIC) + elseif(_BLOSC_EXT STREQUAL ".so" OR + _BLOSC_EXT STREQUAL ".dylib") + set(BLOSC_LIB_TYPE SHARED) + endif() +endif() + +get_filename_component(Blosc_LIBRARY_DIRS ${Blosc_LIBRARY_RELEASE} DIRECTORY) + +if(NOT TARGET Blosc::blosc) + add_library(Blosc::blosc ${BLOSC_LIB_TYPE} IMPORTED) + set_target_properties(Blosc::blosc PROPERTIES + INTERFACE_COMPILE_OPTIONS "${PC_Blosc_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${Blosc_INCLUDE_DIRS}") + + # Standard location + set_target_properties(Blosc::blosc PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" + IMPORTED_LOCATION "${Blosc_LIBRARY}") + + # Release location + if(EXISTS "${Blosc_LIBRARY_RELEASE}") + set_property(TARGET Blosc::blosc APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE) + set_target_properties(Blosc::blosc PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX" + IMPORTED_LOCATION_RELEASE "${Blosc_LIBRARY_RELEASE}") + endif() + + # Debug location + if(EXISTS "${Blosc_LIBRARY_DEBUG}") + set_property(TARGET Blosc::blosc APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG) + set_target_properties(Blosc::blosc PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX" + IMPORTED_LOCATION_DEBUG "${Blosc_LIBRARY_DEBUG}") + endif() + + # Blosc may optionally be compiled with external sources for + # lz4, snappy and zlib . Add them as interface libs if requested + # (there doesn't seem to be a way to figure this out automatically). + # We assume they live along side blosc + if(BLOSC_USE_EXTERNAL_SOURCES) + set_target_properties(Blosc::blosc PROPERTIES + INTERFACE_LINK_DIRECTORIES + "\$<\$:${Blosc_RELEASE_LIBRARY_DIRS}>;\$<\$:${Blosc_DEBUG_LIBRARY_DIRS}>") + + set(BLOSC_EXTERNAL_LIBRARIES lz4 snappy zlib zstd) + + foreach(BLOSC_EXTERNAL_LIB ${BLOSC_EXTERNAL_LIBRARIES}) + + foreach(BUILD_TYPE ${BLOSC_BUILD_TYPES}) + set(_BLOSC_CMAKE_IGNORE_PATH ${CMAKE_IGNORE_PATH}) + + if(VCPKG_TOOLCHAIN) + if(BUILD_TYPE STREQUAL RELEASE) + list(APPEND CMAKE_IGNORE_PATH ${Blosc_DEBUG_LIBRARY_DIRS}) + else() + list(APPEND CMAKE_IGNORE_PATH ${Blosc_RELEASE_LIBRARY_DIRS}) + endif() + endif() + + find_library(${BLOSC_EXTERNAL_LIB}_LIBRARY_${BUILD_TYPE} ${BLOSC_EXTERNAL_LIB} + ${_FIND_BLOSC_ADDITIONAL_OPTIONS} + PATHS ${_BLOSC_LIBRARYDIR_SEARCH_DIRS} + PATH_SUFFIXES ${CMAKE_INSTALL_LIBDIR} lib64 lib) + + if(NOT ${BLOSC_EXTERNAL_LIB}_LIBRARY_${BUILD_TYPE}) + if(BUILD_TYPE STREQUAL DEBUG) + find_library(${BLOSC_EXTERNAL_LIB}_LIBRARY_${BUILD_TYPE} "${BLOSC_EXTERNAL_LIB}d" + ${_FIND_BLOSC_ADDITIONAL_OPTIONS} + PATHS ${_BLOSC_LIBRARYDIR_SEARCH_DIRS} + PATH_SUFFIXES ${CMAKE_INSTALL_LIBDIR} lib64 lib) + endif() + endif() + + set(CMAKE_IGNORE_PATH ${_BLOSC_CMAKE_IGNORE_PATH}) + endforeach() + + if(${BLOSC_EXTERNAL_LIB}_LIBRARY_DEBUG AND ${BLOSC_EXTERNAL_LIB}_LIBRARY_RELEASE) + # if the generator is multi-config or if CMAKE_BUILD_TYPE is set for + # single-config generators, set optimized and debug libraries + get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + if(_isMultiConfig OR CMAKE_BUILD_TYPE) + set(${BLOSC_EXTERNAL_LIB}_LIBRARY optimized ${${BLOSC_EXTERNAL_LIB}_LIBRARY_RELEASE} debug ${${BLOSC_EXTERNAL_LIB}_LIBRARY_DEBUG}) + else() + # For single-config generators where CMAKE_BUILD_TYPE has no value, + # just use the release libraries + set(${BLOSC_EXTERNAL_LIB}_LIBRARY ${${BLOSC_EXTERNAL_LIB}_LIBRARY_RELEASE}) + endif() + # FIXME: This probably should be set for both cases + set(${BLOSC_EXTERNAL_LIB}_LIBRARIES optimized ${${BLOSC_EXTERNAL_LIB}_LIBRARY_RELEASE} debug ${${BLOSC_EXTERNAL_LIB}_LIBRARY_DEBUG}) + endif() + + # if only the release version was found, set the debug variable also to the release version + if(${BLOSC_EXTERNAL_LIB}_LIBRARY_RELEASE AND NOT ${BLOSC_EXTERNAL_LIB}_LIBRARY_DEBUG) + set(${BLOSC_EXTERNAL_LIB}_LIBRARY_DEBUG ${${BLOSC_EXTERNAL_LIB}_LIBRARY_RELEASE}) + set(${BLOSC_EXTERNAL_LIB}_LIBRARY ${${BLOSC_EXTERNAL_LIB}_LIBRARY_RELEASE}) + set(${BLOSC_EXTERNAL_LIB}_LIBRARIES ${${BLOSC_EXTERNAL_LIB}_LIBRARY_RELEASE}) + endif() + + # if only the debug version was found, set the release variable also to the debug version + if(${BLOSC_EXTERNAL_LIB}_LIBRARY_DEBUG AND NOT ${BLOSC_EXTERNAL_LIB}_LIBRARY_RELEASE) + set(${BLOSC_EXTERNAL_LIB}_LIBRARY_RELEASE ${${BLOSC_EXTERNAL_LIB}_LIBRARY_DEBUG}) + set(${BLOSC_EXTERNAL_LIB}_LIBRARY ${${BLOSC_EXTERNAL_LIB}_LIBRARY_DEBUG}) + set(${BLOSC_EXTERNAL_LIB}_LIBRARIES ${${BLOSC_EXTERNAL_LIB}_LIBRARY_DEBUG}) + endif() + + target_link_libraries(Blosc::blosc INTERFACE + $<$:${${BLOSC_EXTERNAL_LIB}_LIBRARY_RELEASE}> + $<$:${${BLOSC_EXTERNAL_LIB}_LIBRARY_DEBUG}>) + + endforeach() + endif() + +endif() + diff --git a/cmake/modules/FindOpenVDB.cmake b/cmake/modules/FindOpenVDB.cmake index 76ddb0d2f3..e35b5f5a0d 100644 --- a/cmake/modules/FindOpenVDB.cmake +++ b/cmake/modules/FindOpenVDB.cmake @@ -1,28 +1,5 @@ -# Copyright (c) DreamWorks Animation LLC -# -# All rights reserved. This software is distributed under the -# Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ ) -# -# Redistributions of source code must retain the above copyright -# and license notice and the following restrictions and disclaimer. -# -# * Neither the name of DreamWorks Animation nor the names of -# its contributors may be used to endorse or promote products derived -# from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE -# LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00. +# Copyright Contributors to the OpenVDB Project +# SPDX-License-Identifier: Apache-2.0 # #[=======================================================================[.rst: @@ -37,7 +14,11 @@ Use this module by invoking find_package with the form:: [version] [EXACT] # Minimum or EXACT version [REQUIRED] # Fail with error if OpenVDB is not found [COMPONENTS ...] # OpenVDB libraries by their canonical name - # e.g. "openvdb" for "libopenvdb" + # e.g. "openvdb" for "libopenvdb", + # "pyopenvdb" for the python plugin + # "openvdb_ax" for the OpenVDB AX extension + # "openvdb_houdini" for the houdini plugin + # "nanovdb" for the nanovdb extension ) IMPORTED Targets @@ -45,6 +26,16 @@ IMPORTED Targets ``OpenVDB::openvdb`` The core openvdb library target. +``OpenVDB::openvdb_je`` + The core openvdb library target with jemalloc. +``OpenVDB::pyopenvdb`` + The openvdb python library target. +``OpenVDB::openvdb_houdini`` + The openvdb houdini library target. +``OpenVDB::openvdb_ax`` + The openvdb_ax library target. +``OpenVDB::nanovdb`` + The nanovdb library target. Result Variables ^^^^^^^^^^^^^^^^ @@ -63,14 +54,18 @@ This will define the following variables: OpenVDB library directories. ``OpenVDB_DEFINITIONS`` Definitions to use when compiling code that uses OpenVDB. -``OpenVDB_{COMPONENT}_FOUND`` +``OpenVDB_${COMPONENT}_FOUND`` True if the system has the named OpenVDB component. ``OpenVDB_USES_BLOSC`` True if the OpenVDB Library has been built with blosc support +``OpenVDB_USES_ZLIB`` + True if the OpenVDB Library has been built with zlib support ``OpenVDB_USES_LOG4CPLUS`` True if the OpenVDB Library has been built with log4cplus support -``OpenVDB_USES_EXR`` - True if the OpenVDB Library has been built with openexr support +``OpenVDB_USES_IMATH_HALF`` + True if the OpenVDB Library has been built with Imath half support +``OpenVDB_USES_DELAYED_LOADING`` + True if the OpenVDB Library has been built with delayed-loading ``OpenVDB_ABI`` Set if this module was able to determine the ABI number the located OpenVDB Library was built against. Unset otherwise. @@ -82,7 +77,9 @@ The following cache variables may also be set: ``OpenVDB_INCLUDE_DIR`` The directory containing ``openvdb/version.h``. -``OpenVDB_{COMPONENT}_LIBRARY`` +``OpenVDB_${COMPONENT}_INCLUDE_DIR`` + Individual component include directories for OpenVDB +``OpenVDB_${COMPONENT}_LIBRARY`` Individual component libraries for OpenVDB Hints @@ -91,55 +88,30 @@ Hints Instead of explicitly setting the cache variables, the following variables may be provided to tell this module where to look. -``OPENVDB_ROOT`` +``OpenVDB_ROOT`` Preferred installation prefix. ``OPENVDB_INCLUDEDIR`` Preferred include directory e.g. /include ``OPENVDB_LIBRARYDIR`` Preferred library directory e.g. /lib +``OPENVDB_${COMPONENT}_ROOT`` + Preferred installation prefix of a specific component. +``OPENVDB_${COMPONENT}_INCLUDEDIR`` + Preferred include directory of a specific component e.g. /include +``OPENVDB_${COMPONENT}_LIBRARYDIR`` + Preferred library directory of a specific component e.g. /lib ``SYSTEM_LIBRARY_PATHS`` - Paths appended to all include and lib searches. + Global list of library paths intended to be searched by and find_xxx call +``OPENVDB_USE_STATIC_LIBS`` + Only search for static openvdb libraries +``DISABLE_CMAKE_SEARCH_PATHS`` + Disable CMakes default search paths for find_xxx calls in this module #]=======================================================================] -# If an explicit openvdb module path was specified, that will be used -if (OPENVDB_FIND_MODULE_PATH) - set(_module_path_bak ${CMAKE_MODULE_PATH}) - set(CMAKE_MODULE_PATH ${OPENVDB_FIND_MODULE_PATH}) - find_package( - OpenVDB ${OpenVDB_FIND_VERSION} QUIET - COMPONENTS - ${OpenVDB_FIND_COMPONENTS} - ) - - set(CMAKE_MODULE_PATH ${_module_path_bak}) - if (OpenVDB_FOUND) - return() - endif () +cmake_minimum_required(VERSION 3.18) +include(GNUInstallDirs) - if (NOT OpenVDB_FIND_QUIETLY) - message(STATUS "Using bundled find module for OpenVDB") - endif () -endif () -# ########################################################################### - -cmake_minimum_required(VERSION 3.3) -# Monitoring _ROOT variables -if(POLICY CMP0074) - cmake_policy(SET CMP0074 NEW) -endif() - -if(OpenVDB_FIND_QUIETLY) - set (_quiet "QUIET") -else() - set (_quiet "") -endif() - -if(OpenVDB_FIND_REQUIRED) - set (_required "REQUIRED") -else() - set (_required "") -endif() # Include utility functions for version information include(${CMAKE_CURRENT_LIST_DIR}/OpenVDBUtils.cmake) @@ -149,8 +121,18 @@ mark_as_advanced( OpenVDB_LIBRARY ) +set(_FIND_OPENVDB_ADDITIONAL_OPTIONS "") +if(DISABLE_CMAKE_SEARCH_PATHS) + set(_FIND_OPENVDB_ADDITIONAL_OPTIONS NO_DEFAULT_PATH) +endif() + set(_OPENVDB_COMPONENT_LIST openvdb + openvdb_je + pyopenvdb + openvdb_ax + openvdb_houdini + nanovdb ) if(OpenVDB_FIND_COMPONENTS) @@ -171,16 +153,65 @@ if(OpenVDB_FIND_COMPONENTS) endif() else() set(OPENVDB_COMPONENTS_PROVIDED FALSE) - set(OpenVDB_FIND_COMPONENTS ${_OPENVDB_COMPONENT_LIST}) + set(OpenVDB_FIND_COMPONENTS openvdb) endif() -# Append OPENVDB_ROOT or $ENV{OPENVDB_ROOT} if set (prioritize the direct cmake var) -set(_OPENVDB_ROOT_SEARCH_DIR "") +# always make sure openvdb is picked up as a component i.e. +# find_package(OpenVDB COMPONENTS pyopenvdb) results in both +# openvdb and pyopenvdb targets. Also make sure it appears +# first in the component lists. +list(INSERT OpenVDB_FIND_COMPONENTS 0 openvdb) +list(REMOVE_DUPLICATES OpenVDB_FIND_COMPONENTS) + +# Set _OPENVDB_ROOT based on a user provided root var. Xxx_ROOT and ENV{Xxx_ROOT} +# are prioritised over the legacy capitalized XXX_ROOT variables for matching +# CMake 3.12 behaviour +# @todo deprecate -D and ENV OPENVDB_ROOT from CMake 3.12 +if(OpenVDB_ROOT) + set(_OPENVDB_ROOT ${OpenVDB_ROOT}) +elseif(DEFINED ENV{OpenVDB_ROOT}) + set(_OPENVDB_ROOT $ENV{OpenVDB_ROOT}) +elseif(OPENVDB_ROOT) + set(_OPENVDB_ROOT ${OPENVDB_ROOT}) +elseif(DEFINED ENV{OPENVDB_ROOT}) + set(_OPENVDB_ROOT $ENV{OPENVDB_ROOT}) +endif() # Additionally try and use pkconfig to find OpenVDB +if(USE_PKGCONFIG) + if(NOT DEFINED PKG_CONFIG_FOUND) + find_package(PkgConfig) + endif() + pkg_check_modules(PC_OpenVDB QUIET OpenVDB) +endif() -find_package(PkgConfig ${_quiet} ) -pkg_check_modules(PC_OpenVDB QUIET OpenVDB) +# This CMake module supports being called from external packages AND from +# within the OpenVDB repository for building openvdb components with the +# core library build disabled. Determine where we are being called from: +# +# (repo structure = /cmake/FindOpenVDB.cmake) +# (inst structure = /lib/cmake/OpenVDB/FindOpenVDB.cmake) + +get_filename_component(_DIR_NAME ${CMAKE_CURRENT_LIST_DIR} NAME) + +if(${_DIR_NAME} STREQUAL "cmake") + # Called from root repo for openvdb components +elseif(${_DIR_NAME} STREQUAL "OpenVDB") + # Set the install variable to track directories if this is being called from + # an installed location and from another package. The expected installation + # directory structure is: + # /lib/cmake/OpenVDB/FindOpenVDB.cmake + # /include + # /bin + get_filename_component(_IMPORT_PREFIX ${CMAKE_CURRENT_LIST_DIR} DIRECTORY) + get_filename_component(_IMPORT_PREFIX ${_IMPORT_PREFIX} DIRECTORY) + get_filename_component(_IMPORT_PREFIX ${_IMPORT_PREFIX} DIRECTORY) + set(_OPENVDB_INSTALL ${_IMPORT_PREFIX}) + list(APPEND _OPENVDB_ROOT ${_OPENVDB_INSTALL}) +endif() + +unset(_DIR_NAME) +unset(_IMPORT_PREFIX) # ------------------------------------------------------------------------ # Search for OpenVDB include DIR @@ -189,24 +220,99 @@ pkg_check_modules(PC_OpenVDB QUIET OpenVDB) set(_OPENVDB_INCLUDE_SEARCH_DIRS "") list(APPEND _OPENVDB_INCLUDE_SEARCH_DIRS ${OPENVDB_INCLUDEDIR} - ${_OPENVDB_ROOT_SEARCH_DIR} + ${_OPENVDB_ROOT} ${PC_OpenVDB_INCLUDE_DIRS} ${SYSTEM_LIBRARY_PATHS} ) -# Look for a standard OpenVDB header file. -find_path(OpenVDB_INCLUDE_DIR openvdb/version.h - PATHS ${_OPENVDB_INCLUDE_SEARCH_DIRS} - PATH_SUFFIXES include -) +foreach(COMPONENT ${OpenVDB_FIND_COMPONENTS}) + # Add in extra component paths + set(_VDB_COMPONENT_SEARCH_DIRS ${_OPENVDB_INCLUDE_SEARCH_DIRS}) + list(APPEND _VDB_COMPONENT_SEARCH_DIRS + ${OPENVDB_${COMPONENT}_ROOT} + ${OPENVDB_${COMPONENT}_INCLUDEDIR} + ) + if(_VDB_COMPONENT_SEARCH_DIRS) + list(REMOVE_DUPLICATES _VDB_COMPONENT_SEARCH_DIRS) + endif() + + # Look for a standard header files. + if(${COMPONENT} STREQUAL "openvdb") + # Look for a standard OpenVDB header file. + find_path(OpenVDB_${COMPONENT}_INCLUDE_DIR openvdb/version.h + ${_FIND_OPENVDB_ADDITIONAL_OPTIONS} + PATHS ${_VDB_COMPONENT_SEARCH_DIRS} + PATH_SUFFIXES + ${CMAKE_INSTALL_INCLUDEDIR} + include + ) + elseif(${COMPONENT} STREQUAL "pyopenvdb") + find_path(OpenVDB_${COMPONENT}_INCLUDE_DIR pyopenvdb.h + ${_FIND_OPENVDB_ADDITIONAL_OPTIONS} + PATHS ${_VDB_COMPONENT_SEARCH_DIRS} + PATH_SUFFIXES + ${CMAKE_INSTALL_INCLUDEDIR}/openvdb/python + ${CMAKE_INSTALL_INCLUDEDIR}/openvdb + ${CMAKE_INSTALL_INCLUDEDIR} + include + ) + elseif(${COMPONENT} STREQUAL "openvdb_ax") + # Look for a standard OpenVDB header file. + find_path(OpenVDB_${COMPONENT}_INCLUDE_DIR compiler/Compiler.h + ${_FIND_OPENVDB_ADDITIONAL_OPTIONS} + PATHS ${_VDB_COMPONENT_SEARCH_DIRS} + PATH_SUFFIXES + ${CMAKE_INSTALL_INCLUDEDIR}/openvdb/openvdb_ax + ${CMAKE_INSTALL_INCLUDEDIR}/openvdb_ax + ${CMAKE_INSTALL_INCLUDEDIR} + include + ) + elseif(${COMPONENT} STREQUAL "openvdb_houdini") + # @note Expects both houdini_utils and openvdb_houdini folders + # to be located in the same place + find_path(OpenVDB_${COMPONENT}_INCLUDE_DIR openvdb_houdini/SOP_NodeVDB.h + ${_FIND_OPENVDB_ADDITIONAL_OPTIONS} + PATHS ${_VDB_COMPONENT_SEARCH_DIRS} + PATH_SUFFIXES + ${CMAKE_INSTALL_INCLUDEDIR}/openvdb + ${CMAKE_INSTALL_INCLUDEDIR} + include + ) + elseif(${COMPONENT} STREQUAL "nanovdb") + # Look for NanoVDB.h + find_path(OpenVDB_${COMPONENT}_INCLUDE_DIR NanoVDB.h + ${_FIND_OPENVDB_ADDITIONAL_OPTIONS} + PATHS ${_VDB_COMPONENT_SEARCH_DIRS} + PATH_SUFFIXES + ${CMAKE_INSTALL_INCLUDEDIR}/nanovdb + ${CMAKE_INSTALL_INCLUDEDIR} + include + ) + endif() + unset(_VDB_COMPONENT_SEARCH_DIRS) +endforeach() -OPENVDB_VERSION_FROM_HEADER("${OpenVDB_INCLUDE_DIR}/openvdb/version.h" +set(OpenVDB_INCLUDE_DIR ${OpenVDB_openvdb_INCLUDE_DIR} + CACHE PATH "The OpenVDB core include directory") + +set(_OPENVDB_VERSION_HEADER "${OpenVDB_INCLUDE_DIR}/openvdb/version.h") +OPENVDB_VERSION_FROM_HEADER("${_OPENVDB_VERSION_HEADER}" VERSION OpenVDB_VERSION MAJOR OpenVDB_MAJOR_VERSION MINOR OpenVDB_MINOR_VERSION PATCH OpenVDB_PATCH_VERSION + ABI OpenVDB_ABI_FROM_HEADER # will be OpenVDB_MAJOR_VERSION prior to 8.1.0 ) +if(OpenVDB_VERSION VERSION_LESS 8.1.0) + set(_OPENVDB_HAS_NEW_VERSION_HEADER FALSE) + # ABI gets computed later +else() + set(_OPENVDB_HAS_NEW_VERSION_HEADER TRUE) + set(OpenVDB_ABI ${OpenVDB_ABI_FROM_HEADER}) +endif() +unset(OpenVDB_ABI_FROM_HEADER) + # ------------------------------------------------------------------------ # Search for OPENVDB lib DIR # ------------------------------------------------------------------------ @@ -217,87 +323,117 @@ set(_OPENVDB_LIBRARYDIR_SEARCH_DIRS "") list(APPEND _OPENVDB_LIBRARYDIR_SEARCH_DIRS ${OPENVDB_LIBRARYDIR} - ${_OPENVDB_ROOT_SEARCH_DIR} + ${_OPENVDB_ROOT} ${PC_OpenVDB_LIBRARY_DIRS} ${SYSTEM_LIBRARY_PATHS} ) -# Build suffix directories +# Library suffix handling + +set(_OPENVDB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) + +set(OPENVDB_PYTHON_PATH_SUFFIXES + lib64/python + lib64/python2.7 + lib64/python3 + lib/python + lib/python2.7 + lib/python3 +) + +# Recurse through all the site-packages and dist-packages on the file system +file(GLOB PYTHON_SITE_PACKAGES ${CMAKE_INSTALL_FULL_LIBDIR}/python**/*) +foreach(_site_package_full_dir ${PYTHON_SITE_PACKAGES}) + string(REPLACE ${CMAKE_INSTALL_FULL_LIBDIR} "${CMAKE_INSTALL_LIBDIR}" + _site_package_dir ${_site_package_full_dir}) + list(APPEND OPENVDB_PYTHON_PATH_SUFFIXES ${_site_package_dir}) +endforeach() -set(OPENVDB_PATH_SUFFIXES +set(OPENVDB_LIB_PATH_SUFFIXES + ${CMAKE_INSTALL_LIBDIR} lib64 lib ) +list(REMOVE_DUPLICATES OPENVDB_PYTHON_PATH_SUFFIXES) +list(REMOVE_DUPLICATES OPENVDB_LIB_PATH_SUFFIXES) + # Static library setup -if(UNIX AND OPENVDB_USE_STATIC_LIBS) - set(_OPENVDB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) - set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") +if(MSVC) + if(OPENVDB_USE_STATIC_LIBS) + set(CMAKE_FIND_LIBRARY_SUFFIXES ".lib") + endif() +else() + if(OPENVDB_USE_STATIC_LIBS) + set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") + endif() endif() set(OpenVDB_LIB_COMPONENTS "") -set(OpenVDB_DEBUG_SUFFIX "d" CACHE STRING "Suffix for the debug libraries") - -# get_property(_is_multi GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) -set(_is_multi FALSE) foreach(COMPONENT ${OpenVDB_FIND_COMPONENTS}) + message("COMPONENT = " ${COMPONENT}) set(LIB_NAME ${COMPONENT}) - find_library(OpenVDB_${COMPONENT}_LIBRARY_RELEASE ${LIB_NAME} lib${LIB_NAME} - PATHS ${_OPENVDB_LIBRARYDIR_SEARCH_DIRS} - PATH_SUFFIXES ${OPENVDB_PATH_SUFFIXES} - ) - - find_library(OpenVDB_${COMPONENT}_LIBRARY_DEBUG ${LIB_NAME}${OpenVDB_DEBUG_SUFFIX} lib${LIB_NAME}${OpenVDB_DEBUG_SUFFIX} - PATHS ${_OPENVDB_LIBRARYDIR_SEARCH_DIRS} - PATH_SUFFIXES ${OPENVDB_PATH_SUFFIXES} + # Add in extra component paths + set(_VDB_COMPONENT_SEARCH_DIRS ${_OPENVDB_LIBRARYDIR_SEARCH_DIRS}) + list(APPEND _VDB_COMPONENT_SEARCH_DIRS + ${OPENVDB_${COMPONENT}_ROOT} + ${OPENVDB_${COMPONENT}_LIBRARYDIR} ) - if (_is_multi) - list(APPEND OpenVDB_LIB_COMPONENTS ${OpenVDB_${COMPONENT}_LIBRARY_RELEASE}) - if (OpenVDB_${COMPONENT}_LIBRARY_DEBUG) - list(APPEND OpenVDB_LIB_COMPONENTS ${OpenVDB_${COMPONENT}_LIBRARY_DEBUG}) - endif () + if(${COMPONENT} STREQUAL "pyopenvdb") + set(_OPENVDB_ORIG_CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES}) + set(CMAKE_FIND_LIBRARY_PREFIXES ";lib") # find non-prefixed + find_library(OpenVDB_${COMPONENT}_LIBRARY ${LIB_NAME} + ${_FIND_OPENVDB_ADDITIONAL_OPTIONS} + PATHS ${_VDB_COMPONENT_SEARCH_DIRS} + PATH_SUFFIXES ${OPENVDB_PYTHON_PATH_SUFFIXES} + ) + set(CMAKE_FIND_LIBRARY_PREFIXES ${_OPENVDB_ORIG_CMAKE_FIND_LIBRARY_PREFIXES}) + elseif(${COMPONENT} STREQUAL "openvdb_je") + # alias to the result of openvdb which should be handled first + set(OpenVDB_${COMPONENT}_LIBRARY ${OpenVDB_openvdb_LIBRARY}) + elseif(${COMPONENT} STREQUAL "nanovdb") + # alias to the result of openvdb which should be handled first + set(OpenVDB_${COMPONENT}_LIBRARY ${OpenVDB_openvdb_LIBRARY}) + else() + find_library(OpenVDB_${COMPONENT}_LIBRARY ${LIB_NAME} + ${_FIND_OPENVDB_ADDITIONAL_OPTIONS} + PATHS ${_VDB_COMPONENT_SEARCH_DIRS} + PATH_SUFFIXES ${OPENVDB_LIB_PATH_SUFFIXES} + ) + endif() - list(FIND CMAKE_CONFIGURATION_TYPES "Debug" _has_debug) - - if(OpenVDB_${COMPONENT}_LIBRARY_RELEASE AND (NOT MSVC OR _has_debug LESS 0 OR OpenVDB_${COMPONENT}_LIBRARY_DEBUG)) + list(APPEND OpenVDB_LIB_COMPONENTS ${OpenVDB_${COMPONENT}_LIBRARY}) + if(${COMPONENT} STREQUAL "nanovdb") + # nanovdb is headers-only, no lib component + if(OpenVDB_${COMPONENT}_INCLUDE_DIR) set(OpenVDB_${COMPONENT}_FOUND TRUE) else() set(OpenVDB_${COMPONENT}_FOUND FALSE) endif() - - set(OpenVDB_${COMPONENT}_LIBRARY ${OpenVDB_${COMPONENT}_LIBRARY_RELEASE}) - else () - string(TOUPPER "${CMAKE_BUILD_TYPE}" _BUILD_TYPE) - - set(OpenVDB_${COMPONENT}_LIBRARY ${OpenVDB_${COMPONENT}_LIBRARY_${_BUILD_TYPE}}) - - if (NOT OpenVDB_${COMPONENT}_LIBRARY) - set(OpenVDB_${COMPONENT}_LIBRARY ${OpenVDB_${COMPONENT}_LIBRARY_RELEASE}) - endif () - - list(APPEND OpenVDB_LIB_COMPONENTS ${OpenVDB_${COMPONENT}_LIBRARY}) - + else() if(OpenVDB_${COMPONENT}_LIBRARY) set(OpenVDB_${COMPONENT}_FOUND TRUE) else() set(OpenVDB_${COMPONENT}_FOUND FALSE) endif() - endif () - + endif() + unset(_VDB_COMPONENT_SEARCH_DIRS) endforeach() -if(UNIX AND OPENVDB_USE_STATIC_LIBS) - set(CMAKE_FIND_LIBRARY_SUFFIXES ${_OPENVDB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) - unset(_OPENVDB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES) -endif() +unset(OPENVDB_PYTHON_PATH_SUFFIXES) +unset(OPENVDB_LIB_PATH_SUFFIXES) + +# Reset library suffix + +set(CMAKE_FIND_LIBRARY_SUFFIXES ${_OPENVDB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) +unset(_OPENVDB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES) # ------------------------------------------------------------------------ # Cache and set OPENVDB_FOUND # ------------------------------------------------------------------------ - include(FindPackageHandleStandardArgs) find_package_handle_standard_args(OpenVDB FOUND_VAR OpenVDB_FOUND @@ -312,13 +448,23 @@ find_package_handle_standard_args(OpenVDB # Determine ABI number # ------------------------------------------------------------------------ -# Set the ABI number the library was built against. Uses vdb_print -find_program(OPENVDB_PRINT vdb_print PATHS ${OpenVDB_INCLUDE_DIR} ) +# Set the ABI number the library was built against. The old system, +# which didn't define the ABI in the build config, uses vdb_print -OPENVDB_ABI_VERSION_FROM_PRINT( - "${OPENVDB_PRINT}" - ABI OpenVDB_ABI -) +if(NOT _OPENVDB_HAS_NEW_VERSION_HEADER) + if(_OPENVDB_INSTALL) + OPENVDB_ABI_VERSION_FROM_PRINT( + "${_OPENVDB_INSTALL}/bin/vdb_print" + ABI OpenVDB_ABI + ) + else() + # Try and find vdb_print from the include path + OPENVDB_ABI_VERSION_FROM_PRINT( + "${OpenVDB_INCLUDE_DIR}/../bin/vdb_print" + ABI OpenVDB_ABI + ) + endif() +endif() if(NOT OpenVDB_FIND_QUIETLY) if(NOT OpenVDB_ABI) @@ -333,166 +479,184 @@ if(NOT OpenVDB_FIND_QUIETLY) endif() # ------------------------------------------------------------------------ -# Handle OpenVDB dependencies +# Handle OpenVDB dependencies and interface settings # ------------------------------------------------------------------------ +# Handle openvdb_houdini first to configure search paths + +if(openvdb_houdini IN_LIST OpenVDB_FIND_COMPONENTS) + include(OpenVDBHoudiniSetup) +endif() + # Add standard dependencies -macro(just_fail msg) - set(OpenVDB_FOUND FALSE) - if(OpenVDB_FIND_REQUIRED) - message(FATAL_ERROR ${msg}) - elseif(NOT OpenVDB_FIND_QUIETLY) - message(WARNING ${msg}) - endif() - return() -endmacro() +find_package(TBB REQUIRED COMPONENTS tbb) -find_package(IlmBase QUIET) -if(NOT IlmBase_FOUND) - pkg_check_modules(IlmBase QUIET IlmBase) -endif() -if (IlmBase_FOUND AND NOT TARGET IlmBase::Half) - message(STATUS "Falling back to IlmBase found by pkg-config...") +# Add deps for pyopenvdb - find_library(IlmHalf_LIBRARY NAMES Half) - if(IlmHalf_LIBRARY-NOTFOUND OR NOT IlmBase_INCLUDE_DIRS) - just_fail("IlmBase::Half can not be found!") - endif() - - add_library(IlmBase::Half UNKNOWN IMPORTED) - set_target_properties(IlmBase::Half PROPERTIES - IMPORTED_LOCATION "${IlmHalf_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${IlmBase_INCLUDE_DIRS}") -elseif(NOT IlmBase_FOUND) - just_fail("IlmBase::Half can not be found!") +if(pyopenvdb IN_LIST OpenVDB_FIND_COMPONENTS) + find_package(Python REQUIRED) endif() -find_package(TBB ${_quiet} ${_required} COMPONENTS tbb) -find_package(ZLIB ${_quiet} ${_required}) -find_package(Boost ${_quiet} ${_required} COMPONENTS iostreams system ) -# Use GetPrerequisites to see which libraries this OpenVDB lib has linked to -# which we can query for optional deps. This basically runs ldd/otoll/objdump -# etc to track deps. We could use a vdb_config binary tools here to improve -# this process +# Add deps for openvdb_ax -include(GetPrerequisites) +if(openvdb_ax IN_LIST OpenVDB_FIND_COMPONENTS) + find_package(LLVM REQUIRED) + find_library(found_LLVM LLVM HINTS ${LLVM_LIBRARY_DIRS}) -set(_EXCLUDE_SYSTEM_PREREQUISITES 1) -set(_RECURSE_PREREQUISITES 0) -set(_OPENVDB_PREREQUISITE_LIST) + if(found_LLVM) + set(LLVM_LIBS "LLVM") + else() + llvm_map_components_to_libnames(_llvm_libs + native core executionengine support mcjit passes objcarcopts) + set(LLVM_LIBS "${_llvm_libs}") + endif() -if(NOT OPENVDB_USE_STATIC_LIBS) -get_prerequisites(${OpenVDB_openvdb_LIBRARY} - _OPENVDB_PREREQUISITE_LIST - ${_EXCLUDE_SYSTEM_PREREQUISITES} - ${_RECURSE_PREREQUISITES} - "" - "${SYSTEM_LIBRARY_PATHS}" -) + if(NOT OpenVDB_FIND_QUIET) + message(STATUS "Found LLVM: ${LLVM_DIR} (found version \"${LLVM_PACKAGE_VERSION}\")") + endif() endif() -unset(_EXCLUDE_SYSTEM_PREREQUISITES) -unset(_RECURSE_PREREQUISITES) - # As the way we resolve optional libraries relies on library file names, use # the configuration options from the main CMakeLists.txt to allow users # to manually identify the requirements of OpenVDB builds if they know them. - set(OpenVDB_USES_BLOSC ${USE_BLOSC}) +set(OpenVDB_USES_ZLIB ${USE_ZLIB}) set(OpenVDB_USES_LOG4CPLUS ${USE_LOG4CPLUS}) -set(OpenVDB_USES_ILM ${USE_EXR}) -set(OpenVDB_USES_EXR ${USE_EXR}) +set(OpenVDB_USES_IMATH_HALF ${USE_IMATH_HALF}) +set(OpenVDB_USES_DELAYED_LOADING ${OPENVDB_USE_DELAYED_LOADING}) +set(OpenVDB_DEFINITIONS) -# Search for optional dependencies +if(WIN32) + if(OPENVDB_USE_STATIC_LIBS) + list(APPEND OpenVDB_DEFINITIONS OPENVDB_STATICLIB) + else() + list(APPEND OpenVDB_DEFINITIONS OPENVDB_DLL) + endif() + # Newer version of OpenVDB define these in Platform.h, but they are also + # provided here to maintain backwards compatibility with header include + # others + list(APPEND OpenVDB_DEFINITIONS _WIN32) + list(APPEND OpenVDB_DEFINITIONS NOMINMAX) +endif() -foreach(PREREQUISITE ${_OPENVDB_PREREQUISITE_LIST}) - set(_HAS_DEP) - get_filename_component(PREREQUISITE ${PREREQUISITE} NAME) +if(MINGW) + list(APPEND OpenVDB_DEFINITIONS _USE_MATH_DEFINES) +endif() - string(FIND ${PREREQUISITE} "blosc" _HAS_DEP) - if(NOT ${_HAS_DEP} EQUAL -1) - set(OpenVDB_USES_BLOSC ON) - endif() +if(OpenVDB_ABI) + # Newer version of OpenVDB defines this in version.h, but it is are also + # provided here to maintain backwards compatibility with header include + # others + list(APPEND OpenVDB_DEFINITIONS OPENVDB_ABI_VERSION_NUMBER=${OpenVDB_ABI}) +endif() - string(FIND ${PREREQUISITE} "log4cplus" _HAS_DEP) - if(NOT ${_HAS_DEP} EQUAL -1) - set(OpenVDB_USES_LOG4CPLUS ON) - endif() +# Configure deps + +if(_OPENVDB_HAS_NEW_VERSION_HEADER) + OPENVDB_GET_VERSION_DEFINE(${_OPENVDB_VERSION_HEADER} "OPENVDB_USE_IMATH_HALF" OpenVDB_USES_IMATH_HALF) + OPENVDB_GET_VERSION_DEFINE(${_OPENVDB_VERSION_HEADER} "OPENVDB_USE_BLOSC" OpenVDB_USES_BLOSC) + OPENVDB_GET_VERSION_DEFINE(${_OPENVDB_VERSION_HEADER} "OPENVDB_USE_ZLIB" OpenVDB_USES_ZLIB) + OPENVDB_GET_VERSION_DEFINE(${_OPENVDB_VERSION_HEADER} "OPENVDB_USE_DELAYED_LOADING" OpenVDB_USES_DELAYED_LOADING) +elseif(NOT OPENVDB_USE_STATIC_LIBS) + # Use GetPrerequisites to see which libraries this OpenVDB lib has linked to + # which we can query for optional deps. This basically runs ldd/otoll/objdump + # etc to track deps. We could use a vdb_config binary tools here to improve + # this process + include(GetPrerequisites) + + set(_EXCLUDE_SYSTEM_PREREQUISITES 1) + set(_RECURSE_PREREQUISITES 0) + set(_OPENVDB_PREREQUISITE_LIST) + + get_prerequisites(${OpenVDB_openvdb_LIBRARY} + _OPENVDB_PREREQUISITE_LIST + ${_EXCLUDE_SYSTEM_PREREQUISITES} + ${_RECURSE_PREREQUISITES} + "" + "${SYSTEM_LIBRARY_PATHS}" + ) - string(FIND ${PREREQUISITE} "IlmImf" _HAS_DEP) - if(NOT ${_HAS_DEP} EQUAL -1) - set(OpenVDB_USES_ILM ON) - endif() -endforeach() + unset(_EXCLUDE_SYSTEM_PREREQUISITES) + unset(_RECURSE_PREREQUISITES) -unset(_OPENVDB_PREREQUISITE_LIST) -unset(_HAS_DEP) + # Search for optional dependencies + foreach(PREREQUISITE ${_OPENVDB_PREREQUISITE_LIST}) + set(_HAS_DEP) + get_filename_component(PREREQUISITE ${PREREQUISITE} NAME) -if(OpenVDB_USES_BLOSC) - find_package(Blosc QUIET) - if(NOT Blosc_FOUND OR NOT TARGET Blosc::blosc) - message(STATUS "find_package could not find Blosc. Using fallback blosc search...") - find_path(Blosc_INCLUDE_DIR blosc.h) - find_library(Blosc_LIBRARY NAMES blosc) - if (Blosc_INCLUDE_DIR AND Blosc_LIBRARY) - set(Blosc_FOUND TRUE) - add_library(Blosc::blosc UNKNOWN IMPORTED) - set_target_properties(Blosc::blosc PROPERTIES - IMPORTED_LOCATION "${Blosc_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES ${Blosc_INCLUDE_DIR}) - elseif() - just_fail("Blosc library can not be found!") + string(FIND ${PREREQUISITE} "blosc" _HAS_DEP) + if(NOT ${_HAS_DEP} EQUAL -1) + set(OpenVDB_USES_BLOSC ON) endif() - endif() + + string(FIND ${PREREQUISITE} "zlib" _HAS_DEP) + if(NOT ${_HAS_DEP} EQUAL -1) + set(OpenVDB_USES_ZLIB ON) + endif() + + string(FIND ${PREREQUISITE} "log4cplus" _HAS_DEP) + if(NOT ${_HAS_DEP} EQUAL -1) + set(OpenVDB_USES_LOG4CPLUS ON) + endif() + + string(FIND ${PREREQUISITE} "Half" _HAS_DEP) + if(NOT ${_HAS_DEP} EQUAL -1) + set(OpenVDB_USES_IMATH_HALF ON) + endif() + + string(FIND ${PREREQUISITE} "boost_iostreams" _HAS_DEP) + if(NOT ${_HAS_DEP} EQUAL -1) + set(OpenVDB_USES_DELAYED_LOADING ON) + endif() + endforeach() + + unset(_OPENVDB_PREREQUISITE_LIST) +endif() + +if(OpenVDB_USES_BLOSC) + find_package(Blosc REQUIRED) +endif() + +if(OpenVDB_USES_ZLIB) + find_package(ZLIB REQUIRED) endif() if(OpenVDB_USES_LOG4CPLUS) - find_package(Log4cplus ${_quiet} ${_required}) + find_package(Log4cplus REQUIRED) endif() -if(OpenVDB_USES_ILM) - find_package(IlmBase ${_quiet} ${_required}) +if(OpenVDB_USES_IMATH_HALF) + find_package(Imath REQUIRED CONFIG) endif() -if(OpenVDB_USES_EXR) - find_package(OpenEXR ${_quiet} ${_required}) +if(OpenVDB_USES_DELAYED_LOADING) + find_package(Boost REQUIRED COMPONENTS iostreams) endif() if(UNIX) - find_package(Threads ${_quiet} ${_required}) + find_package(Threads REQUIRED) endif() # Set deps. Note that the order here is important. If we're building against -# Houdini 17.5 we must include OpenEXR and IlmBase deps first to ensure the -# users chosen namespaced headers are correctly prioritized. Otherwise other -# include paths from shared installs (including houdini) may pull in the wrong -# headers - -set(_OPENVDB_VISIBLE_DEPENDENCIES - Boost::iostreams - Boost::system - IlmBase::Half -) +# Houdini we must include Imath deps first to ensure the users chosen +# namespaced headers are correctly prioritized. Otherwise other include paths +# from shared installs (including houdini) may pull in the wrong headers -set(_OPENVDB_DEFINITIONS) -if(OpenVDB_ABI) - list(APPEND _OPENVDB_DEFINITIONS "-DOPENVDB_ABI_VERSION_NUMBER=${OpenVDB_ABI}") +set(_OPENVDB_VISIBLE_DEPENDENCIES "") + +if(OpenVDB_USES_DELAYED_LOADING) + list(APPEND _OPENVDB_VISIBLE_DEPENDENCIES Boost::iostreams) + list(APPEND OpenVDB_DEFINITIONS OPENVDB_USE_DELAYED_LOADING) endif() -if(OpenVDB_USES_EXR) - list(APPEND _OPENVDB_VISIBLE_DEPENDENCIES - IlmBase::IlmThread - IlmBase::Iex - IlmBase::Imath - OpenEXR::IlmImf - ) - list(APPEND _OPENVDB_DEFINITIONS "-DOPENVDB_TOOLS_RAYTRACER_USE_EXR") +if(OpenVDB_USES_IMATH_HALF) + list(APPEND _OPENVDB_VISIBLE_DEPENDENCIES Imath::Imath) endif() if(OpenVDB_USES_LOG4CPLUS) list(APPEND _OPENVDB_VISIBLE_DEPENDENCIES Log4cplus::log4cplus) - list(APPEND _OPENVDB_DEFINITIONS "-DOPENVDB_USE_LOG4CPLUS") + list(APPEND OpenVDB_DEFINITIONS OPENVDB_USE_LOG4CPLUS) endif() list(APPEND _OPENVDB_VISIBLE_DEPENDENCIES @@ -506,34 +670,26 @@ endif() set(_OPENVDB_HIDDEN_DEPENDENCIES) -if(OpenVDB_USES_BLOSC) - if(OPENVDB_USE_STATIC_LIBS) - list(APPEND _OPENVDB_VISIBLE_DEPENDENCIES $) - else() +if(NOT OPENVDB_USE_STATIC_LIBS) + if(OpenVDB_USES_BLOSC) list(APPEND _OPENVDB_HIDDEN_DEPENDENCIES Blosc::blosc) endif() + if(OpenVDB_USES_ZLIB) + list(APPEND _OPENVDB_HIDDEN_DEPENDENCIES ZLIB::ZLIB) + endif() endif() -if(OPENVDB_USE_STATIC_LIBS) - list(APPEND _OPENVDB_VISIBLE_DEPENDENCIES $) -else() - list(APPEND _OPENVDB_HIDDEN_DEPENDENCIES ZLIB::ZLIB) +if(openvdb_je IN_LIST OpenVDB_FIND_COMPONENTS) + find_package(Jemalloc REQUIRED) endif() # ------------------------------------------------------------------------ -# Configure imported target +# Configure imported targets # ------------------------------------------------------------------------ -set(OpenVDB_LIBRARIES - ${OpenVDB_LIB_COMPONENTS} -) +set(OpenVDB_LIBRARIES ${OpenVDB_LIB_COMPONENTS}) set(OpenVDB_INCLUDE_DIRS ${OpenVDB_INCLUDE_DIR}) -set(OpenVDB_DEFINITIONS) -list(APPEND OpenVDB_DEFINITIONS "${PC_OpenVDB_CFLAGS_OTHER}") -list(APPEND OpenVDB_DEFINITIONS "${_OPENVDB_DEFINITIONS}") -list(REMOVE_DUPLICATES OpenVDB_DEFINITIONS) - set(OpenVDB_LIBRARY_DIRS "") foreach(LIB ${OpenVDB_LIB_COMPONENTS}) get_filename_component(_OPENVDB_LIBDIR ${LIB} DIRECTORY) @@ -541,49 +697,116 @@ foreach(LIB ${OpenVDB_LIB_COMPONENTS}) endforeach() list(REMOVE_DUPLICATES OpenVDB_LIBRARY_DIRS) -foreach(COMPONENT ${OpenVDB_FIND_COMPONENTS}) - if(NOT TARGET OpenVDB::${COMPONENT}) - if (${COMPONENT} STREQUAL openvdb) - include (${CMAKE_CURRENT_LIST_DIR}/CheckAtomic.cmake) - set(_LINK_LIBS ${_OPENVDB_VISIBLE_DEPENDENCIES} ${CMAKE_REQUIRED_LIBRARIES}) - else () - set(_LINK_LIBS _OPENVDB_VISIBLE_DEPENDENCIES) - endif () - - add_library(OpenVDB::${COMPONENT} UNKNOWN IMPORTED) - set_target_properties(OpenVDB::${COMPONENT} PROPERTIES - INTERFACE_COMPILE_OPTIONS "${OpenVDB_DEFINITIONS}" - INTERFACE_INCLUDE_DIRECTORIES "${OpenVDB_INCLUDE_DIR}" - IMPORTED_LINK_DEPENDENT_LIBRARIES "${_OPENVDB_HIDDEN_DEPENDENCIES}" # non visible deps - INTERFACE_LINK_LIBRARIES "${_LINK_LIBS}" # visible deps (headers) - INTERFACE_COMPILE_FEATURES cxx_std_11 - IMPORTED_LOCATION "${OpenVDB_${COMPONENT}_LIBRARY}" +# OpenVDB::openvdb + +if(NOT TARGET OpenVDB::openvdb) + set(OPENVDB_openvdb_LIB_TYPE UNKNOWN) + if(OPENVDB_USE_STATIC_LIBS) + set(OPENVDB_openvdb_LIB_TYPE STATIC) + elseif(UNIX) + get_filename_component(_OPENVDB_openvdb_EXT + ${OpenVDB_openvdb_LIBRARY} EXT) + if(_OPENVDB_openvdb_EXT STREQUAL ".a") + set(OPENVDB_openvdb_LIB_TYPE STATIC) + elseif(_OPENVDB_openvdb_EXT STREQUAL ".so" OR + _OPENVDB_openvdb_EXT STREQUAL ".dylib") + set(OPENVDB_openvdb_LIB_TYPE SHARED) + endif() + endif() + + add_library(OpenVDB::openvdb ${OPENVDB_openvdb_LIB_TYPE} IMPORTED) + set_target_properties(OpenVDB::openvdb PROPERTIES + IMPORTED_LOCATION "${OpenVDB_openvdb_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${PC_OpenVDB_CFLAGS_OTHER}" + INTERFACE_COMPILE_DEFINITIONS "${OpenVDB_DEFINITIONS}" + INTERFACE_INCLUDE_DIRECTORIES "${OpenVDB_INCLUDE_DIR}" + IMPORTED_LINK_DEPENDENT_LIBRARIES "${_OPENVDB_HIDDEN_DEPENDENCIES}" # non visible deps + INTERFACE_LINK_LIBRARIES "${_OPENVDB_VISIBLE_DEPENDENCIES}" # visible deps (headers) + INTERFACE_COMPILE_FEATURES cxx_std_17 + ) +endif() + +# OpenVDB::openvdb_je + +if(OpenVDB_openvdb_je_LIBRARY) + if(NOT TARGET OpenVDB::openvdb_je) + add_library(OpenVDB::openvdb_je INTERFACE IMPORTED) + target_link_libraries(OpenVDB::openvdb_je INTERFACE OpenVDB::openvdb) + target_link_libraries(OpenVDB::openvdb_je INTERFACE Jemalloc::jemalloc) + endif() +endif() + +# OpenVDB::pyopenvdb + +if(OpenVDB_pyopenvdb_LIBRARY) + if(NOT TARGET OpenVDB::pyopenvdb) + add_library(OpenVDB::pyopenvdb MODULE IMPORTED) + set_target_properties(OpenVDB::pyopenvdb PROPERTIES + IMPORTED_LOCATION "${OpenVDB_pyopenvdb_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${OpenVDB_pyopenvdb_INCLUDE_DIR};${PYTHON_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES "OpenVDB::openvdb;${PYTHON_LIBRARIES}" + INTERFACE_COMPILE_FEATURES cxx_std_17 + ) + endif() +endif() + +# OpenVDB::openvdb_houdini + +if(OpenVDB_openvdb_houdini_LIBRARY) + if(NOT TARGET OpenVDB::openvdb_houdini) + add_library(OpenVDB::openvdb_houdini SHARED IMPORTED) + set_target_properties(OpenVDB::openvdb_houdini PROPERTIES + IMPORTED_LOCATION "${OpenVDB_openvdb_houdini_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${OpenVDB_openvdb_houdini_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES "OpenVDB::openvdb;Houdini" + INTERFACE_COMPILE_FEATURES cxx_std_17 ) + endif() +endif() + +# OpenVDB::openvdb_ax - if (_is_multi) - set_target_properties(OpenVDB::${COMPONENT} PROPERTIES - IMPORTED_LOCATION_RELEASE "${OpenVDB_${COMPONENT}_LIBRARY_RELEASE}" - ) - - if (MSVC OR OpenVDB_${COMPONENT}_LIBRARY_DEBUG) - set_target_properties(OpenVDB::${COMPONENT} PROPERTIES - IMPORTED_LOCATION_DEBUG "${OpenVDB_${COMPONENT}_LIBRARY_DEBUG}" - ) - endif () - endif () - - if (OPENVDB_USE_STATIC_LIBS) - set_target_properties(OpenVDB::${COMPONENT} PROPERTIES - INTERFACE_COMPILE_DEFINITIONS "OPENVDB_STATICLIB;OPENVDB_OPENEXR_STATICLIB" +if(OpenVDB_openvdb_ax_LIBRARY) + set(OPENVDB_openvdb_ax_LIB_TYPE UNKNOWN) + if(OPENVDB_USE_STATIC_LIBS) + set(OPENVDB_openvdb_ax_LIB_TYPE STATIC) + elseif(UNIX) + get_filename_component(_OPENVDB_openvdb_ax_EXT + ${OpenVDB_openvdb_ax_LIBRARY} EXT) + if(_OPENVDB_openvdb_ax_EXT STREQUAL ".a") + set(OPENVDB_openvdb_ax_LIB_TYPE STATIC) + elseif(_OPENVDB_openvdb_ax_EXT STREQUAL ".so" OR + _OPENVDB_openvdb_ax_EXT STREQUAL ".dylib") + set(OPENVDB_openvdb_ax_LIB_TYPE SHARED) + endif() + endif() + + + if(NOT TARGET OpenVDB::openvdb_ax) + add_library(OpenVDB::openvdb_ax UNKNOWN IMPORTED) + set_target_properties(OpenVDB::openvdb_ax PROPERTIES + IMPORTED_LOCATION "${OpenVDB_openvdb_ax_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${OpenVDB_openvdb_ax_INCLUDE_DIR}" + INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${LLVM_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "OpenVDB::openvdb;${LLVM_LIBS}" + INTERFACE_COMPILE_FEATURES cxx_std_17 ) - endif() endif() -endforeach() +endif() + +# OpenVDB::nanovdb -if(OpenVDB_FOUND AND NOT OpenVDB_FIND_QUIETLY) - message(STATUS "OpenVDB libraries: ${OpenVDB_LIBRARIES}") +if(OpenVDB_nanovdb_LIBRARY) + if(NOT TARGET OpenVDB::nanovdb) + add_library(OpenVDB::nanovdb INTERFACE IMPORTED) + set_target_properties(OpenVDB::nanovdb PROPERTIES + IMPORTED_LOCATION "${OpenVDB_nanovdb_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${OpenVDB_nanovdb_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES "OpenVDB::openvdb;" + INTERFACE_COMPILE_FEATURES cxx_std_17 + ) + endif() endif() -unset(_OPENVDB_DEFINITIONS) unset(_OPENVDB_VISIBLE_DEPENDENCIES) unset(_OPENVDB_HIDDEN_DEPENDENCIES) diff --git a/cmake/modules/OpenVDBUtils.cmake b/cmake/modules/OpenVDBUtils.cmake index f79862b83a..6e8426c112 100644 --- a/cmake/modules/OpenVDBUtils.cmake +++ b/cmake/modules/OpenVDBUtils.cmake @@ -1,28 +1,5 @@ -# Copyright (c) DreamWorks Animation LLC -# -# All rights reserved. This software is distributed under the -# Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ ) -# -# Redistributions of source code must retain the above copyright -# and license notice and the following restrictions and disclaimer. -# -# * Neither the name of DreamWorks Animation nor the names of -# its contributors may be used to endorse or promote products derived -# from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE -# LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00. +# Copyright Contributors to the OpenVDB Project +# SPDX-License-Identifier: Apache-2.0 # #[=======================================================================[.rst: @@ -39,6 +16,17 @@ Use this module by invoking include with the form:: The following functions are provided: +``OPENVDB_GET_VERSION_DEFINE`` + + OPENVDB_GET_VERSION_DEFINE ( ) + + Parse the provided version file to retrieve the a given OpenVDB define + specified by and store the result in . If the define has a + value, the value is stored. If the define has no value but exists, ON is + stored. Else, OFF is stored. + + If the file does not exist, is unmodified. + ``OPENVDB_VERSION_FROM_HEADER`` OPENVDB_VERSION_FROM_HEADER ( @@ -69,35 +57,47 @@ The following functions are provided: #]=======================================================================] +cmake_minimum_required(VERSION 3.18) + + +function(OPENVDB_GET_VERSION_DEFINE HEADER KEY VALUE) + if(NOT EXISTS ${HEADER}) + return() + endif() + + file(STRINGS "${HEADER}" details REGEX "^#define[\t ]+${KEY}[\t ]+.*") + if(details) + # define has a value, extract it and return + string(REGEX REPLACE "^.*${KEY}[\t ]+([0-9]*).*$" "\\1" details "${details}") + set(${VALUE} ${details} PARENT_SCOPE) + return() + endif() + + # try re-searching for single defines + file(STRINGS "${HEADER}" details REGEX "^#define[\t ]+${KEY}.*") + if(details) + set(${VALUE} ON PARENT_SCOPE) + else() + set(${VALUE} OFF PARENT_SCOPE) + endif() +endfunction() + + +######################################################################## +######################################################################## + function(OPENVDB_VERSION_FROM_HEADER OPENVDB_VERSION_FILE) - cmake_parse_arguments(_VDB "" "VERSION;MAJOR;MINOR;PATCH" "" ${ARGN}) + cmake_parse_arguments(_VDB "" "VERSION;MAJOR;MINOR;PATCH;ABI" "" ${ARGN}) if(NOT EXISTS ${OPENVDB_VERSION_FILE}) return() endif() - file(STRINGS "${OPENVDB_VERSION_FILE}" openvdb_version_str - REGEX "^#define[\t ]+OPENVDB_LIBRARY_MAJOR_VERSION_NUMBER[\t ]+.*" - ) - string(REGEX REPLACE "^.*OPENVDB_LIBRARY_MAJOR_VERSION_NUMBER[\t ]+([0-9]*).*$" "\\1" - _OpenVDB_MAJOR_VERSION "${openvdb_version_str}" - ) - - file(STRINGS "${OPENVDB_VERSION_FILE}" openvdb_version_str - REGEX "^#define[\t ]+OPENVDB_LIBRARY_MINOR_VERSION_NUMBER[\t ]+.*" - ) - string(REGEX REPLACE "^.*OPENVDB_LIBRARY_MINOR_VERSION_NUMBER[\t ]+([0-9]*).*$" "\\1" - _OpenVDB_MINOR_VERSION "${openvdb_version_str}" - ) - - file(STRINGS "${OPENVDB_VERSION_FILE}" openvdb_version_str - REGEX "^#define[\t ]+OPENVDB_LIBRARY_PATCH_VERSION_NUMBER[\t ]+.*" - ) - string(REGEX REPLACE "^.*OPENVDB_LIBRARY_PATCH_VERSION_NUMBER[\t ]+([0-9]*).*$" "\\1" - _OpenVDB_PATCH_VERSION "${openvdb_version_str}" - ) - unset(openvdb_version_str) + OPENVDB_GET_VERSION_DEFINE(${OPENVDB_VERSION_FILE} "OPENVDB_LIBRARY_MAJOR_VERSION_NUMBER" _OpenVDB_MAJOR_VERSION) + OPENVDB_GET_VERSION_DEFINE(${OPENVDB_VERSION_FILE} "OPENVDB_LIBRARY_MINOR_VERSION_NUMBER" _OpenVDB_MINOR_VERSION) + OPENVDB_GET_VERSION_DEFINE(${OPENVDB_VERSION_FILE} "OPENVDB_LIBRARY_PATCH_VERSION_NUMBER" _OpenVDB_PATCH_VERSION) + OPENVDB_GET_VERSION_DEFINE(${OPENVDB_VERSION_FILE} "OPENVDB_ABI_VERSION_NUMBER" _OpenVDB_ABI_VERSION) if(_VDB_VERSION) set(${_VDB_VERSION} @@ -114,6 +114,9 @@ function(OPENVDB_VERSION_FROM_HEADER OPENVDB_VERSION_FILE) if(_VDB_PATCH) set(${_VDB_PATCH} ${_OpenVDB_PATCH_VERSION} PARENT_SCOPE) endif() + if(_VDB_ABI) + set(${_VDB_ABI} ${_OpenVDB_ABI_VERSION} PARENT_SCOPE) + endif() endfunction() @@ -125,9 +128,6 @@ function(OPENVDB_ABI_VERSION_FROM_PRINT OPENVDB_PRINT) cmake_parse_arguments(_VDB "QUIET" "ABI" "" ${ARGN}) if(NOT EXISTS ${OPENVDB_PRINT}) - if(NOT OpenVDB_FIND_QUIETLY) - message(WARNING "vdb_print not found! ${OPENVDB_PRINT}") - endif() return() endif() @@ -150,19 +150,11 @@ function(OPENVDB_ABI_VERSION_FROM_PRINT OPENVDB_PRINT) endif() if(${_VDB_PRINT_RETURN_STATUS}) - if(NOT OpenVDB_FIND_QUIETLY) - message(WARNING "vdb_print returned with status ${_VDB_PRINT_RETURN_STATUS}") - endif() return() endif() set(_OpenVDB_ABI) - if (_VDB_PRINT_VERSION_STRING) - string(REGEX REPLACE ".*abi([0-9]*).*" "\\1" _OpenVDB_ABI ${_VDB_PRINT_VERSION_STRING}) - endif () - if(${_OpenVDB_ABI} STREQUAL ${_VDB_PRINT_VERSION_STRING}) - set(_OpenVDB_ABI "") - endif() + string(REGEX REPLACE ".*abi([0-9]*).*" "\\1" _OpenVDB_ABI ${_VDB_PRINT_VERSION_STRING}) unset(_VDB_PRINT_RETURN_STATUS) unset(_VDB_PRINT_VERSION_STRING) diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 6f94e7acf7..cfcf13a688 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -16,8 +16,8 @@ # On Windows, architecture (64 vs 32 bits) is judged based on the compiler variant. # To build dependencies for either 64 or 32 bit OS, use the respective compiler command line. # -# WARNING: On UNIX platforms wxWidgets hardcode the destdir path into its `wx-conffig` utility, -# therefore, unfortunatelly, the installation cannot be copied/moved elsewhere without re-installing wxWidgets. +# WARNING: On UNIX platforms wxWidgets hardcode the destdir path into its `wx-config` utility, +# therefore, unfortunately, the installation cannot be copied/moved elsewhere without re-installing wxWidgets. # project(BambuStudio-deps)