From 084fabb0003fc674eff5af84e7ab6be0af45b1ca Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 18 Jul 2024 09:34:12 +1000 Subject: [PATCH] deps: add a small helper to locate lists of nerdcruft dependencies --- nc.cmake | 1 + nc_deps.cmake | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 nc_deps.cmake diff --git a/nc.cmake b/nc.cmake index 93e929b..11197cb 100644 --- a/nc.cmake +++ b/nc.cmake @@ -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_optimisation.cmake") include ("${CMAKE_CURRENT_LIST_DIR}/nc_warnings.cmake") +include ("${CMAKE_CURRENT_LIST_DIR}/nc_deps.cmake") \ No newline at end of file diff --git a/nc_deps.cmake b/nc_deps.cmake new file mode 100644 index 0000000..245eada --- /dev/null +++ b/nc_deps.cmake @@ -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 () +