From 0108acf367033c04108e65006feca9de7d3cd59d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20M=C3=BCthing?= <muething@dune-project.org> Date: Wed, 15 Apr 2015 14:09:23 +0200 Subject: [PATCH] [CMake] dune_library_add_sources: Add some sanity checks This patch adds some sanity checks to dune_library_add_sources: - Make sure that dune_enable_all_packages has been called - Test whether the library has been declared in the MODULE_LIBRARIES argument of dune_enable_all_packages In case of an error, the macro aborts the CMake run with a fatal error. --- cmake/modules/DuneEnableAllPackages.cmake | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cmake/modules/DuneEnableAllPackages.cmake b/cmake/modules/DuneEnableAllPackages.cmake index b117b3648..5b244bf67 100644 --- a/cmake/modules/DuneEnableAllPackages.cmake +++ b/cmake/modules/DuneEnableAllPackages.cmake @@ -196,6 +196,19 @@ macro(dune_library_add_sources lib) message(FATAL_ERROR "dune_library_add_sources() requires CMake 3.1+") endif() + if (NOT (DEFINED DUNE_ENABLE_ALL_PACKAGES_MODULE_LIBRARIES)) + message(FATAL_ERROR "You must call dune_enable_all_packages with the MODULE_LIBRARIES option before calling dune_library_add_sources") + endif() + + # This looks weird, but seems to be the most practical way to check for list membership, + # as list(FIND ...) does not work reliably in a macro... + if (NOT (";${DUNE_ENABLE_ALL_PACKAGES_MODULE_LIBRARIES};" MATCHES ";${lib};")) + message(FATAL_ERROR +"Attempt to add sources to library ${lib}, which has not been defined in dune_enable_all_packages. +List of libraries defined in dune_enable_all_packages: ${DUNE_ENABLE_ALL_PACKAGES_MODULE_LIBRARIES}") + endif() + unset(lib_defined) + include(CMakeParseArguments) cmake_parse_arguments(DUNE_LIBRARY_ADD_SOURCES "" "" "SOURCES" ${ARGN}) -- GitLab