Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions cmake/VSAGHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,31 @@ function (vsag_fail_missing_system_dep dep package hint)
"Install package '${package}', expose target ${hint} before configuring VSAG, "
"or set VSAG_USE_SYSTEM_${dep}=OFF to use the bundled copy.")
endfunction ()

# Return TRUE when ${target}'s declared include directories contain ${header}.
function (vsag_target_has_header target header out_var)
set (_include_dirs "")
get_target_property (_target_includes ${target} INTERFACE_INCLUDE_DIRECTORIES)
if (_target_includes)
list (APPEND _include_dirs ${_target_includes})
endif ()

get_target_property (_target_system_includes ${target} INTERFACE_SYSTEM_INCLUDE_DIRECTORIES)
if (_target_system_includes)
list (APPEND _include_dirs ${_target_system_includes})
endif ()

set (_found FALSE)
foreach (_include_dir ${_include_dirs})
if (_include_dir MATCHES "^\\$<BUILD_INTERFACE:(.*)>$")
set (_include_dir "${CMAKE_MATCH_1}")
elseif (_include_dir MATCHES "^\\$<INSTALL_INTERFACE:.*>$")
continue ()
endif ()
if (_include_dir AND EXISTS "${_include_dir}/${header}")
set (_found TRUE)
break ()
endif ()
endforeach ()
set (${out_var} ${_found} PARENT_SCOPE)
endfunction ()
4 changes: 4 additions & 0 deletions cmake/VSAGOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ set (VSAG_USE_SYSTEM_OPENBLAS "" CACHE STRING
"Override VSAG_USE_SYSTEM_DEPS for OpenBLAS: AUTO, ON, OFF, or empty to inherit.")
set_property (CACHE VSAG_USE_SYSTEM_OPENBLAS PROPERTY STRINGS "" AUTO ON OFF)

set (VSAG_USE_SYSTEM_FMT "" CACHE STRING
"Override VSAG_USE_SYSTEM_DEPS for fmt: AUTO, ON, OFF, or empty to inherit.")
set_property (CACHE VSAG_USE_SYSTEM_FMT PROPERTY STRINGS "" AUTO ON OFF)

set (_default_aclocal_path "")
if (DEFINED ENV{ACLOCAL_PATH} AND NOT "$ENV{ACLOCAL_PATH}" STREQUAL "")
set (_default_aclocal_path "$ENV{ACLOCAL_PATH}")
Expand Down
61 changes: 61 additions & 0 deletions extern/fmt/fmt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,67 @@ include (FetchContent)
# ref: https://github.com/fmtlib/fmt/issues/2708
set (FMT_SYSTEM_HEADERS ON)

vsag_get_system_dep_policy (FMT _fmt_policy)
set (FMT_FOUND FALSE)

if (NOT _fmt_policy STREQUAL "OFF")
if (TARGET fmt::fmt)
vsag_target_has_header (fmt::fmt fmt/format.h _fmt_has_header)
if (_fmt_has_header)
set (FMT_FOUND TRUE)
message (STATUS "Using pre-existing fmt::fmt target")
else ()
message (STATUS "Ignoring pre-existing fmt::fmt target without fmt/format.h")
endif ()
endif ()

if (NOT FMT_FOUND)
set (_fmt_include_hints "")
if (DEFINED fmt_DIR AND NOT "${fmt_DIR}" STREQUAL "")
get_filename_component (_fmt_prefix "${fmt_DIR}/../../.." ABSOLUTE)
list (APPEND _fmt_include_hints "${_fmt_prefix}" "${_fmt_prefix}/include")
endif ()

unset (_fmt_include_dir CACHE)
unset (_vsag_fmt_include_dir CACHE)
find_path (_vsag_fmt_include_dir
NAMES fmt/format.h
HINTS ${_fmt_include_hints}
PATH_SUFFIXES include)
set (_fmt_include_dir "${_vsag_fmt_include_dir}")
unset (_vsag_fmt_include_dir CACHE)

if (_fmt_include_dir)
find_package (fmt CONFIG QUIET)
if (TARGET fmt::fmt)
vsag_target_has_header (fmt::fmt fmt/format.h _fmt_has_header)
if (_fmt_has_header)
set (FMT_FOUND TRUE)
message (STATUS "Found fmt via find_package(fmt CONFIG)")
else ()
message (STATUS "Ignoring fmt package without fmt/format.h")
endif ()
else ()
message (STATUS "Ignoring fmt package without fmt::fmt target")
endif ()
else ()
message (STATUS "fmt/format.h was not found in system include paths")
endif ()
endif ()
Comment thread
wxyucs marked this conversation as resolved.

if (NOT FMT_FOUND AND _fmt_policy STREQUAL "ON")
vsag_fail_missing_system_dep (FMT fmt fmt::fmt)
endif ()
endif ()

if (FMT_FOUND)
if (NOT TARGET fmt::fmt-header-only)
add_library (fmt::fmt-header-only INTERFACE IMPORTED GLOBAL)
target_link_libraries (fmt::fmt-header-only INTERFACE fmt::fmt)
endif ()
return ()
endif ()

set (fmt_urls
https://github.com/fmtlib/fmt/archive/refs/tags/10.2.1.tar.gz
# this url is maintained by the vsag project, if it's broken, please try
Expand Down
Loading