FindOpenVDB.cmake 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  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. cmake_minimum_required(VERSION 3.3)
  89. # Monitoring <PackageName>_ROOT variables
  90. if(POLICY CMP0074)
  91. cmake_policy(SET CMP0074 NEW)
  92. endif()
  93. if(OpenVDB_FIND_QUIETLY)
  94. set (_quiet "QUIET")
  95. else()
  96. set (_quiet "")
  97. endif()
  98. if(OpenVDB_FIND_REQUIRED)
  99. set (_required "REQUIRED")
  100. else()
  101. set (_required "")
  102. endif()
  103. # Include utility functions for version information
  104. include(${CMAKE_CURRENT_LIST_DIR}/OpenVDBUtils.cmake)
  105. mark_as_advanced(
  106. OpenVDB_INCLUDE_DIR
  107. OpenVDB_LIBRARY
  108. )
  109. set(_OPENVDB_COMPONENT_LIST
  110. openvdb
  111. )
  112. if(OpenVDB_FIND_COMPONENTS)
  113. set(OPENVDB_COMPONENTS_PROVIDED TRUE)
  114. set(_IGNORED_COMPONENTS "")
  115. foreach(COMPONENT ${OpenVDB_FIND_COMPONENTS})
  116. if(NOT ${COMPONENT} IN_LIST _OPENVDB_COMPONENT_LIST)
  117. list(APPEND _IGNORED_COMPONENTS ${COMPONENT})
  118. endif()
  119. endforeach()
  120. if(_IGNORED_COMPONENTS)
  121. message(STATUS "Ignoring unknown components of OpenVDB:")
  122. foreach(COMPONENT ${_IGNORED_COMPONENTS})
  123. message(STATUS " ${COMPONENT}")
  124. endforeach()
  125. list(REMOVE_ITEM OpenVDB_FIND_COMPONENTS ${_IGNORED_COMPONENTS})
  126. endif()
  127. else()
  128. set(OPENVDB_COMPONENTS_PROVIDED FALSE)
  129. set(OpenVDB_FIND_COMPONENTS ${_OPENVDB_COMPONENT_LIST})
  130. endif()
  131. # Append OPENVDB_ROOT or $ENV{OPENVDB_ROOT} if set (prioritize the direct cmake var)
  132. set(_OPENVDB_ROOT_SEARCH_DIR "")
  133. # Additionally try and use pkconfig to find OpenVDB
  134. find_package(PkgConfig ${_quiet} )
  135. pkg_check_modules(PC_OpenVDB QUIET OpenVDB)
  136. # ------------------------------------------------------------------------
  137. # Search for OpenVDB include DIR
  138. # ------------------------------------------------------------------------
  139. set(_OPENVDB_INCLUDE_SEARCH_DIRS "")
  140. list(APPEND _OPENVDB_INCLUDE_SEARCH_DIRS
  141. ${OPENVDB_INCLUDEDIR}
  142. ${_OPENVDB_ROOT_SEARCH_DIR}
  143. ${PC_OpenVDB_INCLUDE_DIRS}
  144. ${SYSTEM_LIBRARY_PATHS}
  145. )
  146. # Look for a standard OpenVDB header file.
  147. find_path(OpenVDB_INCLUDE_DIR openvdb/version.h
  148. PATHS ${_OPENVDB_INCLUDE_SEARCH_DIRS}
  149. PATH_SUFFIXES include
  150. )
  151. OPENVDB_VERSION_FROM_HEADER("${OpenVDB_INCLUDE_DIR}/openvdb/version.h"
  152. VERSION OpenVDB_VERSION
  153. MAJOR OpenVDB_MAJOR_VERSION
  154. MINOR OpenVDB_MINOR_VERSION
  155. PATCH OpenVDB_PATCH_VERSION
  156. )
  157. # ------------------------------------------------------------------------
  158. # Search for OPENVDB lib DIR
  159. # ------------------------------------------------------------------------
  160. set(_OPENVDB_LIBRARYDIR_SEARCH_DIRS "")
  161. # Append to _OPENVDB_LIBRARYDIR_SEARCH_DIRS in priority order
  162. list(APPEND _OPENVDB_LIBRARYDIR_SEARCH_DIRS
  163. ${OPENVDB_LIBRARYDIR}
  164. ${_OPENVDB_ROOT_SEARCH_DIR}
  165. ${PC_OpenVDB_LIBRARY_DIRS}
  166. ${SYSTEM_LIBRARY_PATHS}
  167. )
  168. # Build suffix directories
  169. set(OPENVDB_PATH_SUFFIXES
  170. lib64
  171. lib
  172. )
  173. # Static library setup
  174. if(UNIX AND OPENVDB_USE_STATIC_LIBS)
  175. set(_OPENVDB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
  176. set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
  177. endif()
  178. set(OpenVDB_LIB_COMPONENTS "")
  179. set(OpenVDB_DEBUG_SUFFIX "d" CACHE STRING "Suffix for the debug libraries")
  180. get_property(_is_multi GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  181. foreach(COMPONENT ${OpenVDB_FIND_COMPONENTS})
  182. set(LIB_NAME ${COMPONENT})
  183. find_library(OpenVDB_${COMPONENT}_LIBRARY_RELEASE ${LIB_NAME} lib${LIB_NAME}
  184. PATHS ${_OPENVDB_LIBRARYDIR_SEARCH_DIRS}
  185. PATH_SUFFIXES ${OPENVDB_PATH_SUFFIXES}
  186. )
  187. find_library(OpenVDB_${COMPONENT}_LIBRARY_DEBUG ${LIB_NAME}${OpenVDB_DEBUG_SUFFIX} lib${LIB_NAME}${OpenVDB_DEBUG_SUFFIX}
  188. PATHS ${_OPENVDB_LIBRARYDIR_SEARCH_DIRS}
  189. PATH_SUFFIXES ${OPENVDB_PATH_SUFFIXES}
  190. )
  191. if (_is_multi)
  192. list(APPEND OpenVDB_LIB_COMPONENTS ${OpenVDB_${COMPONENT}_LIBRARY_RELEASE})
  193. if (MSVC OR OpenVDB_${COMPONENT}_LIBRARY_DEBUG)
  194. list(APPEND OpenVDB_LIB_COMPONENTS ${OpenVDB_${COMPONENT}_LIBRARY_DEBUG})
  195. endif ()
  196. list(FIND CMAKE_CONFIGURATION_TYPES "Debug" _has_debug)
  197. if(OpenVDB_${COMPONENT}_LIBRARY_RELEASE AND (NOT MSVC OR _has_debug LESS 0 OR OpenVDB_${COMPONENT}_LIBRARY_DEBUG))
  198. set(OpenVDB_${COMPONENT}_FOUND TRUE)
  199. else()
  200. set(OpenVDB_${COMPONENT}_FOUND FALSE)
  201. endif()
  202. set(OpenVDB_${COMPONENT}_LIBRARY ${OpenVDB_${COMPONENT}_LIBRARY_RELEASE})
  203. else ()
  204. string(TOUPPER "${CMAKE_BUILD_TYPE}" _BUILD_TYPE)
  205. set(OpenVDB_${COMPONENT}_LIBRARY ${OpenVDB_${COMPONENT}_LIBRARY_${_BUILD_TYPE}})
  206. if (NOT OpenVDB_${COMPONENT}_LIBRARY)
  207. set(OpenVDB_${COMPONENT}_LIBRARY ${OpenVDB_${COMPONENT}_LIBRARY_RELEASE})
  208. endif ()
  209. list(APPEND OpenVDB_LIB_COMPONENTS ${OpenVDB_${COMPONENT}_LIBRARY})
  210. if(OpenVDB_${COMPONENT}_LIBRARY)
  211. set(OpenVDB_${COMPONENT}_FOUND TRUE)
  212. else()
  213. set(OpenVDB_${COMPONENT}_FOUND FALSE)
  214. endif()
  215. endif ()
  216. endforeach()
  217. if(UNIX AND OPENVDB_USE_STATIC_LIBS)
  218. set(CMAKE_FIND_LIBRARY_SUFFIXES ${_OPENVDB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
  219. unset(_OPENVDB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES)
  220. endif()
  221. # ------------------------------------------------------------------------
  222. # Cache and set OPENVDB_FOUND
  223. # ------------------------------------------------------------------------
  224. include(FindPackageHandleStandardArgs)
  225. find_package_handle_standard_args(OpenVDB
  226. FOUND_VAR OpenVDB_FOUND
  227. REQUIRED_VARS
  228. OpenVDB_INCLUDE_DIR
  229. OpenVDB_LIB_COMPONENTS
  230. VERSION_VAR OpenVDB_VERSION
  231. HANDLE_COMPONENTS
  232. )
  233. # ------------------------------------------------------------------------
  234. # Determine ABI number
  235. # ------------------------------------------------------------------------
  236. # Set the ABI number the library was built against. Uses vdb_print
  237. find_program(OPENVDB_PRINT vdb_print PATHS ${OpenVDB_INCLUDE_DIR} )
  238. OPENVDB_ABI_VERSION_FROM_PRINT(
  239. "${OPENVDB_PRINT}"
  240. ABI OpenVDB_ABI
  241. )
  242. if(NOT OpenVDB_FIND_QUIETLY)
  243. if(NOT OpenVDB_ABI)
  244. message(WARNING "Unable to determine OpenVDB ABI version from OpenVDB "
  245. "installation. The library major version \"${OpenVDB_MAJOR_VERSION}\" "
  246. "will be inferred. If this is not correct, use "
  247. "add_definitions(-DOPENVDB_ABI_VERSION_NUMBER=N)"
  248. )
  249. else()
  250. message(STATUS "OpenVDB ABI Version: ${OpenVDB_ABI}")
  251. endif()
  252. endif()
  253. # ------------------------------------------------------------------------
  254. # Handle OpenVDB dependencies
  255. # ------------------------------------------------------------------------
  256. # Add standard dependencies
  257. macro(just_fail msg)
  258. set(OpenVDB_FOUND FALSE)
  259. if(OpenVDB_FIND_REQUIRED)
  260. message(FATAL_ERROR ${msg})
  261. elseif(NOT OpenVDB_FIND_QUIETLY)
  262. message(WARNING ${msg})
  263. endif()
  264. return()
  265. endmacro()
  266. find_package(IlmBase QUIET COMPONENTS Half)
  267. if(NOT IlmBase_FOUND)
  268. pkg_check_modules(IlmBase QUIET IlmBase)
  269. endif()
  270. if (IlmBase_FOUND AND NOT TARGET IlmBase::Half)
  271. message(STATUS "Falling back to IlmBase found by pkg-config...")
  272. find_library(IlmHalf_LIBRARY NAMES Half)
  273. if(IlmHalf_LIBRARY-NOTFOUND OR NOT IlmBase_INCLUDE_DIRS)
  274. just_fail("IlmBase::Half can not be found!")
  275. endif()
  276. add_library(IlmBase::Half UNKNOWN IMPORTED)
  277. set_target_properties(IlmBase::Half PROPERTIES
  278. IMPORTED_LOCATION "${IlmHalf_LIBRARY}"
  279. INTERFACE_INCLUDE_DIRECTORIES "${IlmBase_INCLUDE_DIRS}")
  280. elseif(NOT IlmBase_FOUND)
  281. just_fail("IlmBase::Half can not be found!")
  282. endif()
  283. find_package(TBB ${_quiet} ${_required} COMPONENTS tbb)
  284. find_package(ZLIB ${_quiet} ${_required})
  285. find_package(Boost ${_quiet} ${_required} COMPONENTS iostreams system )
  286. # Use GetPrerequisites to see which libraries this OpenVDB lib has linked to
  287. # which we can query for optional deps. This basically runs ldd/otoll/objdump
  288. # etc to track deps. We could use a vdb_config binary tools here to improve
  289. # this process
  290. include(GetPrerequisites)
  291. set(_EXCLUDE_SYSTEM_PREREQUISITES 1)
  292. set(_RECURSE_PREREQUISITES 0)
  293. set(_OPENVDB_PREREQUISITE_LIST)
  294. if(NOT OPENVDB_USE_STATIC_LIBS)
  295. get_prerequisites(${OpenVDB_openvdb_LIBRARY}
  296. _OPENVDB_PREREQUISITE_LIST
  297. ${_EXCLUDE_SYSTEM_PREREQUISITES}
  298. ${_RECURSE_PREREQUISITES}
  299. ""
  300. "${SYSTEM_LIBRARY_PATHS}"
  301. )
  302. endif()
  303. unset(_EXCLUDE_SYSTEM_PREREQUISITES)
  304. unset(_RECURSE_PREREQUISITES)
  305. # As the way we resolve optional libraries relies on library file names, use
  306. # the configuration options from the main CMakeLists.txt to allow users
  307. # to manually identify the requirements of OpenVDB builds if they know them.
  308. set(OpenVDB_USES_BLOSC ${USE_BLOSC})
  309. set(OpenVDB_USES_LOG4CPLUS ${USE_LOG4CPLUS})
  310. set(OpenVDB_USES_ILM ${USE_EXR})
  311. set(OpenVDB_USES_EXR ${USE_EXR})
  312. # Search for optional dependencies
  313. foreach(PREREQUISITE ${_OPENVDB_PREREQUISITE_LIST})
  314. set(_HAS_DEP)
  315. get_filename_component(PREREQUISITE ${PREREQUISITE} NAME)
  316. string(FIND ${PREREQUISITE} "blosc" _HAS_DEP)
  317. if(NOT ${_HAS_DEP} EQUAL -1)
  318. set(OpenVDB_USES_BLOSC ON)
  319. endif()
  320. string(FIND ${PREREQUISITE} "log4cplus" _HAS_DEP)
  321. if(NOT ${_HAS_DEP} EQUAL -1)
  322. set(OpenVDB_USES_LOG4CPLUS ON)
  323. endif()
  324. string(FIND ${PREREQUISITE} "IlmImf" _HAS_DEP)
  325. if(NOT ${_HAS_DEP} EQUAL -1)
  326. set(OpenVDB_USES_ILM ON)
  327. endif()
  328. endforeach()
  329. unset(_OPENVDB_PREREQUISITE_LIST)
  330. unset(_HAS_DEP)
  331. if(OpenVDB_USES_BLOSC)
  332. find_package(Blosc QUIET)
  333. if(NOT Blosc_FOUND OR NOT TARGET Blosc::blosc)
  334. message(STATUS "find_package could not find Blosc. Using fallback blosc search...")
  335. find_path(Blosc_INCLUDE_DIR blosc.h)
  336. find_library(Blosc_LIBRARY NAMES blosc)
  337. if (Blosc_INCLUDE_DIR AND Blosc_LIBRARY)
  338. set(Blosc_FOUND TRUE)
  339. add_library(Blosc::blosc UNKNOWN IMPORTED)
  340. set_target_properties(Blosc::blosc PROPERTIES
  341. IMPORTED_LOCATION "${Blosc_LIBRARY}"
  342. INTERFACE_INCLUDE_DIRECTORIES ${Blosc_INCLUDE_DIR})
  343. elseif()
  344. just_fail("Blosc library can not be found!")
  345. endif()
  346. endif()
  347. endif()
  348. if(OpenVDB_USES_LOG4CPLUS)
  349. find_package(Log4cplus ${_quiet} ${_required})
  350. endif()
  351. if(OpenVDB_USES_ILM)
  352. find_package(IlmBase ${_quiet} ${_required})
  353. endif()
  354. if(OpenVDB_USES_EXR)
  355. find_package(OpenEXR ${_quiet} ${_required})
  356. endif()
  357. if(UNIX)
  358. find_package(Threads ${_quiet} ${_required})
  359. endif()
  360. # Set deps. Note that the order here is important. If we're building against
  361. # Houdini 17.5 we must include OpenEXR and IlmBase deps first to ensure the
  362. # users chosen namespaced headers are correctly prioritized. Otherwise other
  363. # include paths from shared installs (including houdini) may pull in the wrong
  364. # headers
  365. set(_OPENVDB_VISIBLE_DEPENDENCIES
  366. Boost::iostreams
  367. Boost::system
  368. IlmBase::Half
  369. )
  370. set(_OPENVDB_DEFINITIONS)
  371. if(OpenVDB_ABI)
  372. list(APPEND _OPENVDB_DEFINITIONS "-DOPENVDB_ABI_VERSION_NUMBER=${OpenVDB_ABI}")
  373. endif()
  374. if(OpenVDB_USES_EXR)
  375. list(APPEND _OPENVDB_VISIBLE_DEPENDENCIES
  376. IlmBase::IlmThread
  377. IlmBase::Iex
  378. IlmBase::Imath
  379. OpenEXR::IlmImf
  380. )
  381. list(APPEND _OPENVDB_DEFINITIONS "-DOPENVDB_TOOLS_RAYTRACER_USE_EXR")
  382. endif()
  383. if(OpenVDB_USES_LOG4CPLUS)
  384. list(APPEND _OPENVDB_VISIBLE_DEPENDENCIES Log4cplus::log4cplus)
  385. list(APPEND _OPENVDB_DEFINITIONS "-DOPENVDB_USE_LOG4CPLUS")
  386. endif()
  387. list(APPEND _OPENVDB_VISIBLE_DEPENDENCIES
  388. TBB::tbb
  389. )
  390. if(UNIX)
  391. list(APPEND _OPENVDB_VISIBLE_DEPENDENCIES
  392. Threads::Threads
  393. )
  394. endif()
  395. set(_OPENVDB_HIDDEN_DEPENDENCIES)
  396. if(OpenVDB_USES_BLOSC)
  397. if(OPENVDB_USE_STATIC_LIBS)
  398. list(APPEND _OPENVDB_VISIBLE_DEPENDENCIES $<LINK_ONLY:Blosc::blosc>)
  399. else()
  400. list(APPEND _OPENVDB_HIDDEN_DEPENDENCIES Blosc::blosc)
  401. endif()
  402. endif()
  403. if(OPENVDB_USE_STATIC_LIBS)
  404. list(APPEND _OPENVDB_VISIBLE_DEPENDENCIES $<LINK_ONLY:ZLIB::ZLIB>)
  405. else()
  406. list(APPEND _OPENVDB_HIDDEN_DEPENDENCIES ZLIB::ZLIB)
  407. endif()
  408. # ------------------------------------------------------------------------
  409. # Configure imported target
  410. # ------------------------------------------------------------------------
  411. set(OpenVDB_LIBRARIES
  412. ${OpenVDB_LIB_COMPONENTS}
  413. )
  414. set(OpenVDB_INCLUDE_DIRS ${OpenVDB_INCLUDE_DIR})
  415. set(OpenVDB_DEFINITIONS)
  416. list(APPEND OpenVDB_DEFINITIONS "${PC_OpenVDB_CFLAGS_OTHER}")
  417. list(APPEND OpenVDB_DEFINITIONS "${_OPENVDB_DEFINITIONS}")
  418. list(REMOVE_DUPLICATES OpenVDB_DEFINITIONS)
  419. set(OpenVDB_LIBRARY_DIRS "")
  420. foreach(LIB ${OpenVDB_LIB_COMPONENTS})
  421. get_filename_component(_OPENVDB_LIBDIR ${LIB} DIRECTORY)
  422. list(APPEND OpenVDB_LIBRARY_DIRS ${_OPENVDB_LIBDIR})
  423. endforeach()
  424. list(REMOVE_DUPLICATES OpenVDB_LIBRARY_DIRS)
  425. foreach(COMPONENT ${OpenVDB_FIND_COMPONENTS})
  426. if(NOT TARGET OpenVDB::${COMPONENT})
  427. if (${COMPONENT} STREQUAL openvdb)
  428. include (${CMAKE_CURRENT_LIST_DIR}/CheckAtomic.cmake)
  429. set(_LINK_LIBS ${_OPENVDB_VISIBLE_DEPENDENCIES} ${CMAKE_REQUIRED_LIBRARIES})
  430. else ()
  431. set(_LINK_LIBS _OPENVDB_VISIBLE_DEPENDENCIES)
  432. endif ()
  433. add_library(OpenVDB::${COMPONENT} UNKNOWN IMPORTED)
  434. set_target_properties(OpenVDB::${COMPONENT} PROPERTIES
  435. INTERFACE_COMPILE_OPTIONS "${OpenVDB_DEFINITIONS}"
  436. INTERFACE_INCLUDE_DIRECTORIES "${OpenVDB_INCLUDE_DIR}"
  437. IMPORTED_LINK_DEPENDENT_LIBRARIES "${_OPENVDB_HIDDEN_DEPENDENCIES}" # non visible deps
  438. INTERFACE_LINK_LIBRARIES "${_LINK_LIBS}" # visible deps (headers)
  439. INTERFACE_COMPILE_FEATURES cxx_std_11
  440. IMPORTED_LOCATION "${OpenVDB_${COMPONENT}_LIBRARY}"
  441. )
  442. if (_is_multi)
  443. set_target_properties(OpenVDB::${COMPONENT} PROPERTIES
  444. IMPORTED_LOCATION_RELEASE "${OpenVDB_${COMPONENT}_LIBRARY_RELEASE}"
  445. )
  446. if (MSVC OR OpenVDB_${COMPONENT}_LIBRARY_DEBUG)
  447. set_target_properties(OpenVDB::${COMPONENT} PROPERTIES
  448. IMPORTED_LOCATION_DEBUG "${OpenVDB_${COMPONENT}_LIBRARY_DEBUG}"
  449. )
  450. endif ()
  451. endif ()
  452. if (OPENVDB_USE_STATIC_LIBS)
  453. set_target_properties(OpenVDB::${COMPONENT} PROPERTIES
  454. INTERFACE_COMPILE_DEFINITIONS "OPENVDB_STATICLIB;OPENVDB_OPENEXR_STATICLIB"
  455. )
  456. endif()
  457. endif()
  458. endforeach()
  459. if(OpenVDB_FOUND AND NOT OpenVDB_FIND_QUIETLY)
  460. message(STATUS "OpenVDB libraries: ${OpenVDB_LIBRARIES}")
  461. endif()
  462. unset(_OPENVDB_DEFINITIONS)
  463. unset(_OPENVDB_VISIBLE_DEPENDENCIES)
  464. unset(_OPENVDB_HIDDEN_DEPENDENCIES)