From 0240a1f32fb02b502d1be8f189de04f8bbc40d4c Mon Sep 17 00:00:00 2001 From: Jesse Yurkovich Date: Tue, 12 Aug 2025 21:26:38 +0200 Subject: [PATCH] Cleanup: CMake: Modernize bf_intern_openvdb dependencies This follows the other CMake "modernization" commits, this time for `bf_intern_openvdb` and the OpenVDB dependency itself. The difference with this one is that `intern/openvdb` becomes an "optional" dependency itself. This is because downstream consumers often want to include this dependency rather than openvdb directly, so this target must also be optional. Optional, in this case, means the target always exists but may be entirely empty. Summary - If you are using BKE APIs to access openvdb features, then use the `bf::blenkernel` target - If you are only using `intern/openvdb` APIs then use the `bf::intern::optional::openvdb` target (rare) - For all other cases, use the `bf::dependencies::optional::openvdb` target (rare) context: https://devtalk.blender.org/t/cmake-cleanup/30260 Pull Request: https://projects.blender.org/blender/blender/pulls/137071 --- CMakeLists.txt | 21 ------------ .../cmake/platform/dependency_targets.cmake | 24 ++++++++++++++ extern/mantaflow/CMakeLists.txt | 16 +-------- intern/CMakeLists.txt | 6 ++-- intern/mantaflow/CMakeLists.txt | 11 +------ intern/openvdb/CMakeLists.txt | 33 +++++++------------ source/blender/blenkernel/CMakeLists.txt | 15 +-------- .../blenkernel/intern/ocean_spectrum.cc | 2 ++ source/blender/draw/CMakeLists.txt | 14 -------- .../blender/editors/space_node/CMakeLists.txt | 14 -------- .../editors/space_spreadsheet/CMakeLists.txt | 13 -------- source/blender/geometry/CMakeLists.txt | 14 -------- source/blender/io/usd/CMakeLists.txt | 13 -------- source/blender/makesrna/intern/CMakeLists.txt | 18 +--------- source/blender/modifiers/CMakeLists.txt | 14 -------- source/blender/nodes/CMakeLists.txt | 10 ------ source/blender/nodes/geometry/CMakeLists.txt | 10 ------ source/blender/python/intern/CMakeLists.txt | 11 ------- 18 files changed, 43 insertions(+), 216 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0cbe9624089..1e33020df78 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1656,27 +1656,6 @@ if(NOT WITH_SYSTEM_EIGEN3) set(EIGEN3_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/extern/Eigen3) endif() -if(WITH_OPENVDB) - list(APPEND OPENVDB_DEFINITIONS -DWITH_OPENVDB) - - if(WITH_OPENVDB_3_ABI_COMPATIBLE) - list(APPEND OPENVDB_DEFINITIONS -DOPENVDB_3_ABI_COMPATIBLE) - endif() - - # OpenVDB headers use deprecated TBB headers, silence warning. - list(APPEND OPENVDB_DEFINITIONS -DTBB_SUPPRESS_DEPRECATED_MESSAGES=1) - - list(APPEND OPENVDB_INCLUDE_DIRS - ${BOOST_INCLUDE_DIR} - ${TBB_INCLUDE_DIRS} - ${OPENEXR_INCLUDE_DIRS} - ) - - if(WITH_OPENVDB_BLOSC) - list(APPEND OPENVDB_DEFINITIONS -DWITH_OPENVDB_BLOSC) - endif() -endif() - # ----------------------------------------------------------------------------- # Configure Metal diff --git a/build_files/cmake/platform/dependency_targets.cmake b/build_files/cmake/platform/dependency_targets.cmake index dfe4d6a74f1..0de437af9ca 100644 --- a/build_files/cmake/platform/dependency_targets.cmake +++ b/build_files/cmake/platform/dependency_targets.cmake @@ -38,6 +38,30 @@ if(WITH_MANIFOLD) endif() endif() +# ----------------------------------------------------------------------------- +# Configure OpenVDB + +add_library(bf_deps_optional_openvdb INTERFACE) +add_library(bf::dependencies::optional::openvdb ALIAS bf_deps_optional_openvdb) + +if(WITH_OPENVDB) + target_compile_definitions(bf_deps_optional_openvdb INTERFACE WITH_OPENVDB) + if(WITH_OPENVDB_BLOSC) + target_compile_definitions(bf_deps_optional_openvdb INTERFACE WITH_OPENVDB_BLOSC) + endif() + if(WITH_OPENVDB_3_ABI_COMPATIBLE) + target_compile_definitions(bf_deps_optional_openvdb INTERFACE OPENVDB_3_ABI_COMPATIBLE) + endif() + + target_include_directories(bf_deps_optional_openvdb SYSTEM INTERFACE ${OPENVDB_INCLUDE_DIRS}) + target_link_libraries(bf_deps_optional_openvdb + INTERFACE + ${OPENVDB_LIBRARIES} + bf::dependencies::optional::tbb + ) +endif() + + # ----------------------------------------------------------------------------- # Configure Eigen diff --git a/extern/mantaflow/CMakeLists.txt b/extern/mantaflow/CMakeLists.txt index 7f8d2b03f81..b9ee4414a5b 100644 --- a/extern/mantaflow/CMakeLists.txt +++ b/extern/mantaflow/CMakeLists.txt @@ -79,12 +79,6 @@ if(WITH_MANTA_NUMPY AND WITH_PYTHON_NUMPY) endif() if(WITH_OPENVDB) - list(APPEND INC_SYS - ${OPENVDB_INCLUDE_DIRS} - ) - list(APPEND LIB - ${OPENVDB_LIBRARIES} - ) if(WIN32) # OpenVDB emits lots of these, they should be suppressed through other # means but MSVC 16.8/16.9 has broken this functionality, so C4251 is @@ -233,18 +227,10 @@ if(WITH_MANTA_NUMPY AND WITH_PYTHON_NUMPY) endif() set(LIB + PRIVATE bf::dependencies::optional::openvdb PRIVATE bf::dependencies::optional::tbb ${PYTHON_LINKFLAGS} ${PYTHON_LIBRARIES} ) blender_add_lib(extern_mantaflow "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") - -if(WITH_OPENVDB) - # The VDB libs above are only added to as INTERFACE libs by blender_add_lib, - # meaning extern_mantaflow itself actually does not have a dependency on the - # OpenVDB libraries, and CMAKE is free to link the VDB libraries before - # extern_mantaflow causing linker errors on linux. By explicitly declaring - # a dependency here, CMAKE will do the right thing. - target_link_libraries(extern_mantaflow PRIVATE ${OPENVDB_LIBRARIES}) -endif() diff --git a/intern/CMakeLists.txt b/intern/CMakeLists.txt index 22d395cfe4d..41280f5c943 100644 --- a/intern/CMakeLists.txt +++ b/intern/CMakeLists.txt @@ -14,6 +14,8 @@ add_subdirectory(mikktspace) add_subdirectory(eigen) add_subdirectory(sky) +add_subdirectory(openvdb) + if(WITH_AUDASPACE) add_subdirectory(audaspace) endif() @@ -55,10 +57,6 @@ if(WITH_UV_SLIM) add_subdirectory(slim) endif() -if(WITH_OPENVDB) - add_subdirectory(openvdb) -endif() - if(WITH_QUADRIFLOW) add_subdirectory(quadriflow) endif() diff --git a/intern/mantaflow/CMakeLists.txt b/intern/mantaflow/CMakeLists.txt index 80599a30497..48a862e0350 100644 --- a/intern/mantaflow/CMakeLists.txt +++ b/intern/mantaflow/CMakeLists.txt @@ -38,16 +38,6 @@ set(INC_SYS ${ZLIB_INCLUDE_DIRS} ) -if(WITH_OPENVDB) - add_definitions(-DWITH_OPENVDB ${OPENVDB_DEFINITIONS}) - list(APPEND INC_SYS - ${OPENVDB_INCLUDE_DIRS} - ) - list(APPEND LIB - ${OPENVDB_LIBRARIES} - ) -endif() - set(SRC intern/manta_python_API.cpp intern/manta_fluid_API.cpp @@ -65,6 +55,7 @@ set(LIB PRIVATE bf::blenlib PRIVATE bf::dna PRIVATE bf::intern::guardedalloc + PRIVATE bf::dependencies::optional::openvdb PRIVATE bf::dependencies::optional::tbb extern_mantaflow diff --git a/intern/openvdb/CMakeLists.txt b/intern/openvdb/CMakeLists.txt index d03b7623d1e..79a34eb962f 100644 --- a/intern/openvdb/CMakeLists.txt +++ b/intern/openvdb/CMakeLists.txt @@ -2,36 +2,25 @@ # # SPDX-License-Identifier: GPL-2.0-or-later -set(INC - . -) - -set(INC_SYS -) - -set(SRC - openvdb_capi.h - openvdb_fwd.hh -) - -set(LIB - PRIVATE bf::intern::guardedalloc -) - if(WITH_OPENVDB) - add_definitions(-DWITH_OPENVDB ${OPENVDB_DEFINITIONS}) - - list(APPEND INC_SYS - ${OPENVDB_INCLUDE_DIRS} + list(APPEND INC + PUBLIC . ) list(APPEND SRC + openvdb_capi.h + openvdb_fwd.hh openvdb_capi.cc ) list(APPEND LIB - ${OPENVDB_LIBRARIES} + PUBLIC bf::dependencies::optional::openvdb ) + + blender_add_lib(bf_intern_openvdb "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") +else() + # Empty target + add_library(bf_intern_openvdb INTERFACE) endif() -blender_add_lib(bf_intern_openvdb "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") +add_library(bf::intern::optional::openvdb ALIAS bf_intern_openvdb) \ No newline at end of file diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index 92ab9392f37..490c6568bcc 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -590,6 +590,7 @@ set(LIB PRIVATE bf::intern::clog bf_intern_ghost PRIVATE bf::intern::guardedalloc + PUBLIC bf::intern::optional::openvdb # Contains intern-openvdb items in public headers bf_intern_libmv # Uses stub when disabled. bf_intern_mikktspace bf_intern_opensubdiv # Uses stub when disabled. @@ -789,20 +790,6 @@ if(WITH_OPENSUBDIV) add_definitions(-DWITH_OPENSUBDIV) endif() -if(WITH_OPENVDB) - list(APPEND INC - ../../../intern/openvdb - ) - list(APPEND INC_SYS - ${OPENVDB_INCLUDE_DIRS} - ) - list(APPEND LIB - bf_intern_openvdb - ${OPENVDB_LIBRARIES} - ) - add_definitions(-DWITH_OPENVDB ${OPENVDB_DEFINITIONS}) -endif() - if(WITH_QUADRIFLOW) list(APPEND INC ../../../intern/quadriflow diff --git a/source/blender/blenkernel/intern/ocean_spectrum.cc b/source/blender/blenkernel/intern/ocean_spectrum.cc index a178bd65a9e..dc55c25f057 100644 --- a/source/blender/blenkernel/intern/ocean_spectrum.cc +++ b/source/blender/blenkernel/intern/ocean_spectrum.cc @@ -7,8 +7,10 @@ */ #include "BLI_math_base.hh" +#include "BLI_math_constants.h" #include "BKE_ocean.h" + #include "ocean_intern.h" #include diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt index b135bb4dc8b..73651d825e9 100644 --- a/source/blender/draw/CMakeLists.txt +++ b/source/blender/draw/CMakeLists.txt @@ -780,20 +780,6 @@ if(WITH_OPENSUBDIV) ) endif() -if(WITH_OPENVDB) - list(APPEND INC - ../../../intern/openvdb - ) - list(APPEND INC_SYS - ${OPENVDB_INCLUDE_DIRS} - ) - list(APPEND LIB - bf_intern_openvdb - ${OPENVDB_LIBRARIES} - ) - add_definitions(-DWITH_OPENVDB ${OPENVDB_DEFINITIONS}) -endif() - if(WITH_MOD_FLUID) list(APPEND INC ../../../intern/mantaflow/extern diff --git a/source/blender/editors/space_node/CMakeLists.txt b/source/blender/editors/space_node/CMakeLists.txt index 96e0b6af48e..8567669bc7a 100644 --- a/source/blender/editors/space_node/CMakeLists.txt +++ b/source/blender/editors/space_node/CMakeLists.txt @@ -79,20 +79,6 @@ if(WITH_OPENSUBDIV) add_definitions(-DWITH_OPENSUBDIV) endif() -if(WITH_OPENVDB) - list(APPEND INC - ../../../../intern/openvdb - ) - list(APPEND INC_SYS - ${OPENVDB_INCLUDE_DIRS} - ) - list(APPEND LIB - bf_intern_openvdb - ${OPENVDB_LIBRARIES} - ) - add_definitions(-DWITH_OPENVDB ${OPENVDB_DEFINITIONS}) -endif() - if(WITH_TBB) if(WIN32) # TBB includes `Windows.h` which will define min/max macros diff --git a/source/blender/editors/space_spreadsheet/CMakeLists.txt b/source/blender/editors/space_spreadsheet/CMakeLists.txt index b427d68c9a6..a49e5f5417f 100644 --- a/source/blender/editors/space_spreadsheet/CMakeLists.txt +++ b/source/blender/editors/space_spreadsheet/CMakeLists.txt @@ -57,19 +57,6 @@ set(LIB PRIVATE bf::windowmanager ) -if(WITH_OPENVDB) - list(APPEND INC - ../../../../intern/openvdb - ) - list(APPEND INC_SYS - ${OPENVDB_INCLUDE_DIRS} - ) - list(APPEND LIB - ${OPENVDB_LIBRARIES} - ) - add_definitions(-DWITH_OPENVDB ${OPENVDB_DEFINITIONS}) -endif() - blender_add_lib(bf_editor_space_spreadsheet "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") # RNA_prototypes.hh dna_type_offsets.h diff --git a/source/blender/geometry/CMakeLists.txt b/source/blender/geometry/CMakeLists.txt index fed03e18229..ece2d8dec02 100644 --- a/source/blender/geometry/CMakeLists.txt +++ b/source/blender/geometry/CMakeLists.txt @@ -124,20 +124,6 @@ if(WITH_UV_SLIM) add_definitions(-DWITH_UV_SLIM) endif() -if(WITH_OPENVDB) - list(APPEND INC - ../../../intern/openvdb - ) - list(APPEND INC_SYS - ${OPENVDB_INCLUDE_DIRS} - ) - list(APPEND LIB - bf_intern_openvdb - ${OPENVDB_LIBRARIES} - ) - add_definitions(-DWITH_OPENVDB ${OPENVDB_DEFINITIONS}) -endif() - if(WITH_GMP) add_definitions(-DWITH_GMP) diff --git a/source/blender/io/usd/CMakeLists.txt b/source/blender/io/usd/CMakeLists.txt index 81defd084d2..dfe96846a5c 100644 --- a/source/blender/io/usd/CMakeLists.txt +++ b/source/blender/io/usd/CMakeLists.txt @@ -222,19 +222,6 @@ list(APPEND LIB ${TBB_LIBRARIES} ) -if(WITH_OPENVDB) - add_definitions(-DWITH_OPENVDB ${OPENVDB_DEFINITIONS}) - list(APPEND INC - ../../../../intern/openvdb - ) - list(APPEND INC_SYS - ${OPENVDB_INCLUDE_DIRS} - ) - list(APPEND LIB - ${OPENVDB_LIBRARIES} - ) -endif() - if(WITH_MATERIALX) add_definitions(-DWITH_MATERIALX) list(APPEND LIB MaterialXCore) diff --git a/source/blender/makesrna/intern/CMakeLists.txt b/source/blender/makesrna/intern/CMakeLists.txt index f93960f68ef..70134166ece 100644 --- a/source/blender/makesrna/intern/CMakeLists.txt +++ b/source/blender/makesrna/intern/CMakeLists.txt @@ -387,23 +387,6 @@ if(WITH_OPENSUBDIV) ) add_definitions(-DWITH_OPENSUBDIV) endif() -if(WITH_OPENVDB) - list(APPEND INC - ../../../../intern/openvdb - ) - list(APPEND INC_SYS - ${OPENVDB_INCLUDE_DIRS} - ) - add_definitions(-DWITH_OPENVDB ${OPENVDB_DEFINITIONS}) -endif() - -if(WITH_OPENVDB) - add_definitions(-DWITH_OPENVDB) - - if(WITH_OPENVDB_BLOSC) - add_definitions(-DWITH_OPENVDB_BLOSC) - endif() -endif() if(WITH_INPUT_NDOF) add_definitions(-DWITH_INPUT_NDOF) @@ -479,6 +462,7 @@ set(SRC set(LIB PRIVATE bf::animrig PRIVATE bf::dna + PRIVATE bf::dependencies::optional::openvdb PRIVATE bf::dependencies::optional::tbb PRIVATE extern_fmtlib bf_editor_space_api diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt index 0f5b1cf5a35..149f473ac8f 100644 --- a/source/blender/modifiers/CMakeLists.txt +++ b/source/blender/modifiers/CMakeLists.txt @@ -222,20 +222,6 @@ if(WITH_TBB) endif() endif() -if(WITH_OPENVDB) - list(APPEND INC - ../../../intern/openvdb - ) - list(APPEND INC_SYS - ${OPENVDB_INCLUDE_DIRS} - ) - list(APPEND LIB - bf_intern_openvdb - ${OPENVDB_LIBRARIES} - ) - add_definitions(-DWITH_OPENVDB ${OPENVDB_DEFINITIONS}) -endif() - if(WITH_EXPERIMENTAL_FEATURES) add_definitions(-DWITH_SIMULATION_DATABLOCK) endif() diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt index 7529461031e..41a4c711618 100644 --- a/source/blender/nodes/CMakeLists.txt +++ b/source/blender/nodes/CMakeLists.txt @@ -228,16 +228,6 @@ if(WITH_GMP) ) endif() -if(WITH_OPENVDB) - list(APPEND INC - ../../../intern/openvdb - ) - list(APPEND INC_SYS - ${OPENVDB_INCLUDE_DIRS} - ) - add_definitions(-DWITH_OPENVDB ${OPENVDB_DEFINITIONS}) -endif() - blender_add_lib(bf_nodes "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") add_library(bf::nodes ALIAS bf_nodes) diff --git a/source/blender/nodes/geometry/CMakeLists.txt b/source/blender/nodes/geometry/CMakeLists.txt index 5134c929fb9..afca8bebf1d 100644 --- a/source/blender/nodes/geometry/CMakeLists.txt +++ b/source/blender/nodes/geometry/CMakeLists.txt @@ -350,16 +350,6 @@ if(WITH_GMP) ) endif() -if(WITH_OPENVDB) - list(APPEND INC - ../../../../intern/openvdb - ) - list(APPEND INC_SYS - ${OPENVDB_INCLUDE_DIRS} - ) - add_definitions(-DWITH_OPENVDB ${OPENVDB_DEFINITIONS}) -endif() - add_node_discovery( bf_nodes_geometry_generated "${SRC}" diff --git a/source/blender/python/intern/CMakeLists.txt b/source/blender/python/intern/CMakeLists.txt index 36d8e93d390..58345a64d45 100644 --- a/source/blender/python/intern/CMakeLists.txt +++ b/source/blender/python/intern/CMakeLists.txt @@ -320,17 +320,6 @@ if(WITH_IO_GREASE_PENCIL) add_definitions(-DWITH_IO_GREASE_PENCIL) endif() -if(WITH_ALEMBIC) - add_definitions(-DWITH_ALEMBIC) -endif() - -if(WITH_OPENVDB) - add_definitions(-DWITH_OPENVDB) - list(APPEND INC - ../../../../intern/openvdb - ) -endif() - if(WITH_ALEMBIC) add_definitions(-DWITH_ALEMBIC) list(APPEND INC