From 2b7d59f3109483bfa45dc41e2a2f6a2f82addfec Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 17 Nov 2017 14:31:07 -0500 Subject: Genex: Enable COMPILE_LANGUAGE for file(GENERATE) with Visual Studio Issue: #17435 --- Source/cmGeneratorExpressionNode.cxx | 16 ++++++++++------ .../CompileDefinitions-stderr-VS.txt | 3 ++- .../COMPILE_LANGUAGE-genex/CompileOptions-stderr-VS.txt | 3 ++- .../IncludeDirectories-stderr-VS.txt | 3 ++- Tests/RunCMake/File_Generate/RunCMakeTest.cmake | 16 +++++++--------- 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 488bbfd..5068560 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -828,12 +828,16 @@ static const struct CompileLanguageNode : public cmGeneratorExpressionNode } std::string genName = gg->GetName(); if (genName.find("Visual Studio") != std::string::npos) { - reportError(context, content->GetOriginalExpression(), - "$ may not be used with Visual Studio " - "generators."); - return std::string(); - } - if (genName.find("Xcode") != std::string::npos) { + if (dagChecker && (dagChecker->EvaluatingCompileDefinitions() || + dagChecker->EvaluatingCompileOptions() || + dagChecker->EvaluatingIncludeDirectories())) { + reportError( + context, content->GetOriginalExpression(), + "$ may only be used for file(GENERATE) " + "with the Visual Studio generator."); + return std::string(); + } + } else if (genName.find("Xcode") != std::string::npos) { if (dagChecker && (dagChecker->EvaluatingCompileDefinitions() || dagChecker->EvaluatingIncludeDirectories())) { reportError( diff --git a/Tests/RunCMake/COMPILE_LANGUAGE-genex/CompileDefinitions-stderr-VS.txt b/Tests/RunCMake/COMPILE_LANGUAGE-genex/CompileDefinitions-stderr-VS.txt index 73b66ac..830d5f3 100644 --- a/Tests/RunCMake/COMPILE_LANGUAGE-genex/CompileDefinitions-stderr-VS.txt +++ b/Tests/RunCMake/COMPILE_LANGUAGE-genex/CompileDefinitions-stderr-VS.txt @@ -3,6 +3,7 @@ CMake Error at CompileDefinitions.cmake:5 \(target_compile_definitions\): \$ - \$ may not be used with Visual Studio generators. + \$ may only be used for file\(GENERATE\) with the Visual + Studio generator. Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/COMPILE_LANGUAGE-genex/CompileOptions-stderr-VS.txt b/Tests/RunCMake/COMPILE_LANGUAGE-genex/CompileOptions-stderr-VS.txt index e9e8e9f..66b45c0 100644 --- a/Tests/RunCMake/COMPILE_LANGUAGE-genex/CompileOptions-stderr-VS.txt +++ b/Tests/RunCMake/COMPILE_LANGUAGE-genex/CompileOptions-stderr-VS.txt @@ -3,6 +3,7 @@ CMake Error at CompileOptions.cmake:5 \(target_compile_options\): \$ - \$ may not be used with Visual Studio generators. + \$ may only be used for file\(GENERATE\) with the Visual + Studio generator. Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/COMPILE_LANGUAGE-genex/IncludeDirectories-stderr-VS.txt b/Tests/RunCMake/COMPILE_LANGUAGE-genex/IncludeDirectories-stderr-VS.txt index ec15068..06900bc 100644 --- a/Tests/RunCMake/COMPILE_LANGUAGE-genex/IncludeDirectories-stderr-VS.txt +++ b/Tests/RunCMake/COMPILE_LANGUAGE-genex/IncludeDirectories-stderr-VS.txt @@ -3,6 +3,7 @@ CMake Error at IncludeDirectories.cmake:5 \(target_include_directories\): \$ - \$ may not be used with Visual Studio generators. + \$ may only be used for file\(GENERATE\) with the Visual + Studio generator. Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/File_Generate/RunCMakeTest.cmake b/Tests/RunCMake/File_Generate/RunCMakeTest.cmake index b660463..616e210 100644 --- a/Tests/RunCMake/File_Generate/RunCMakeTest.cmake +++ b/Tests/RunCMake/File_Generate/RunCMakeTest.cmake @@ -21,15 +21,13 @@ if (NOT file_contents MATCHES "generated.cpp.rule") message(SEND_ERROR "Rule file not in target sources! ${file_contents}") endif() -if (NOT RunCMake_GENERATOR MATCHES "Visual Studio") - run_cmake(COMPILE_LANGUAGE-genex) - foreach(l CXX C) - file(READ "${RunCMake_BINARY_DIR}/COMPILE_LANGUAGE-genex-build/opts-${l}.txt" l_defs) - if (NOT l_defs STREQUAL "LANG_IS_${l}\n") - message(FATAL_ERROR "File content does not match: ${l_defs}") - endif() - endforeach() -endif() +run_cmake(COMPILE_LANGUAGE-genex) +foreach(l CXX C) + file(READ "${RunCMake_BINARY_DIR}/COMPILE_LANGUAGE-genex-build/opts-${l}.txt" l_defs) + if (NOT l_defs STREQUAL "LANG_IS_${l}\n") + message(FATAL_ERROR "File content does not match: ${l_defs}") + endif() +endforeach() set(timeformat "%Y%j%H%M%S") -- cgit v0.12