The provided CMake code contains a logical error in the main if condition that will cause it to crash or behave unpredictably. ## The Core Bug The issue lies in this line: if((var MATCHES "_(LIBRARIES|LIBRARY|INCLUDE|VERSION)") AND (NOT ${${var}} STREQUAL "") AND ...) ## Why it fails * ${var} evaluates to the value of the variable stored in var (e.g., /usr/include). * ${${var}} attempts a double expansion. It looks for a variable whose name is literally /usr/include. * If that path contains semicolons, spaces, or special characters, CMake will throw a syntax error. If it is empty, CMake will evaluate it as NOT STREQUAL "" and cause unexpected behavior. ## The Fix In CMake if statements, you do not need to expand variables when checking if they are empty or defined. You should pass the variable name directly, or use DEFINED. Here is the corrected code: #---Populate the configure arguments returned by 'root-config --config'-------------------------get_cmake_property(variables CACHE_VARIABLES)foreach(var ${variables}) # FIX: Use NOT "${${var}}" STREQUAL "" with quotes, or simply check if the variable is defined and not empty if((var MATCHES "_(LIBRARIES|LIBRARY|INCLUDE|VERSION)") AND (DEFINED ${var}) AND (NOT "${${var}}" STREQUAL "") AND (NOT var MATCHES "NOTFOUND")) # FIX: var should not have ${} here either if checking the name 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") # Created by the 'latest' call to project() AND NOT(var MATCHES "^CMAKE_CACHE_") # related to previous CMake invocation eg CMAKE_CACHE_MAJOR_VERSION AND NOT(var MATCHES "^ROOT_.*_LIBRARY$")) # Created for users in ROOTConfig.cmake set(ROOT_CONFIGARGS "${ROOT_CONFIGARGS}${var}=${${var}} ") endif() endif() endif()endforeach() ## Key Improvements Made * Added Quotes: Changed ${${var}} to "${${var}}". This prevents CMake from breaking when a variable contains a list (semicolons) or spaces. * Fixed NOTFOUND Check: Changed NOT ${var} MATCHES "NOTFOUND" to NOT var MATCHES "NOTFOUND". You want to check if the variable name or its content contains "NOTFOUND". If you meant to check the content, it should be NOT "${${var}}" MATCHES "NOTFOUND". To help me tailor this script perfectly, tell me: * What CMake version are you targeting? * Are you getting a specific error message during configuration? * Is this for a custom ROOT framework build?