Skip to content

Commit 6d0205f

Browse files
committed
Reuse an externally provided fmt instead of adding a second copy
rapids_cpm_find only checks for duplicate packages when GLOBAL_TARGETS is set. After #281, if the enclosing project already provides fmt::fmt, NVBench adds it again, which collides on fmt trying to add a library alias. Add a guard for rapids_cpm_find, and add the existing fmt to the export sets for find_dependency(fmt). Signed-off-by: Igor Peshansky <ipeshansky@nvidia.com>
1 parent d4ccbc0 commit 6d0205f

1 file changed

Lines changed: 30 additions & 17 deletions

File tree

cmake/NVBenchDependencies.cmake

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,42 @@
11
################################################################################
22
# fmtlib/fmt
3+
set(fmt_export_set)
34
set(export_set_details)
45
set(install_fmt OFF)
56
if(NOT BUILD_SHARED_LIBS AND NVBench_ENABLE_INSTALL_RULES)
6-
set(export_set_details BUILD_EXPORT_SET nvbench-targets
7-
INSTALL_EXPORT_SET nvbench-targets)
7+
set(fmt_export_set nvbench-targets)
8+
set(export_set_details BUILD_EXPORT_SET ${fmt_export_set}
9+
INSTALL_EXPORT_SET ${fmt_export_set})
810
set(install_fmt ON)
911
endif()
1012

11-
rapids_cpm_find(fmt 12.2.0 ${export_set_details}
12-
CPM_ARGS
13-
GIT_REPOSITORY "https://github.com/fmtlib/fmt.git"
14-
GIT_TAG "12.2.0"
15-
OPTIONS
16-
# Force static to keep fmt internal.
17-
"BUILD_SHARED_LIBS OFF"
18-
# Suppress warnings from fmt headers by marking them as system.
19-
"FMT_SYSTEM_HEADERS ON"
20-
# Disable install rules since we're linking statically.
21-
"FMT_INSTALL ${install_fmt}"
22-
"CMAKE_POSITION_INDEPENDENT_CODE ON"
23-
)
24-
25-
if(NOT fmt_ADDED)
13+
# fmt may already be provided by the enclosing project
14+
if(TARGET fmt::fmt)
15+
message(STATUS "NVBench: using externally provided fmt ${fmt_VERSION}")
2616
set(fmt_is_external TRUE)
17+
if(fmt_export_set)
18+
include("${rapids-cmake-dir}/export/package.cmake")
19+
rapids_export_package(BUILD fmt ${fmt_export_set})
20+
rapids_export_package(INSTALL fmt ${fmt_export_set})
21+
endif()
22+
else()
23+
rapids_cpm_find(fmt 12.2.0 ${export_set_details}
24+
CPM_ARGS
25+
GIT_REPOSITORY "https://github.com/fmtlib/fmt.git"
26+
GIT_TAG "12.2.0"
27+
OPTIONS
28+
# Force static to keep fmt internal.
29+
"BUILD_SHARED_LIBS OFF"
30+
# Suppress warnings from fmt headers by marking them as system.
31+
"FMT_SYSTEM_HEADERS ON"
32+
# Disable install rules since we're linking statically.
33+
"FMT_INSTALL ${install_fmt}"
34+
"CMAKE_POSITION_INDEPENDENT_CODE ON"
35+
)
36+
37+
if(NOT fmt_ADDED)
38+
set(fmt_is_external TRUE)
39+
endif()
2740
endif()
2841

2942
################################################################################

0 commit comments

Comments
 (0)