Yes, I am sure about the logical flaws, though there is an important nuance regarding where it will break. This block is extracted from the official CERN ROOT framework's main CMakeLists.txt file. [1, 2] While it has successfully run for years in that specific environment, it relies on hazardous syntax behavior that breaks easily if copied elsewhere or if your cache contains certain characters. The original code will cause syntax errors, unquoted variable expansion issues, or silent evaluation bugs in three places: ## 1. The NOT ${${var}} STREQUAL "" evaluation (Syntax Error) In standard programming logic, you want to see if the value of the variable is empty. However, because CMake variables are often lists (strings separated by semicolons, like paths or lists of libraries), unquoted expansion causes a crash. * * The Bug: If var is ZLIB_LIBRARIES, then ${var} is ZLIB_LIBRARIES. Evaluating ${${var}} expands to something like /usr/lib/libz.so;/usr/lib/libm.so. Without quotes, CMake reads this as: if (NOT /usr/lib/libz.so /usr/lib/libm.so STREQUAL ""). * The Result: CMake fails with a configuration error because if() receives too many arguments. * Why it works inside ROOT: It only passes this check if the variable matches _(LIBRARIES|LIBRARY|INCLUDE|VERSION). In ROOT's exact build environment, those specific matched cache entries usually contain scalar strings or well-formed single paths at the moment this loop runs. * ## 2. The NOT ${var} MATCHES "NOTFOUND" bug (Logical Error) * * The Bug: If you want to check if the value inside the variable contains NOTFOUND (a common CMake placeholder), writing ${var} evaluates to the name of the variable. * The Result: This line reads NOT ZLIB_LIBRARIES MATCHES "NOTFOUND". It is matching the literal string "ZLIB_LIBRARIES" against "NOTFOUND", which is always true. It completely fails to check if the actual path was missing. * The Intent: To check the contents, it must be NOT "${${var}}" MATCHES "NOTFOUND". To check the name, it must be NOT var MATCHES "NOTFOUND". * ## 3. Argument Expansion inside if() Historically (CMake 2.x), variable names inside if() statements were automatically expanded if they matched an existing variable name. This legacy behavior makes if(var MATCHES ...) occasionally behave unpredictably depending on what var resolves to. Modern CMake practices strongly dictate using explicit quotes if("${var}" MATCHES ...) to safeguard against variable name collision and whitespaces. ## What should you do? If you are modifying or debugging a CERN ROOT build and it is currently failing, it is highly likely that a newly added dependency library has spaces, semicolons, or a NOTFOUND status in its cache string. [1, 2] Replacing that exact block with the following safe version stops CMake from misinterpreting lists and spaces: #---Populate the configure arguments returned by 'root-config --config'-------------------------get_cmake_property(variables CACHE_VARIABLES)foreach(var ${variables}) # 1. Safely quote "${var}" for regex matching # 2. Use double quotes around "${${var}}" to prevent list expansion errors # 3. Fixed NOTFOUND to look at the VALUE ("${${var}}"), not the variable name if(("${var}" MATCHES "_(LIBRARIES|LIBRARY|INCLUDE|VERSION)") AND (NOT "${${var}}" STREQUAL "") AND (NOT "${${var}}" MATCHES "NOTFOUND")) if ("${var}" MATCHES "^QT_") # filter out the very long list of Qt libraries and include dirs if ("${var}" MATCHES "(QT_LIBRARY_DIR|QT_QTCORE_INCLUDE_DIR)") set(ROOT_CONFIGARGS "${ROOT_CONFIGARGS}${var}=${${var}} ") endif() else() if ((NOT "${var}" MATCHES "_(DOCS|TESTS|INSTALL)") AND (NOT "${var}" MATCHES "^_") AND NOT("${var}" MATCHES "^CMAKE_PROJECT_VERSION") AND NOT("${var}" MATCHES "^CMAKE_CACHE_") AND NOT("${var}" MATCHES "^ROOT_.*_LIBRARY$")) set(ROOT_CONFIGARGS "${ROOT_CONFIGARGS}${var}=${${var}} ") endif() endif() endif()endforeach() Are you building CERN ROOT from source, or did you copy this snippet for a custom project? If you're getting a specific error message, share it so we can pin down exactly which variable is tripping it up! [1, 2] [1] [https://git.ustc.edu.cn](https://git.ustc.edu.cn/cxwx/root/-/blob/v6-28-02/CMakeLists.txt?ref_type=tags) [2] [https://git.ustc.edu.cn](https://git.ustc.edu.cn/cxwx/root/-/blob/v6-28-02/CMakeLists.txt?ref_type=tags)