FindOpenVDB.cmake 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. # Copyright (c) DreamWorks Animation LLC
  2. #
  3. # All rights reserved. This software is distributed under the
  4. # Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
  5. #
  6. # Redistributions of source code must retain the above copyright
  7. # and license notice and the following restrictions and disclaimer.
  8. #
  9. # * Neither the name of DreamWorks Animation nor the names of
  10. # its contributors may be used to endorse or promote products derived
  11. # from this software without specific prior written permission.
  12. #
  13. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  14. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  15. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  16. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  17. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
  18. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  19. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  21. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. # IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
  25. # LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
  26. #
  27. #[=======================================================================[.rst:
  28. FindOpenVDB
  29. -----------
  30. Find OpenVDB include dirs, libraries and settings
  31. Use this module by invoking find_package with the form::
  32. find_package(OpenVDB
  33. [version] [EXACT] # Minimum or EXACT version
  34. [REQUIRED] # Fail with error if OpenVDB is not found
  35. [COMPONENTS <libs>...] # OpenVDB libraries by their canonical name
  36. # e.g. "openvdb" for "libopenvdb"
  37. )
  38. IMPORTED Targets
  39. ^^^^^^^^^^^^^^^^
  40. ``OpenVDB::openvdb``
  41. The core openvdb library target.
  42. Result Variables
  43. ^^^^^^^^^^^^^^^^
  44. This will define the following variables:
  45. ``OpenVDB_FOUND``
  46. True if the system has the OpenVDB library.
  47. ``OpenVDB_VERSION``
  48. The version of the OpenVDB library which was found.
  49. ``OpenVDB_INCLUDE_DIRS``
  50. Include directories needed to use OpenVDB.
  51. ``OpenVDB_LIBRARIES``
  52. Libraries needed to link to OpenVDB.
  53. ``OpenVDB_LIBRARY_DIRS``
  54. OpenVDB library directories.
  55. ``OpenVDB_DEFINITIONS``
  56. Definitions to use when compiling code that uses OpenVDB.
  57. ``OpenVDB_{COMPONENT}_FOUND``
  58. True if the system has the named OpenVDB component.
  59. ``OpenVDB_USES_BLOSC``
  60. True if the OpenVDB Library has been built with blosc support
  61. ``OpenVDB_USES_LOG4CPLUS``
  62. True if the OpenVDB Library has been built with log4cplus support
  63. ``OpenVDB_USES_EXR``
  64. True if the OpenVDB Library has been built with openexr support
  65. ``OpenVDB_ABI``
  66. Set if this module was able to determine the ABI number the located
  67. OpenVDB Library was built against. Unset otherwise.
  68. Cache Variables
  69. ^^^^^^^^^^^^^^^
  70. The following cache variables may also be set:
  71. ``OpenVDB_INCLUDE_DIR``
  72. The directory containing ``openvdb/version.h``.
  73. ``OpenVDB_{COMPONENT}_LIBRARY``
  74. Individual component libraries for OpenVDB
  75. Hints
  76. ^^^^^
  77. Instead of explicitly setting the cache variables, the following variables
  78. may be provided to tell this module where to look.
  79. ``OPENVDB_ROOT``
  80. Preferred installation prefix.
  81. ``OPENVDB_INCLUDEDIR``
  82. Preferred include directory e.g. <prefix>/include
  83. ``OPENVDB_LIBRARYDIR``
  84. Preferred library directory e.g. <prefix>/lib
  85. ``SYSTEM_LIBRARY_PATHS``
  86. Paths appended to all include and lib searches.
  87. #]=======================================================================]
  88. # If an explicit openvdb module path was specified, that will be used
  89. if (OPENVDB_FIND_MODULE_PATH)
  90. set(_module_path_bak ${CMAKE_MODULE_PATH})
  91. set(CMAKE_MODULE_PATH ${OPENVDB_FIND_MODULE_PATH})
  92. find_package(
  93. OpenVDB ${OpenVDB_FIND_VERSION} QUIET
  94. COMPONENTS
  95. ${OpenVDB_FIND_COMPONENTS}
  96. )
  97. set(CMAKE_MODULE_PATH ${_module_path_bak})
  98. if (OpenVDB_FOUND)
  99. return()
  100. endif ()
  101. if (NOT OpenVDB_FIND_QUIETLY)
  102. message(STATUS "Using bundled find module for OpenVDB")
  103. endif ()
  104. endif ()
  105. # ###########################################################################
  106. cmake_minimum_required(VERSION 3.3)
  107. # Monitoring <PackageName>_ROOT variables
  108. if(POLICY CMP0074)
  109. cmake_policy(SET CMP0074 NEW)
  110. endif()
  111. if(OpenVDB_FIND_QUIETLY)
  112. set (_quiet "QUIET")
  113. else()
  114. set (_quiet "")
  115. endif()
  116. if(OpenVDB_FIND_REQUIRED)
  117. set (_required "REQUIRED")
  118. else()
  119. set (_required "")
  120. endif()
  121. # Include utility functions for version information
  122. include(${CMAKE_CURRENT_LIST_DIR}/OpenVDBUtils.cmake)
  123. mark_as_advanced(
  124. OpenVDB_INCLUDE_DIR
  125. OpenVDB_LIBRARY
  126. )
  127. set(_OPENVDB_COMPONENT_LIST
  128. openvdb
  129. )
  130. if(OpenVDB_FIND_COMPONENTS)
  131. set(OPENVDB_COMPONENTS_PROVIDED TRUE)
  132. set(_IGNORED_COMPONENTS "")
  133. foreach(COMPONENT ${OpenVDB_FIND_COMPONENTS})
  134. if(NOT ${COMPONENT} IN_LIST _OPENVDB_COMPONENT_LIST)
  135. list(APPEND _IGNORED_COMPONENTS ${COMPONENT})
  136. endif()
  137. endforeach()
  138. if(_IGNORED_COMPONENTS)
  139. message(STATUS "Ignoring unknown components of OpenVDB:")
  140. foreach(COMPONENT ${_IGNORED_COMPONENTS})
  141. message(STATUS " ${COMPONENT}")
  142. endforeach()
  143. list(REMOVE_ITEM OpenVDB_FIND_COMPONENTS ${_IGNORED_COMPONENTS})
  144. endif()
  145. else()
  146. set(OPENVDB_COMPONENTS_PROVIDED FALSE)
  147. set(OpenVDB_FIND_COMPONENTS ${_OPENVDB_COMPONENT_LIST})
  148. endif()
  149. # Append OPENVDB_ROOT or $ENV{OPENVDB_ROOT} if set (prioritize the direct cmake var)
  150. set(_OPENVDB_ROOT_SEARCH_DIR "")
  151. # Additionally try and use pkconfig to find OpenVDB
  152. find_package(PkgConfig ${_quiet} )
  153. pkg_check_modules(PC_OpenVDB QUIET OpenVDB)
  154. # ------------------------------------------------------------------------
  155. # Search for OpenVDB include DIR
  156. # ------------------------------------------------------------------------
  157. set(_OPENVDB_INCLUDE_SEARCH_DIRS "")
  158. list(APPEND _OPENVDB_INCLUDE_SEARCH_DIRS
  159. ${OPENVDB_INCLUDEDIR}
  160. ${_OPENVDB_ROOT_SEARCH_DIR}
  161. ${PC_OpenVDB_INCLUDE_DIRS}
  162. ${SYSTEM_LIBRARY_PATHS}
  163. )
  164. # Look for a standard OpenVDB header file.
  165. find_path(OpenVDB_INCLUDE_DIR openvdb/version.h
  166. PATHS ${_OPENVDB_INCLUDE_SEARCH_DIRS}
  167. PATH_SUFFIXES include
  168. )
  169. OPENVDB_VERSION_FROM_HEADER("${OpenVDB_INCLUDE_DIR}/openvdb/version.h"
  170. VERSION OpenVDB_VERSION
  171. MAJOR OpenVDB_MAJOR_VERSION
  172. MINOR OpenVDB_MINOR_VERSION
  173. PATCH OpenVDB_PATCH_VERSION
  174. )
  175. # ------------------------------------------------------------------------
  176. # Search for OPENVDB lib DIR
  177. # ------------------------------------------------------------------------
  178. set(_OPENVDB_LIBRARYDIR_SEARCH_DIRS "")
  179. # Append to _OPENVDB_LIBRARYDIR_SEARCH_DIRS in priority order
  180. list(APPEND _OPENVDB_LIBRARYDIR_SEARCH_DIRS
  181. ${OPENVDB_LIBRARYDIR}
  182. ${_OPENVDB_ROOT_SEARCH_DIR}
  183. ${PC_OpenVDB_LIBRARY_DIRS}
  184. ${SYSTEM_LIBRARY_PATHS}
  185. )
  186. # Build suffix directories
  187. set(OPENVDB_PATH_SUFFIXES
  188. lib64
  189. lib
  190. )
  191. # Static library setup
  192. if(UNIX AND OPENVDB_USE_STATIC_LIBS)
  193. set(_OPENVDB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
  194. set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
  195. endif()
  196. set(OpenVDB_LIB_COMPONENTS "")
  197. set(OpenVDB_DEBUG_SUFFIX "d" CACHE STRING "Suffix for the debug libraries")
  198. get_property(_is_multi GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  199. foreach(COMPONENT ${OpenVDB_FIND_COMPONENTS})
  200. set(LIB_NAME ${COMPONENT})
  201. find_library(OpenVDB_${COMPONENT}_LIBRARY_RELEASE ${LIB_NAME} lib${LIB_NAME}
  202. PATHS ${_OPENVDB_LIBRARYDIR_SEARCH_DIRS}
  203. PATH_SUFFIXES ${OPENVDB_PATH_SUFFIXES}
  204. )
  205. find_library(OpenVDB_${COMPONENT}_LIBRARY_DEBUG ${LIB_NAME}${OpenVDB_DEBUG_SUFFIX} lib${LIB_NAME}${OpenVDB_DEBUG_SUFFIX}
  206. PATHS ${_OPENVDB_LIBRARYDIR_SEARCH_DIRS}
  207. PATH_SUFFIXES ${OPENVDB_PATH_SUFFIXES}
  208. )
  209. if (_is_multi)
  210. list(APPEND OpenVDB_LIB_COMPONENTS ${OpenVDB_${COMPONENT}_LIBRARY_RELEASE})
  211. if (OpenVDB_${COMPONENT}_LIBRARY_DEBUG)
  212. list(APPEND OpenVDB_LIB_COMPONENTS ${OpenVDB_${COMPONENT}_LIBRARY_DEBUG})
  213. endif ()
  214. list(FIND CMAKE_CONFIGURATION_TYPES "Debug" _has_debug)
  215. if(OpenVDB_${COMPONENT}_LIBRARY_RELEASE AND (NOT MSVC OR _has_debug LESS 0 OR OpenVDB_${COMPONENT}_LIBRARY_DEBUG))
  216. set(OpenVDB_${COMPONENT}_FOUND TRUE)
  217. else()
  218. set(OpenVDB_${COMPONENT}_FOUND FALSE)
  219. endif()
  220. set(OpenVDB_${COMPONENT}_LIBRARY ${OpenVDB_${COMPONENT}_LIBRARY_RELEASE})
  221. else ()
  222. string(TOUPPER "${CMAKE_BUILD_TYPE}" _BUILD_TYPE)
  223. set(OpenVDB_${COMPONENT}_LIBRARY ${OpenVDB_${COMPONENT}_LIBRARY_${_BUILD_TYPE}})
  224. if (NOT OpenVDB_${COMPONENT}_LIBRARY)
  225. set(OpenVDB_${COMPONENT}_LIBRARY ${OpenVDB_${COMPONENT}_LIBRARY_RELEASE})
  226. endif ()
  227. list(APPEND OpenVDB_LIB_COMPONENTS ${OpenVDB_${COMPONENT}_LIBRARY})
  228. if(OpenVDB_${COMPONENT}_LIBRARY)
  229. set(OpenVDB_${COMPONENT}_FOUND TRUE)
  230. else()
  231. set(OpenVDB_${COMPONENT}_FOUND FALSE)
  232. endif()
  233. endif ()
  234. endforeach()
  235. if(UNIX AND OPENVDB_USE_STATIC_LIBS)
  236. set(CMAKE_FIND_LIBRARY_SUFFIXES ${_OPENVDB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
  237. unset(_OPENVDB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES)
  238. endif()
  239. # ------------------------------------------------------------------------
  240. # Cache and set OPENVDB_FOUND
  241. # ------------------------------------------------------------------------
  242. include(FindPackageHandleStandardArgs)
  243. find_package_handle_standard_args(OpenVDB
  244. FOUND_VAR OpenVDB_FOUND
  245. REQUIRED_VARS
  246. OpenVDB_INCLUDE_DIR
  247. OpenVDB_LIB_COMPONENTS
  248. VERSION_VAR OpenVDB_VERSION
  249. HANDLE_COMPONENTS
  250. )
  251. # ------------------------------------------------------------------------
  252. # Determine ABI number
  253. # ------------------------------------------------------------------------
  254. # Set the ABI number the library was built against. Uses vdb_print
  255. find_program(OPENVDB_PRINT vdb_print PATHS ${OpenVDB_INCLUDE_DIR} )
  256. OPENVDB_ABI_VERSION_FROM_PRINT(
  257. "${OPENVDB_PRINT}"
  258. ABI OpenVDB_ABI
  259. )
  260. if(NOT OpenVDB_FIND_QUIETLY)
  261. if(NOT OpenVDB_ABI)
  262. message(WARNING "Unable to determine OpenVDB ABI version from OpenVDB "
  263. "installation. The library major version \"${OpenVDB_MAJOR_VERSION}\" "
  264. "will be inferred. If this is not correct, use "
  265. "add_definitions(-DOPENVDB_ABI_VERSION_NUMBER=N)"
  266. )
  267. else()
  268. message(STATUS "OpenVDB ABI Version: ${OpenVDB_ABI}")
  269. endif()
  270. endif()
  271. # ------------------------------------------------------------------------
  272. # Handle OpenVDB dependencies
  273. # ------------------------------------------------------------------------
  274. # Add standard dependencies
  275. macro(just_fail msg)
  276. set(OpenVDB_FOUND FALSE)
  277. if(OpenVDB_FIND_REQUIRED)
  278. message(FATAL_ERROR ${msg})
  279. elseif(NOT OpenVDB_FIND_QUIETLY)
  280. message(WARNING ${msg})
  281. endif()
  282. return()
  283. endmacro()
  284. find_package(IlmBase QUIET)
  285. if(NOT IlmBase_FOUND)
  286. pkg_check_modules(IlmBase QUIET IlmBase)
  287. endif()
  288. if (IlmBase_FOUND AND NOT TARGET IlmBase::Half)
  289. message(STATUS "Falling back to IlmBase found by pkg-config...")
  290. find_library(IlmHalf_LIBRARY NAMES Half)
  291. if(IlmHalf_LIBRARY-NOTFOUND OR NOT IlmBase_INCLUDE_DIRS)
  292. just_fail("IlmBase::Half can not be found!")
  293. endif()
  294. add_library(IlmBase::Half UNKNOWN IMPORTED)
  295. set_target_properties(IlmBase::Half PROPERTIES
  296. IMPORTED_LOCATION "${IlmHalf_LIBRARY}"
  297. INTERFACE_INCLUDE_DIRECTORIES "${IlmBase_INCLUDE_DIRS}")
  298. elseif(NOT IlmBase_FOUND)
  299. just_fail("IlmBase::Half can not be found!")
  300. endif()
  301. find_package(TBB ${_quiet} ${_required} COMPONENTS tbb)
  302. find_package(ZLIB ${_quiet} ${_required})
  303. find_package(Boost ${_quiet} ${_required} COMPONENTS iostreams system )
  304. # Use GetPrerequisites to see which libraries this OpenVDB lib has linked to
  305. # which we can query for optional deps. This basically runs ldd/otoll/objdump
  306. # etc to track deps. We could use a vdb_config binary tools here to improve
  307. # this process
  308. include(GetPrerequisites)
  309. set(_EXCLUDE_SYSTEM_PREREQUISITES 1)
  310. set(_RECURSE_PREREQUISITES 0)
  311. set(_OPENVDB_PREREQUISITE_LIST)
  312. if(NOT OPENVDB_USE_STATIC_LIBS)
  313. get_prerequisites(${OpenVDB_openvdb_LIBRARY}
  314. _OPENVDB_PREREQUISITE_LIST
  315. ${_EXCLUDE_SYSTEM_PREREQUISITES}
  316. ${_RECURSE_PREREQUISITES}
  317. ""
  318. "${SYSTEM_LIBRARY_PATHS}"
  319. )
  320. endif()
  321. unset(_EXCLUDE_SYSTEM_PREREQUISITES)
  322. unset(_RECURSE_PREREQUISITES)
  323. # As the way we resolve optional libraries relies on library file names, use
  324. # the configuration options from the main CMakeLists.txt to allow users
  325. # to manually identify the requirements of OpenVDB builds if they know them.
  326. set(OpenVDB_USES_BLOSC ${USE_BLOSC})
  327. set(OpenVDB_USES_LOG4CPLUS ${USE_LOG4CPLUS})
  328. set(OpenVDB_USES_ILM ${USE_EXR})
  329. set(OpenVDB_USES_EXR ${USE_EXR})
  330. # Search for optional dependencies
  331. foreach(PREREQUISITE ${_OPENVDB_PREREQUISITE_LIST})
  332. set(_HAS_DEP)
  333. get_filename_component(PREREQUISITE ${PREREQUISITE} NAME)
  334. string(FIND ${PREREQUISITE} "blosc" _HAS_DEP)
  335. if(NOT ${_HAS_DEP} EQUAL -1)
  336. set(OpenVDB_USES_BLOSC ON)
  337. endif()
  338. string(FIND ${PREREQUISITE} "log4cplus" _HAS_DEP)
  339. if(NOT ${_HAS_DEP} EQUAL -1)
  340. set(OpenVDB_USES_LOG4CPLUS ON)
  341. endif()
  342. string(FIND ${PREREQUISITE} "IlmImf" _HAS_DEP)
  343. if(NOT ${_HAS_DEP} EQUAL -1)
  344. set(OpenVDB_USES_ILM ON)
  345. endif()
  346. endforeach()
  347. unset(_OPENVDB_PREREQUISITE_LIST)
  348. unset(_HAS_DEP)
  349. if(OpenVDB_USES_BLOSC)
  350. find_package(Blosc QUIET)
  351. if(NOT Blosc_FOUND OR NOT TARGET Blosc::blosc)
  352. message(STATUS "find_package could not find Blosc. Using fallback blosc search...")
  353. find_path(Blosc_INCLUDE_DIR blosc.h)
  354. find_library(Blosc_LIBRARY NAMES blosc)
  355. if (Blosc_INCLUDE_DIR AND Blosc_LIBRARY)
  356. set(Blosc_FOUND TRUE)
  357. add_library(Blosc::blosc UNKNOWN IMPORTED)
  358. set_target_properties(Blosc::blosc PROPERTIES
  359. IMPORTED_LOCATION "${Blosc_LIBRARY}"
  360. INTERFACE_INCLUDE_DIRECTORIES ${Blosc_INCLUDE_DIR})
  361. elseif()
  362. just_fail("Blosc library can not be found!")
  363. endif()
  364. endif()
  365. endif()
  366. if(OpenVDB_USES_LOG4CPLUS)
  367. find_package(Log4cplus ${_quiet} ${_required})
  368. endif()
  369. if(OpenVDB_USES_ILM)
  370. find_package(IlmBase ${_quiet} ${_required})
  371. endif()
  372. if(OpenVDB_USES_EXR)
  373. find_package(OpenEXR ${_quiet} ${_required})
  374. endif()
  375. if(UNIX)
  376. find_package(Threads ${_quiet} ${_required})
  377. endif()
  378. # Set deps. Note that the order here is important. If we're building against
  379. # Houdini 17.5 we must include OpenEXR and IlmBase deps first to ensure the
  380. # users chosen namespaced headers are correctly prioritized. Otherwise other
  381. # include paths from shared installs (including houdini) may pull in the wrong
  382. # headers
  383. set(_OPENVDB_VISIBLE_DEPENDENCIES
  384. Boost::iostreams
  385. Boost::system
  386. IlmBase::Half
  387. )
  388. set(_OPENVDB_DEFINITIONS)
  389. if(OpenVDB_ABI)
  390. list(APPEND _OPENVDB_DEFINITIONS "-DOPENVDB_ABI_VERSION_NUMBER=${OpenVDB_ABI}")
  391. endif()
  392. if(OpenVDB_USES_EXR)
  393. list(APPEND _OPENVDB_VISIBLE_DEPENDENCIES
  394. IlmBase::IlmThread
  395. IlmBase::Iex
  396. IlmBase::Imath
  397. OpenEXR::IlmImf
  398. )
  399. list(APPEND _OPENVDB_DEFINITIONS "-DOPENVDB_TOOLS_RAYTRACER_USE_EXR")
  400. endif()
  401. if(OpenVDB_USES_LOG4CPLUS)
  402. list(APPEND _OPENVDB_VISIBLE_DEPENDENCIES Log4cplus::log4cplus)
  403. list(APPEND _OPENVDB_DEFINITIONS "-DOPENVDB_USE_LOG4CPLUS")
  404. endif()
  405. list(APPEND _OPENVDB_VISIBLE_DEPENDENCIES
  406. TBB::tbb
  407. )
  408. if(UNIX)
  409. list(APPEND _OPENVDB_VISIBLE_DEPENDENCIES
  410. Threads::Threads
  411. )
  412. endif()
  413. set(_OPENVDB_HIDDEN_DEPENDENCIES)
  414. if(OpenVDB_USES_BLOSC)
  415. if(OPENVDB_USE_STATIC_LIBS)
  416. list(APPEND _OPENVDB_VISIBLE_DEPENDENCIES $<LINK_ONLY:Blosc::blosc>)
  417. else()
  418. list(APPEND _OPENVDB_HIDDEN_DEPENDENCIES Blosc::blosc)
  419. endif()
  420. endif()
  421. if(OPENVDB_USE_STATIC_LIBS)
  422. list(APPEND _OPENVDB_VISIBLE_DEPENDENCIES $<LINK_ONLY:ZLIB::ZLIB>)
  423. else()
  424. list(APPEND _OPENVDB_HIDDEN_DEPENDENCIES ZLIB::ZLIB)
  425. endif()
  426. # ------------------------------------------------------------------------
  427. # Configure imported target
  428. # ------------------------------------------------------------------------
  429. set(OpenVDB_LIBRARIES
  430. ${OpenVDB_LIB_COMPONENTS}
  431. )
  432. set(OpenVDB_INCLUDE_DIRS ${OpenVDB_INCLUDE_DIR})
  433. set(OpenVDB_DEFINITIONS)
  434. list(APPEND OpenVDB_DEFINITIONS "${PC_OpenVDB_CFLAGS_OTHER}")
  435. list(APPEND OpenVDB_DEFINITIONS "${_OPENVDB_DEFINITIONS}")
  436. list(REMOVE_DUPLICATES OpenVDB_DEFINITIONS)
  437. set(OpenVDB_LIBRARY_DIRS "")
  438. foreach(LIB ${OpenVDB_LIB_COMPONENTS})
  439. get_filename_component(_OPENVDB_LIBDIR ${LIB} DIRECTORY)
  440. list(APPEND OpenVDB_LIBRARY_DIRS ${_OPENVDB_LIBDIR})
  441. endforeach()
  442. list(REMOVE_DUPLICATES OpenVDB_LIBRARY_DIRS)
  443. foreach(COMPONENT ${OpenVDB_FIND_COMPONENTS})
  444. if(NOT TARGET OpenVDB::${COMPONENT})
  445. if (${COMPONENT} STREQUAL openvdb)
  446. include (${CMAKE_CURRENT_LIST_DIR}/CheckAtomic.cmake)
  447. set(_LINK_LIBS ${_OPENVDB_VISIBLE_DEPENDENCIES} ${CMAKE_REQUIRED_LIBRARIES})
  448. else ()
  449. set(_LINK_LIBS _OPENVDB_VISIBLE_DEPENDENCIES)
  450. endif ()
  451. add_library(OpenVDB::${COMPONENT} UNKNOWN IMPORTED)
  452. set_target_properties(OpenVDB::${COMPONENT} PROPERTIES
  453. INTERFACE_COMPILE_OPTIONS "${OpenVDB_DEFINITIONS}"
  454. INTERFACE_INCLUDE_DIRECTORIES "${OpenVDB_INCLUDE_DIR}"
  455. IMPORTED_LINK_DEPENDENT_LIBRARIES "${_OPENVDB_HIDDEN_DEPENDENCIES}" # non visible deps
  456. INTERFACE_LINK_LIBRARIES "${_LINK_LIBS}" # visible deps (headers)
  457. INTERFACE_COMPILE_FEATURES cxx_std_11
  458. IMPORTED_LOCATION "${OpenVDB_${COMPONENT}_LIBRARY}"
  459. )
  460. if (_is_multi)
  461. set_target_properties(OpenVDB::${COMPONENT} PROPERTIES
  462. IMPORTED_LOCATION_RELEASE "${OpenVDB_${COMPONENT}_LIBRARY_RELEASE}"
  463. )
  464. if (MSVC OR OpenVDB_${COMPONENT}_LIBRARY_DEBUG)
  465. set_target_properties(OpenVDB::${COMPONENT} PROPERTIES
  466. IMPORTED_LOCATION_DEBUG "${OpenVDB_${COMPONENT}_LIBRARY_DEBUG}"
  467. )
  468. endif ()
  469. endif ()
  470. if (OPENVDB_USE_STATIC_LIBS)
  471. set_target_properties(OpenVDB::${COMPONENT} PROPERTIES
  472. INTERFACE_COMPILE_DEFINITIONS "OPENVDB_STATICLIB;OPENVDB_OPENEXR_STATICLIB"
  473. )
  474. endif()
  475. endif()
  476. endforeach()
  477. if(OpenVDB_FOUND AND NOT OpenVDB_FIND_QUIETLY)
  478. message(STATUS "OpenVDB libraries: ${OpenVDB_LIBRARIES}")
  479. endif()
  480. unset(_OPENVDB_DEFINITIONS)
  481. unset(_OPENVDB_VISIBLE_DEPENDENCIES)
  482. unset(_OPENVDB_HIDDEN_DEPENDENCIES)