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
This commit is contained in:
Jesse Yurkovich
2025-08-12 21:26:38 +02:00
committed by Jesse Yurkovich
parent 42b6c7f804
commit 0240a1f32f
18 changed files with 43 additions and 216 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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()

View File

@@ -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()

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -7,8 +7,10 @@
*/
#include "BLI_math_base.hh"
#include "BLI_math_constants.h"
#include "BKE_ocean.h"
#include "ocean_intern.h"
#include <algorithm>

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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)

View File

@@ -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

View File

@@ -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()

View File

@@ -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)

View File

@@ -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}"

View File

@@ -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