Skip to content

Commit d145ec5

Browse files
authored
Allow to use nanobind as an archive in FetchContent (#1212)
* declare tsl::robin_map as imported interface library - Only find the dependency when tsl::robin_map is not present (fetchcontent archive support) - Requires tsl-robin-map as mandatory * declare imported library only if not already present
1 parent 1a5bba5 commit d145ec5

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

cmake/nanobind-config.cmake

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,20 @@ function (nanobind_build_library TARGET_NAME)
246246
# However, if the directory _does_ exist, then the user is free to choose
247247
# whether nanobind uses them (based on `NB_USE_SUBMODULE_DEPS`), with a
248248
# preference to choose them if `NB_USE_SUBMODULE_DEPS` is not defined
249-
if (NOT IS_DIRECTORY ${NB_DIR}/ext/robin_map/include OR
250-
(DEFINED NB_USE_SUBMODULE_DEPS AND NOT NB_USE_SUBMODULE_DEPS))
249+
if(IS_DIRECTORY ${NB_DIR}/ext/robin_map/include
250+
AND (DEFINED NB_USE_SUBMODULE_DEPS AND NB_USE_SUBMODULE_DEPS)
251+
AND NOT TARGET tsl::robin_map
252+
)
253+
add_library(tsl::robin_map INTERFACE IMPORTED)
254+
set_target_properties(tsl::robin_map PROPERTIES
255+
INTERFACE_INCLUDE_DIRECTORIES ${NB_DIR}/ext/robin_map/include)
256+
endif()
257+
258+
if(NOT TARGET tsl::robin_map)
251259
include(CMakeFindDependencyMacro)
252-
find_dependency(tsl-robin-map)
253-
target_link_libraries(${TARGET_NAME} PRIVATE tsl::robin_map)
254-
else()
255-
target_include_directories(${TARGET_NAME} PRIVATE
256-
${NB_DIR}/ext/robin_map/include)
260+
find_dependency(tsl-robin-map CONFIG REQUIRED)
257261
endif()
262+
target_link_libraries(${TARGET_NAME} PRIVATE tsl::robin_map)
258263

259264
target_include_directories(${TARGET_NAME} ${AS_SYSINCLUDE} PUBLIC
260265
${Python_INCLUDE_DIRS}

0 commit comments

Comments
 (0)