From fb2fa4765611bbf94fdf63a50ff20c5905d34057 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 28 May 2014 22:02:57 +0200 Subject: Genex: Clarify error message on use with non-binary targets (#14899). --- Source/cmGeneratorExpressionEvaluator.cxx | 28 +++++++++++----------- .../NonValidTarget-CXX_COMPILER_ID-result.txt | 1 + .../NonValidTarget-CXX_COMPILER_ID-stderr.txt | 9 +++++++ .../NonValidTarget-CXX_COMPILER_ID.cmake | 8 +++++++ .../NonValidTarget-CXX_COMPILER_VERSION-result.txt | 1 + .../NonValidTarget-CXX_COMPILER_VERSION-stderr.txt | 9 +++++++ .../NonValidTarget-CXX_COMPILER_VERSION.cmake | 8 +++++++ .../NonValidTarget-C_COMPILER_ID-result.txt | 1 + .../NonValidTarget-C_COMPILER_ID-stderr.txt | 9 +++++++ .../NonValidTarget-C_COMPILER_ID.cmake | 8 +++++++ .../NonValidTarget-C_COMPILER_VERSION-result.txt | 1 + .../NonValidTarget-C_COMPILER_VERSION-stderr.txt | 9 +++++++ .../NonValidTarget-C_COMPILER_VERSION.cmake | 8 +++++++ .../NonValidTarget-TARGET_POLICY-result.txt | 1 + .../NonValidTarget-TARGET_POLICY-stderr.txt | 9 +++++++ .../NonValidTarget-TARGET_POLICY.cmake | 8 +++++++ .../NonValidTarget-TARGET_PROPERTY-result.txt | 1 + .../NonValidTarget-TARGET_PROPERTY-stderr.txt | 11 +++++++++ .../NonValidTarget-TARGET_PROPERTY.cmake | 8 +++++++ .../GeneratorExpression/RunCMakeTest.cmake | 6 +++++ 20 files changed, 130 insertions(+), 14 deletions(-) create mode 100644 Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID-result.txt create mode 100644 Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID-stderr.txt create mode 100644 Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID.cmake create mode 100644 Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION-result.txt create mode 100644 Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION-stderr.txt create mode 100644 Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION.cmake create mode 100644 Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID-result.txt create mode 100644 Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID-stderr.txt create mode 100644 Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID.cmake create mode 100644 Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION-result.txt create mode 100644 Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION-stderr.txt create mode 100644 Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION.cmake create mode 100644 Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY-result.txt create mode 100644 Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY-stderr.txt create mode 100644 Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY.cmake create mode 100644 Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY-result.txt create mode 100644 Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY-stderr.txt create mode 100644 Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY.cmake diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx index 0b357f6..a15e3ff 100644 --- a/Source/cmGeneratorExpressionEvaluator.cxx +++ b/Source/cmGeneratorExpressionEvaluator.cxx @@ -457,8 +457,8 @@ static const struct CCompilerIdNode : public CompilerIdNode if (!context->HeadTarget) { reportError(context, content->GetOriginalExpression(), - "$ may only be used with targets. It may not " - "be used with add_custom_command."); + "$ may only be used with binary targets. It may " + "not be used with add_custom_command or add_custom_target."); return std::string(); } return this->EvaluateWithLanguage(parameters, context, content, @@ -479,8 +479,8 @@ static const struct CXXCompilerIdNode : public CompilerIdNode if (!context->HeadTarget) { reportError(context, content->GetOriginalExpression(), - "$ may only be used with targets. It may not " - "be used with add_custom_command."); + "$ may only be used with binary targets. It may " + "not be used with add_custom_command or add_custom_target."); return std::string(); } return this->EvaluateWithLanguage(parameters, context, content, @@ -541,8 +541,8 @@ static const struct CCompilerVersionNode : public CompilerVersionNode if (!context->HeadTarget) { reportError(context, content->GetOriginalExpression(), - "$ may only be used with targets. It may not " - "be used with add_custom_command."); + "$ may only be used with binary targets. It " + "may not be used with add_custom_command or add_custom_target."); return std::string(); } return this->EvaluateWithLanguage(parameters, context, content, @@ -563,8 +563,8 @@ static const struct CxxCompilerVersionNode : public CompilerVersionNode if (!context->HeadTarget) { reportError(context, content->GetOriginalExpression(), - "$ may only be used with targets. It may " - "not be used with add_custom_command."); + "$ may only be used with binary targets. It " + "may not be used with add_custom_command or add_custom_target."); return std::string(); } return this->EvaluateWithLanguage(parameters, context, content, @@ -893,10 +893,10 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode if (!target && parameters.size() == 1) { reportError(context, content->GetOriginalExpression(), - "$ may only be used with targets. It may not " - "be used with add_custom_command. Specify the target to read a " - "property from using the $ signature " - "instead."); + "$ may only be used with binary targets. " + "It may not be used with add_custom_command or add_custom_target. " + "Specify the target to read a property from using the " + "$ signature instead."); return std::string(); } @@ -1460,8 +1460,8 @@ static const struct TargetPolicyNode : public cmGeneratorExpressionNode if (!context->HeadTarget) { reportError(context, content->GetOriginalExpression(), - "$ may only be used with targets. It may not " - "be used with add_custom_command."); + "$ may only be used with binary targets. It " + "may not be used with add_custom_command or add_custom_target."); return std::string(); } diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID-result.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID-stderr.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID-stderr.txt new file mode 100644 index 0000000..dd7a183 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID-stderr.txt @@ -0,0 +1,9 @@ +CMake Error at NonValidTarget-CXX_COMPILER_ID.cmake:4 \(add_custom_command\): + Error evaluating generator expression: + + \$ + + \$ may only be used with binary targets. It may not be + used with add_custom_command or add_custom_target. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID.cmake b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID.cmake new file mode 100644 index 0000000..7dd38da --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_ID.cmake @@ -0,0 +1,8 @@ + +enable_language(CXX) + +add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp" + COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp" "${CMAKE_CURRENT_BINARY_DIR}/copied_file$.cpp" +) + +add_library(empty "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp") diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION-result.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION-stderr.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION-stderr.txt new file mode 100644 index 0000000..d4a064a --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION-stderr.txt @@ -0,0 +1,9 @@ +CMake Error at NonValidTarget-CXX_COMPILER_VERSION.cmake:4 \(add_custom_command\): + Error evaluating generator expression: + + \$ + + \$ may only be used with binary targets. It may not + be used with add_custom_command or add_custom_target. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION.cmake b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION.cmake new file mode 100644 index 0000000..1afb2b5 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-CXX_COMPILER_VERSION.cmake @@ -0,0 +1,8 @@ + +enable_language(CXX) + +add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp" + COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp" "${CMAKE_CURRENT_BINARY_DIR}/copied_file$.cpp" +) + +add_library(empty "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp") diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID-result.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID-stderr.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID-stderr.txt new file mode 100644 index 0000000..b8e53ed --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID-stderr.txt @@ -0,0 +1,9 @@ +CMake Error at NonValidTarget-C_COMPILER_ID.cmake:4 \(add_custom_command\): + Error evaluating generator expression: + + \$ + + \$ may only be used with binary targets. It may not be used + with add_custom_command or add_custom_target. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID.cmake b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID.cmake new file mode 100644 index 0000000..2d92ee3 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_ID.cmake @@ -0,0 +1,8 @@ + +enable_language(CXX) + +add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp" + COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp" "${CMAKE_CURRENT_BINARY_DIR}/copied_file$.cpp" +) + +add_library(empty "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp") diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION-result.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION-stderr.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION-stderr.txt new file mode 100644 index 0000000..551efe9 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION-stderr.txt @@ -0,0 +1,9 @@ +CMake Error at NonValidTarget-C_COMPILER_VERSION.cmake:4 \(add_custom_command\): + Error evaluating generator expression: + + \$ + + \$ may only be used with binary targets. It may not be + used with add_custom_command or add_custom_target. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION.cmake b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION.cmake new file mode 100644 index 0000000..9b8a531 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-C_COMPILER_VERSION.cmake @@ -0,0 +1,8 @@ + +enable_language(CXX) + +add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp" + COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp" "${CMAKE_CURRENT_BINARY_DIR}/copied_file$.cpp" +) + +add_library(empty "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp") diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY-result.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY-stderr.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY-stderr.txt new file mode 100644 index 0000000..0e87538 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY-stderr.txt @@ -0,0 +1,9 @@ +CMake Error at NonValidTarget-TARGET_POLICY.cmake:4 \(add_custom_command\): + Error evaluating generator expression: + + \$ + + \$ may only be used with binary targets. It may not be + used with add_custom_command or add_custom_target. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY.cmake b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY.cmake new file mode 100644 index 0000000..10b37b5 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_POLICY.cmake @@ -0,0 +1,8 @@ + +enable_language(CXX) + +add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp" + COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp" "${CMAKE_CURRENT_BINARY_DIR}/copied_file$.cpp" +) + +add_library(empty "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp") diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY-result.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY-stderr.txt b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY-stderr.txt new file mode 100644 index 0000000..08ad3c2 --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY-stderr.txt @@ -0,0 +1,11 @@ +CMake Error at NonValidTarget-TARGET_PROPERTY.cmake:4 \(add_custom_command\): + Error evaluating generator expression: + + \$ + + \$ may only be used with binary targets. It may not + be used with add_custom_command or add_custom_target. Specify the target + to read a property from using the \$ signature + instead. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY.cmake b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY.cmake new file mode 100644 index 0000000..64abc5f --- /dev/null +++ b/Tests/RunCMake/GeneratorExpression/NonValidTarget-TARGET_PROPERTY.cmake @@ -0,0 +1,8 @@ + +enable_language(CXX) + +add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp" + COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/empty.cpp" "${CMAKE_CURRENT_BINARY_DIR}/copied_file$.cpp" +) + +add_library(empty "${CMAKE_CURRENT_BINARY_DIR}/copied_file.cpp") diff --git a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake index f3f99ed..c8f3fdf 100644 --- a/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake +++ b/Tests/RunCMake/GeneratorExpression/RunCMakeTest.cmake @@ -10,3 +10,9 @@ run_cmake(BadTargetName) run_cmake(BadTargetTypeObject) run_cmake(BadInstallPrefix) run_cmake(CMP0044-WARN) +run_cmake(NonValidTarget-C_COMPILER_ID) +run_cmake(NonValidTarget-CXX_COMPILER_ID) +run_cmake(NonValidTarget-C_COMPILER_VERSION) +run_cmake(NonValidTarget-CXX_COMPILER_VERSION) +run_cmake(NonValidTarget-TARGET_PROPERTY) +run_cmake(NonValidTarget-TARGET_POLICY) -- cgit v0.12