From c1379ef56a153cf9a901df56777b691f9623a275 Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Sun, 26 Apr 2026 16:06:04 +0200 Subject: [PATCH] find_* commands: ensure correct checks for VALIDATOR option Ensure, regardless where the command is defined, that a macro is not accepted as value for VALIDATOR option. --- Source/cmFindBase.cxx | 12 +++++------- .../find_file/VALIDATOR-specify-macro-stderr.txt | 6 ++++++ .../RunCMake/find_file/VALIDATOR-specify-macro.cmake | 3 +++ Tests/RunCMake/find_file/subdir/CMakeLists.txt | 3 +++ .../find_library/VALIDATOR-specify-macro-stderr.txt | 6 ++++++ .../find_library/VALIDATOR-specify-macro.cmake | 3 +++ Tests/RunCMake/find_library/subdir/CMakeLists.txt | 3 +++ .../find_path/VALIDATOR-specify-macro-stderr.txt | 6 ++++++ .../RunCMake/find_path/VALIDATOR-specify-macro.cmake | 3 +++ Tests/RunCMake/find_path/subdir/CMakeLists.txt | 3 +++ .../find_program/VALIDATOR-specify-macro-stderr.txt | 6 ++++++ .../find_program/VALIDATOR-specify-macro.cmake | 3 +++ Tests/RunCMake/find_program/subdir/CMakeLists.txt | 3 +++ 13 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 Tests/RunCMake/find_file/subdir/CMakeLists.txt create mode 100644 Tests/RunCMake/find_library/subdir/CMakeLists.txt create mode 100644 Tests/RunCMake/find_path/subdir/CMakeLists.txt create mode 100644 Tests/RunCMake/find_program/subdir/CMakeLists.txt diff --git a/Source/cmFindBase.cxx b/Source/cmFindBase.cxx index 3e98e3f796..e9e8dfd4b9 100644 --- a/Source/cmFindBase.cxx +++ b/Source/cmFindBase.cxx @@ -184,18 +184,16 @@ bool cmFindBase::ParseArguments(std::vector const& argsIn) } // ensure a macro is not specified as validator auto const& validatorName = args[j]; - cmList macros{ this->Makefile->GetProperty("MACROS") }; - if (std::find_if(macros.begin(), macros.end(), - [&validatorName](std::string const& item) { - return cmSystemTools::Strucmp(validatorName.c_str(), - item.c_str()) == 0; - }) != macros.end()) { + if (this->Makefile->GetState() + ->GetCommandType(validatorName) + .value_or(cmStateEnums::CommandType::Macro) != + cmStateEnums::CommandType::Function) { this->SetError(cmStrCat( "command specified for VALIDATOR is not a function: ", args[j], '.')); return false; } - this->ValidatorName = args[j]; + this->ValidatorName = validatorName; } else if (this->CheckCommonArgument(args[j])) { doing = DoingNone; } else { diff --git a/Tests/RunCMake/find_file/VALIDATOR-specify-macro-stderr.txt b/Tests/RunCMake/find_file/VALIDATOR-specify-macro-stderr.txt index f6391ad88e..1f4da93dcd 100644 --- a/Tests/RunCMake/find_file/VALIDATOR-specify-macro-stderr.txt +++ b/Tests/RunCMake/find_file/VALIDATOR-specify-macro-stderr.txt @@ -2,3 +2,9 @@ CMake Error at VALIDATOR-specify-macro\.cmake:[0-9]+ \(find_file\): find_file command specified for VALIDATOR is not a function: check\. Call Stack \(most recent call first\): CMakeLists\.txt:[0-9]+ \(include\) + + +CMake Error at VALIDATOR-specify-macro\.cmake:[0-9]+ \(find_file\): + find_file command specified for VALIDATOR is not a function: check2\. +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/find_file/VALIDATOR-specify-macro.cmake b/Tests/RunCMake/find_file/VALIDATOR-specify-macro.cmake index ec0ce9a30d..861fbf5db4 100644 --- a/Tests/RunCMake/find_file/VALIDATOR-specify-macro.cmake +++ b/Tests/RunCMake/find_file/VALIDATOR-specify-macro.cmake @@ -3,3 +3,6 @@ macro(CHECK result path) endmacro() find_file(result NAMES input.txt VALIDATOR check) + +add_subdirectory(subdir) +find_file(result NAMES input.txt VALIDATOR check2) diff --git a/Tests/RunCMake/find_file/subdir/CMakeLists.txt b/Tests/RunCMake/find_file/subdir/CMakeLists.txt new file mode 100644 index 0000000000..1edb7768c5 --- /dev/null +++ b/Tests/RunCMake/find_file/subdir/CMakeLists.txt @@ -0,0 +1,3 @@ + +macro(CHECK2 result path) +endmacro() diff --git a/Tests/RunCMake/find_library/VALIDATOR-specify-macro-stderr.txt b/Tests/RunCMake/find_library/VALIDATOR-specify-macro-stderr.txt index 8f7f8c4c21..c2200851f5 100644 --- a/Tests/RunCMake/find_library/VALIDATOR-specify-macro-stderr.txt +++ b/Tests/RunCMake/find_library/VALIDATOR-specify-macro-stderr.txt @@ -2,3 +2,9 @@ CMake Error at VALIDATOR-specify-macro\.cmake:[0-9]+ \(find_library\): find_library command specified for VALIDATOR is not a function: check\. Call Stack \(most recent call first\): CMakeLists\.txt:[0-9]+ \(include\) + + +CMake Error at VALIDATOR-specify-macro\.cmake:[0-9]+ \(find_library\): + find_library command specified for VALIDATOR is not a function: check2\. +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/find_library/VALIDATOR-specify-macro.cmake b/Tests/RunCMake/find_library/VALIDATOR-specify-macro.cmake index fa90d723df..f652828bec 100644 --- a/Tests/RunCMake/find_library/VALIDATOR-specify-macro.cmake +++ b/Tests/RunCMake/find_library/VALIDATOR-specify-macro.cmake @@ -3,3 +3,6 @@ macro(CHECK result path) endmacro() find_library(result NAMES input.txt VALIDATOR check) + +add_subdirectory(subdir) +find_library(result NAMES input.txt VALIDATOR check2) diff --git a/Tests/RunCMake/find_library/subdir/CMakeLists.txt b/Tests/RunCMake/find_library/subdir/CMakeLists.txt new file mode 100644 index 0000000000..1edb7768c5 --- /dev/null +++ b/Tests/RunCMake/find_library/subdir/CMakeLists.txt @@ -0,0 +1,3 @@ + +macro(CHECK2 result path) +endmacro() diff --git a/Tests/RunCMake/find_path/VALIDATOR-specify-macro-stderr.txt b/Tests/RunCMake/find_path/VALIDATOR-specify-macro-stderr.txt index 9f0e3e82b3..bff9f352da 100644 --- a/Tests/RunCMake/find_path/VALIDATOR-specify-macro-stderr.txt +++ b/Tests/RunCMake/find_path/VALIDATOR-specify-macro-stderr.txt @@ -2,3 +2,9 @@ CMake Error at VALIDATOR-specify-macro\.cmake:[0-9]+ \(find_path\): find_path command specified for VALIDATOR is not a function: check\. Call Stack \(most recent call first\): CMakeLists\.txt:[0-9]+ \(include\) + + +CMake Error at VALIDATOR-specify-macro\.cmake:[0-9]+ \(find_path\): + find_path command specified for VALIDATOR is not a function: check2\. +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/find_path/VALIDATOR-specify-macro.cmake b/Tests/RunCMake/find_path/VALIDATOR-specify-macro.cmake index 62b44ed6ce..f1faded600 100644 --- a/Tests/RunCMake/find_path/VALIDATOR-specify-macro.cmake +++ b/Tests/RunCMake/find_path/VALIDATOR-specify-macro.cmake @@ -3,3 +3,6 @@ macro(CHECK result path) endmacro() find_path(result NAMES input.txt VALIDATOR check) + +add_subdirectory(subdir) +find_path(result NAMES input.txt VALIDATOR check2) diff --git a/Tests/RunCMake/find_path/subdir/CMakeLists.txt b/Tests/RunCMake/find_path/subdir/CMakeLists.txt new file mode 100644 index 0000000000..1edb7768c5 --- /dev/null +++ b/Tests/RunCMake/find_path/subdir/CMakeLists.txt @@ -0,0 +1,3 @@ + +macro(CHECK2 result path) +endmacro() diff --git a/Tests/RunCMake/find_program/VALIDATOR-specify-macro-stderr.txt b/Tests/RunCMake/find_program/VALIDATOR-specify-macro-stderr.txt index 949f29d85a..567e577cb2 100644 --- a/Tests/RunCMake/find_program/VALIDATOR-specify-macro-stderr.txt +++ b/Tests/RunCMake/find_program/VALIDATOR-specify-macro-stderr.txt @@ -2,3 +2,9 @@ CMake Error at VALIDATOR-specify-macro\.cmake:[0-9]+ \(find_program\): find_program command specified for VALIDATOR is not a function: check\. Call Stack \(most recent call first\): CMakeLists\.txt:[0-9]+ \(include\) + + +CMake Error at VALIDATOR-specify-macro\.cmake:[0-9]+ \(find_program\): + find_program command specified for VALIDATOR is not a function: check2\. +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/find_program/VALIDATOR-specify-macro.cmake b/Tests/RunCMake/find_program/VALIDATOR-specify-macro.cmake index 43bb9ec310..3e5e579e45 100644 --- a/Tests/RunCMake/find_program/VALIDATOR-specify-macro.cmake +++ b/Tests/RunCMake/find_program/VALIDATOR-specify-macro.cmake @@ -3,3 +3,6 @@ macro(CHECK result path) endmacro() find_program(result NAMES input.txt VALIDATOR check) + +add_subdirectory(subdir) +find_program(result NAMES input.txt VALIDATOR check2) diff --git a/Tests/RunCMake/find_program/subdir/CMakeLists.txt b/Tests/RunCMake/find_program/subdir/CMakeLists.txt new file mode 100644 index 0000000000..1edb7768c5 --- /dev/null +++ b/Tests/RunCMake/find_program/subdir/CMakeLists.txt @@ -0,0 +1,3 @@ + +macro(CHECK2 result path) +endmacro()