deps: add a small helper to locate lists of nerdcruft dependencies

This commit is contained in:
Danny Robson 2024-07-18 09:34:12 +10:00
parent c688cf9dbb
commit 084fabb000
2 changed files with 23 additions and 0 deletions

View File

@ -19,3 +19,4 @@ include ("${CMAKE_CURRENT_LIST_DIR}/nc_sanitizer.cmake")
include ("${CMAKE_CURRENT_LIST_DIR}/nc_platform.cmake") include ("${CMAKE_CURRENT_LIST_DIR}/nc_platform.cmake")
include ("${CMAKE_CURRENT_LIST_DIR}/nc_optimisation.cmake") include ("${CMAKE_CURRENT_LIST_DIR}/nc_optimisation.cmake")
include ("${CMAKE_CURRENT_LIST_DIR}/nc_warnings.cmake") include ("${CMAKE_CURRENT_LIST_DIR}/nc_warnings.cmake")
include ("${CMAKE_CURRENT_LIST_DIR}/nc_deps.cmake")

22
nc_deps.cmake Normal file
View File

@ -0,0 +1,22 @@
# Loads the provided arguments as components from find_package(cruft) if at least one is missing
macro (nc_deps)
if (${ARGC} LESS_EQUAL 0)
message (FATAL_ERROR "nc_deps requires at least one component")
endif ()
set (__nc_deps_lib_FAIL)
foreach (__nc_deps_lib ${ARGN})
if (NOT TARGET cruft::${__nc_deps_lib})
message (WARNING "missing cruft::${lib}")
set (__nc_deps_lib_FAIL 1)
break ()
endif()
endforeach ()
if (DEFINED __nc_deps_lib_FAIL)
message (STATUS "using find_package for cruft::${ARGN}")
find_package(cruft CONFIG REQUIRED COMPONENTS ${ARGN})
endif ()
endmacro ()