[BUILD] Cannot find nanobind headers
Environment
**Operating System: Linux (Rocky 8.10) **Version / Commit SHA: 12.0.1 **CMake Version: 3.31.3 **Compiler: GCC 11.2.1
Describe the problem
[63/185] Building CXX object openvdb/openvdb/python/CMakeFiles/nanobind-static.dir/Release/home/alex/packages/nanobind/2.6.1/nanobind/src/nb_internals.cpp.o
FAILED: openvdb/openvdb/python/CMakeFiles/nanobind-static.dir/Release/home/alex/packages/nanobind/2.6.1/nanobind/src/nb_internals.cpp.o
/usr/local/bin/ccache /opt/rh/gcc-toolset-11/root/usr/bin/c++ -DNB_COMPACT_ASSERTIONS -DCMAKE_INTDIR=\"Release\" -O3 -DNDEBUG -std=c++17 -fPIC -ffunction-sections -fdata-sections -fno-strict-aliasing -MD -MT openvdb/openvdb/python/CMakeFiles/nanobind-static.dir/Release/home/alex/packages/nanobind/2.6.1/nanobind/src/nb_internals.cpp.o -MF openvdb/openvdb/python/CMakeFiles/nanobind-static.dir/Release/home/alex/packages/nanobind/2.6.1/nanobind/src/nb_internals.cpp.o.d -o openvdb/openvdb/python/CMakeFiles/nanobind-static.dir/Release/home/alex/packages/nanobind/2.6.1/nanobind/src/nb_internals.cpp.o -c /home/alex/packages/nanobind/2.6.1/nanobind/src/nb_internals.cpp
/home/alex/packages/nanobind/2.6.1/nanobind/src/nb_internals.cpp:10:10: fatal error: nanobind/nanobind.h: No such file or directory
10 | #include <nanobind/nanobind.h>
| ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
To Reproduce
Steps to reproduce the behavior:
- Build Nanobind 2.6.1 (2.5.0 also had the issue) and install somewhere (not on the system)
- Build OpenVDB with
-D nanobind_DIR=/path/to/nanobind/cmake - See error
Additional context
I saw in nanobind-config.cmake that nanobind_add_module has NB_SUPPRESS_WARNINGS that will set it so:
if (ARG_NB_SUPPRESS_WARNINGS)
set(EXTRA_LIBRARY_PARAMS AS_SYSINCLUDE)
endif()
nanobind_build_library(${libname} ${EXTRA_LIBRARY_PARAMS})
Which would set nanobind_build_library to do this:
target_include_directories(${TARGET_NAME} ${AS_SYSINCLUDE} PUBLIC
${Python_INCLUDE_DIRS}
${NB_DIR}/include)
So I did a quick test on this line https://github.com/AcademySoftwareFoundation/openvdb/blob/master/openvdb/openvdb/python/CMakeLists.txt#L54 to NB_STATIC;NB_SUPPRESS_WARNINGS
But this unfortunately wasn't enough...
Just to note for whoever is searching and have a similar issue. The only way I could resolve this is to have nanobind build to the same destination as openvdb. I have a hunch that:
https://github.com/wjakob/nanobind/blob/master/cmake/nanobind-config.cmake#L260
Doesn't seem to pass along nanobind or python to be in the target_include_directories. Whether or not it is an oversight of openvdb or how nanobind is meant to be used through CMake I am not sure (yet).
Cheers
I have also run into this - this seems like an issue with the brew configuration of nanobind. Nanobind needs the robin-map dependency. If it doesn't find it (during find_package(nanobind)), it early exits with a warning and doesn't correctly configure the nanobind target (cmake generation will incorrectly succeed). In my test, brew install nanobind does not correctly bring down the dependency.
To fix, all I needed to do was brew install robin-map - re-running cmake no longer produced the warning and the config/includes were correct.
I will update the VDB build docs, but this seems like multiple issues with thew brew config + an issue with the nanobind CMake not correctly error-ing out if it can't find robin-map