diff options
33 files changed, 323 insertions, 139 deletions
diff --git a/Help/manual/cmake-generator-expressions.7.rst b/Help/manual/cmake-generator-expressions.7.rst index f2e6597..c0449fb 100644 --- a/Help/manual/cmake-generator-expressions.7.rst +++ b/Help/manual/cmake-generator-expressions.7.rst @@ -110,24 +110,30 @@ Variable Queries The mapping in :prop_tgt:`MAP_IMPORTED_CONFIG_<CONFIG>` is also considered by this expression when it is evaluated on a property on an :prop_tgt:`IMPORTED` target. -``$<PLATFORM_ID:platform_id>`` - ``1`` if the CMake's platform id matches ``platform_id`` - otherwise ``0``. +``$<PLATFORM_ID:platform_ids>`` + where ``platform_ids`` is a comma-separated list. + ``1`` if the CMake's platform id matches any one of the entries in + ``platform_ids``, otherwise ``0``. See also the :variable:`CMAKE_SYSTEM_NAME` variable. -``$<C_COMPILER_ID:compiler_id>`` - ``1`` if the CMake's compiler id of the C compiler matches ``compiler_id``, - otherwise ``0``. +``$<C_COMPILER_ID:compiler_ids>`` + where ``compiler_ids`` is a comma-separated list. + ``1`` if the CMake's compiler id of the C compiler matches any one + of the entries in ``compiler_ids``, otherwise ``0``. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable. -``$<CXX_COMPILER_ID:compiler_id>`` - ``1`` if the CMake's compiler id of the CXX compiler matches ``compiler_id``, - otherwise ``0``. -``$<CUDA_COMPILER_ID:compiler_id>`` - ``1`` if the CMake's compiler id of the CUDA compiler matches ``compiler_id``, - otherwise ``0``. +``$<CXX_COMPILER_ID:compiler_ids>`` + where ``compiler_ids`` is a comma-separated list. + ``1`` if the CMake's compiler id of the CXX compiler matches any one + of the entries in ``compiler_ids``, otherwise ``0``. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable. -``$<Fortran_COMPILER_ID:compiler_id>`` - ``1`` if the CMake's compiler id of the Fortran compiler matches ``compiler_id``, - otherwise ``0``. +``$<CUDA_COMPILER_ID:compiler_ids>`` + where ``compiler_ids`` is a comma-separated list. + ``1`` if the CMake's compiler id of the CUDA compiler matches any one + of the entries in ``compiler_ids``, otherwise ``0``. + See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable. +``$<Fortran_COMPILER_ID:compiler_ids>`` + where ``compiler_ids`` is a comma-separated list. + ``1`` if the CMake's compiler id of the Fortran compiler matches any one + of the entries in ``compiler_ids``, otherwise ``0``. See also the :variable:`CMAKE_<LANG>_COMPILER_ID` variable. ``$<C_COMPILER_VERSION:version>`` ``1`` if the version of the C compiler matches ``version``, otherwise ``0``. @@ -158,20 +164,20 @@ Variable Queries .. _`Boolean COMPILE_LANGUAGE Generator Expression`: -``$<COMPILE_LANG_AND_ID:language,compiler_id>`` +``$<COMPILE_LANG_AND_ID:language,compiler_ids>`` ``1`` when the language used for compilation unit matches ``language`` and - the CMake's compiler id of the language compiler matches ``compiler_id``, - otherwise ``0``. This expression is a short form for the combination of - ``$<COMPILE_LANGUAGE:language>`` and ``$<LANG_COMPILER_ID:compiler_id>``. - This expression may be used to specify compile options, - compile definitions, and include directories for source files of a + the CMake's compiler id of the language compiler matches any one of the + entries in ``compiler_ids``, otherwise ``0``. This expression is a short form + for the combination of ``$<COMPILE_LANGUAGE:language>`` and + ``$<LANG_COMPILER_ID:compiler_ids>``. This expression may be used to specify + compile options, compile definitions, and include directories for source files of a particular language and compiler combination in a target. For example: .. code-block:: cmake add_executable(myapp main.cpp foo.c bar.cpp zot.cu) target_compile_definitions(myapp - PRIVATE $<$<COMPILE_LANG_AND_ID:CXX,Clang>:COMPILING_CXX_WITH_CLANG> + PRIVATE $<$<COMPILE_LANG_AND_ID:CXX,AppleClang,Clang>:COMPILING_CXX_WITH_CLANG> $<$<COMPILE_LANG_AND_ID:CXX,Intel>:COMPILING_CXX_WITH_INTEL> $<$<COMPILE_LANG_AND_ID:C,Clang>:COMPILING_C_WITH_CLANG> ) @@ -194,10 +200,10 @@ Variable Queries $<$<AND:$<COMPILE_LANGUAGE:C>,$<C_COMPILER_ID:Clang>>:COMPILING_C_WITH_CLANG> ) -``$<COMPILE_LANGUAGE:language>`` - ``1`` when the language used for compilation unit matches ``language``, - otherwise ``0``. This expression may be used to specify compile options, - compile definitions, and include directories for source files of a +``$<COMPILE_LANGUAGE:languages>`` + ``1`` when the language used for compilation unit matches any of the entries + in ``languages``, otherwise ``0``. This expression may be used to specify + compile options, compile definitions, and include directories for source files of a particular language in a target. For example: .. code-block:: cmake @@ -211,7 +217,7 @@ Variable Queries $<$<COMPILE_LANGUAGE:CUDA>:COMPILING_CUDA> ) target_include_directories(myapp - PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/opt/foo/cxx_headers> + PRIVATE $<$<COMPILE_LANGUAGE:CXX,CUDA>:/opt/foo/headers> ) This specifies the use of the ``-fno-exceptions`` compile option, diff --git a/Help/release/dev/genex-comma-separated.rst b/Help/release/dev/genex-comma-separated.rst new file mode 100644 index 0000000..f27f781 --- /dev/null +++ b/Help/release/dev/genex-comma-separated.rst @@ -0,0 +1,8 @@ +genex-comma-separated +--------------------- + +* The :manual:`generator expressions <cmake-generator-expressions(7)>` + ``C_COMPILER_ID``, ``CXX_COMPILER_ID``, ``CUDA_COMPILER_ID``, + ``Fortran_COMPILER_ID``, ``COMPILE_LANGUAGE``, ``COMPILE_LANG_AND_ID``, and + ``PLATFORM_ID`` learned to support matching one value from a comma-separated + list. diff --git a/Modules/CheckLanguage.cmake b/Modules/CheckLanguage.cmake index d096849..a1a3a7a 100644 --- a/Modules/CheckLanguage.cmake +++ b/Modules/CheckLanguage.cmake @@ -18,7 +18,9 @@ such as ``Fortran``. If :variable:`CMAKE_<LANG>_COMPILER` is already defined the check does nothing. Otherwise it tries enabling the language in a test project. The result is cached in :variable:`CMAKE_<LANG>_COMPILER` as the compiler that was found, or ``NOTFOUND`` if the language cannot be -enabled. +enabled. For CUDA which can have an explicit host compiler, the cache +:variable:`CMAKE_CUDA_HOST_COMPILER` variable will be set if it was required +for compilation. Example: @@ -39,13 +41,23 @@ macro(check_language lang) set(_desc "Looking for a ${lang} compiler") message(STATUS ${_desc}) file(REMOVE_RECURSE ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang}) - file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang}/CMakeLists.txt" + + set(extra_compiler_variables) + if(lang STREQUAL CUDA) + set(extra_compiler_variables "set(CMAKE_CUDA_HOST_COMPILER \\\"\${CMAKE_CUDA_HOST_COMPILER}\\\")") + endif() + + set(content "cmake_minimum_required(VERSION ${CMAKE_VERSION}) project(Check${lang} ${lang}) file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\" \"set(CMAKE_${lang}_COMPILER \\\"\${CMAKE_${lang}_COMPILER}\\\")\\n\" - ) -") + \"${extra_compiler_variables}\\n\" + )" + ) + + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Check${lang}/CMakeLists.txt" + "${content}") if(CMAKE_GENERATOR_INSTANCE) set(_D_CMAKE_GENERATOR_INSTANCE "-DCMAKE_GENERATOR_INSTANCE:INTERNAL=${CMAKE_GENERATOR_INSTANCE}") else() @@ -75,5 +87,12 @@ file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\" message(STATUS "${_desc} - ${CMAKE_${lang}_COMPILER}") set(CMAKE_${lang}_COMPILER "${CMAKE_${lang}_COMPILER}" CACHE FILEPATH "${lang} compiler") mark_as_advanced(CMAKE_${lang}_COMPILER) + + if(CMAKE_${lang}_HOST_COMPILER) + message(STATUS "Looking for a ${lang} host compiler - ${CMAKE_${lang}_HOST_COMPILER}") + set(CMAKE_${lang}_HOST_COMPILER "${CMAKE_${lang}_HOST_COMPILER}" CACHE FILEPATH "${lang} host compiler") + mark_as_advanced(CMAKE_${lang}_HOST_COMPILER) + endif() + endif() endmacro() diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 29543b8..aeccf8e 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -1,5 +1,5 @@ # CMake version number components. set(CMake_VERSION_MAJOR 3) set(CMake_VERSION_MINOR 14) -set(CMake_VERSION_PATCH 20190603) +set(CMake_VERSION_PATCH 20190604) #set(CMake_VERSION_RC 1) diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx index 268de6f..7442018 100644 --- a/Source/cmGeneratorExpressionEvaluator.cxx +++ b/Source/cmGeneratorExpressionEvaluator.cxx @@ -166,9 +166,13 @@ std::string GeneratorExpressionContent::EvaluateParameters( reportError(context, this->GetOriginalExpression(), "$<" + identifier + "> expression requires at least one parameter."); - } - if (numExpected == cmGeneratorExpressionNode::OneOrZeroParameters && - parameters.size() > 1) { + } else if (numExpected == cmGeneratorExpressionNode::TwoOrMoreParameters && + parameters.size() < 2) { + reportError(context, this->GetOriginalExpression(), + "$<" + identifier + + "> expression requires at least two parameters."); + } else if (numExpected == cmGeneratorExpressionNode::OneOrZeroParameters && + parameters.size() > 1) { reportError(context, this->GetOriginalExpression(), "$<" + identifier + "> expression requires one or zero parameters."); diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 68ef170..a60c75c 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -632,7 +632,7 @@ struct CompilerIdNode : public cmGeneratorExpressionNode { } - int NumExpectedParameters() const override { return OneOrZeroParameters; } + int NumExpectedParameters() const override { return ZeroOrMoreParameters; } std::string Evaluate( const std::vector<std::string>& parameters, @@ -664,36 +664,39 @@ struct CompilerIdNode : public cmGeneratorExpressionNode if (parameters.empty()) { return compilerId; } - static cmsys::RegularExpression compilerIdValidator("^[A-Za-z0-9_]*$"); - if (!compilerIdValidator.find(parameters.front())) { - reportError(context, content->GetOriginalExpression(), - "Expression syntax not recognized."); - return std::string(); - } if (compilerId.empty()) { return parameters.front().empty() ? "1" : "0"; } + static cmsys::RegularExpression compilerIdValidator("^[A-Za-z0-9_]*$"); - if (strcmp(parameters.front().c_str(), compilerId.c_str()) == 0) { - return "1"; - } + for (auto& param : parameters) { - if (cmsysString_strcasecmp(parameters.front().c_str(), - compilerId.c_str()) == 0) { - switch (context->LG->GetPolicyStatus(cmPolicies::CMP0044)) { - case cmPolicies::WARN: { - std::ostringstream e; - e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0044); - context->LG->GetCMakeInstance()->IssueMessage( - MessageType::AUTHOR_WARNING, e.str(), context->Backtrace); - CM_FALLTHROUGH; + if (!compilerIdValidator.find(param)) { + reportError(context, content->GetOriginalExpression(), + "Expression syntax not recognized."); + return std::string(); + } + + if (strcmp(param.c_str(), compilerId.c_str()) == 0) { + return "1"; + } + + if (cmsysString_strcasecmp(param.c_str(), compilerId.c_str()) == 0) { + switch (context->LG->GetPolicyStatus(cmPolicies::CMP0044)) { + case cmPolicies::WARN: { + std::ostringstream e; + e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0044); + context->LG->GetCMakeInstance()->IssueMessage( + MessageType::AUTHOR_WARNING, e.str(), context->Backtrace); + CM_FALLTHROUGH; + } + case cmPolicies::OLD: + return "1"; + case cmPolicies::NEW: + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::REQUIRED_IF_USED: + break; } - case cmPolicies::OLD: - return "1"; - case cmPolicies::NEW: - case cmPolicies::REQUIRED_ALWAYS: - case cmPolicies::REQUIRED_IF_USED: - break; } } return "0"; @@ -773,7 +776,7 @@ struct PlatformIdNode : public cmGeneratorExpressionNode { PlatformIdNode() {} // NOLINT(modernize-use-equals-default) - int NumExpectedParameters() const override { return OneOrZeroParameters; } + int NumExpectedParameters() const override { return ZeroOrMoreParameters; } std::string Evaluate( const std::vector<std::string>& parameters, @@ -791,8 +794,10 @@ struct PlatformIdNode : public cmGeneratorExpressionNode return parameters.front().empty() ? "1" : "0"; } - if (parameters.front() == platformId) { - return "1"; + for (auto& param : parameters) { + if (param == platformId) { + return "1"; + } } return "0"; } @@ -946,7 +951,7 @@ static const struct CompileLanguageNode : public cmGeneratorExpressionNode { CompileLanguageNode() {} // NOLINT(modernize-use-equals-default) - int NumExpectedParameters() const override { return OneOrZeroParameters; } + int NumExpectedParameters() const override { return ZeroOrMoreParameters; } std::string Evaluate( const std::vector<std::string>& parameters, @@ -977,7 +982,13 @@ static const struct CompileLanguageNode : public cmGeneratorExpressionNode if (parameters.empty()) { return context->Language; } - return context->Language == parameters.front() ? "1" : "0"; + + for (auto& param : parameters) { + if (context->Language == param) { + return "1"; + } + } + return "0"; } } languageNode; @@ -985,7 +996,7 @@ static const struct CompileLanguageAndIdNode : public cmGeneratorExpressionNode { CompileLanguageAndIdNode() {} // NOLINT(modernize-use-equals-default) - int NumExpectedParameters() const override { return 2; } + int NumExpectedParameters() const override { return TwoOrMoreParameters; } std::string Evaluate( const std::vector<std::string>& parameters, @@ -1018,7 +1029,8 @@ static const struct CompileLanguageAndIdNode : public cmGeneratorExpressionNode const std::string& lang = context->Language; if (lang == parameters.front()) { - std::vector<std::string> idParameter = { parameters[1] }; + std::vector<std::string> idParameter((parameters.cbegin() + 1), + parameters.cend()); return CompilerIdNode{ lang.c_str() }.EvaluateWithLanguage( idParameter, context, content, dagChecker, lang); } diff --git a/Source/cmGeneratorExpressionNode.h b/Source/cmGeneratorExpressionNode.h index 3dbfc6e..7a36924 100644 --- a/Source/cmGeneratorExpressionNode.h +++ b/Source/cmGeneratorExpressionNode.h @@ -20,7 +20,9 @@ struct cmGeneratorExpressionNode { DynamicParameters = 0, OneOrMoreParameters = -1, - OneOrZeroParameters = -2 + TwoOrMoreParameters = -2, + ZeroOrMoreParameters = -3, + OneOrZeroParameters = -4 }; virtual ~cmGeneratorExpressionNode() = default; diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 26886f5..df0f33f 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -331,6 +331,37 @@ bool cmGlobalGenerator::CheckTargetsForMissingSources() const return failed; } +bool cmGlobalGenerator::CheckTargetsForType() const +{ + if (!this->GetLanguageEnabled("Swift")) { + return false; + } + bool failed = false; + for (cmLocalGenerator* generator : this->LocalGenerators) { + for (cmGeneratorTarget* target : generator->GetGeneratorTargets()) { + std::vector<std::string> configs; + target->Makefile->GetConfigurations(configs); + if (configs.empty()) { + configs.emplace_back(); + } + + for (std::string const& config : configs) { + if (target->GetLinkerLanguage(config) == "Swift") { + if (target->GetPropertyAsBool("WIN32_EXECUTABLE")) { + this->GetCMakeInstance()->IssueMessage( + MessageType::FATAL_ERROR, + "WIN32_EXECUTABLE property is not supported on Swift " + "executables", + target->GetBacktrace()); + failed = true; + } + } + } + } + } + return failed; +} + bool cmGlobalGenerator::IsExportedTargetsFile( const std::string& filename) const { @@ -1414,6 +1445,10 @@ bool cmGlobalGenerator::Compute() return false; } + if (this->CheckTargetsForType()) { + return false; + } + for (cmLocalGenerator* localGen : this->LocalGenerators) { localGen->ComputeHomeRelativeOutputPath(); } diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index dcd8c5f..db96489 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -609,6 +609,7 @@ private: virtual void ForceLinkerLanguages(); bool CheckTargetsForMissingSources() const; + bool CheckTargetsForType() const; void CreateLocalGenerators(); diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index f99caed..df0d00c 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -192,12 +192,9 @@ bool cmListFileParser::ParseFunction(const char* name, long line) } // Arguments. - unsigned long lastLine; unsigned long parenDepth = 0; this->Separation = SeparationOkay; - while ( - (static_cast<void>(lastLine = cmListFileLexer_GetCurrentLine(this->Lexer)), - token = cmListFileLexer_Scan(this->Lexer))) { + while ((token = cmListFileLexer_Scan(this->Lexer))) { if (token->type == cmListFileLexer_Token_Space || token->type == cmListFileLexer_Token_Newline) { this->Separation = SeparationOkay; @@ -252,7 +249,7 @@ bool cmListFileParser::ParseFunction(const char* name, long line) std::ostringstream error; cmListFileContext lfc; lfc.FilePath = this->FileName; - lfc.Line = lastLine; + lfc.Line = line; cmListFileBacktrace lfbt = this->Backtrace; lfbt = lfbt.Push(lfc); error << "Parse error. Function missing ending \")\". " diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 87d2232..fe5c8af 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1169,30 +1169,34 @@ void cmLocalGenerator::GetTargetFlags( libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS"; CM_FALLTHROUGH; case cmStateEnums::SHARED_LIBRARY: { - linkFlags = this->Makefile->GetSafeDefinition(libraryLinkVariable); - linkFlags += " "; - if (!buildType.empty()) { - std::string build = libraryLinkVariable; - build += "_"; - build += buildType; - linkFlags += this->Makefile->GetSafeDefinition(build); + if (linkLanguage != "Swift") { + linkFlags = this->Makefile->GetSafeDefinition(libraryLinkVariable); linkFlags += " "; - } - if (this->Makefile->IsOn("WIN32") && - !(this->Makefile->IsOn("CYGWIN") || this->Makefile->IsOn("MINGW"))) { - std::vector<cmSourceFile*> sources; - target->GetSourceFiles(sources, buildType); - std::string defFlag = - this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG"); - for (cmSourceFile* sf : sources) { - if (sf->GetExtension() == "def") { - linkFlags += defFlag; - linkFlags += this->ConvertToOutputFormat( - cmSystemTools::CollapseFullPath(sf->GetFullPath()), SHELL); - linkFlags += " "; + if (!buildType.empty()) { + std::string build = libraryLinkVariable; + build += "_"; + build += buildType; + linkFlags += this->Makefile->GetSafeDefinition(build); + linkFlags += " "; + } + if (this->Makefile->IsOn("WIN32") && + !(this->Makefile->IsOn("CYGWIN") || + this->Makefile->IsOn("MINGW"))) { + std::vector<cmSourceFile*> sources; + target->GetSourceFiles(sources, buildType); + std::string defFlag = + this->Makefile->GetSafeDefinition("CMAKE_LINK_DEF_FILE_FLAG"); + for (cmSourceFile* sf : sources) { + if (sf->GetExtension() == "def") { + linkFlags += defFlag; + linkFlags += this->ConvertToOutputFormat( + cmSystemTools::CollapseFullPath(sf->GetFullPath()), SHELL); + linkFlags += " "; + } } } } + const char* targetLinkFlags = target->GetProperty("LINK_FLAGS"); if (targetLinkFlags) { linkFlags += targetLinkFlags; @@ -1207,6 +1211,7 @@ void cmLocalGenerator::GetTargetFlags( linkFlags += " "; } } + std::vector<std::string> opts; target->GetLinkOptions(opts, config, linkLanguage); // LINK_OPTIONS are escaped. @@ -1217,25 +1222,49 @@ void cmLocalGenerator::GetTargetFlags( } } break; case cmStateEnums::EXECUTABLE: { - linkFlags += this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS"); - linkFlags += " "; - if (!buildType.empty()) { - std::string build = "CMAKE_EXE_LINKER_FLAGS_"; - build += buildType; - linkFlags += this->Makefile->GetSafeDefinition(build); + if (linkLanguage != "Swift") { + linkFlags += + this->Makefile->GetSafeDefinition("CMAKE_EXE_LINKER_FLAGS"); linkFlags += " "; + if (!buildType.empty()) { + std::string build = "CMAKE_EXE_LINKER_FLAGS_"; + build += buildType; + linkFlags += this->Makefile->GetSafeDefinition(build); + linkFlags += " "; + } + if (linkLanguage.empty()) { + cmSystemTools::Error( + "CMake can not determine linker language for target: " + + target->GetName()); + return; + } + + if (target->GetPropertyAsBool("WIN32_EXECUTABLE")) { + linkFlags += + this->Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE"); + linkFlags += " "; + } else { + linkFlags += + this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE"); + linkFlags += " "; + } + + if (target->IsExecutableWithExports()) { + std::string exportFlagVar = "CMAKE_EXE_EXPORTS_"; + exportFlagVar += linkLanguage; + exportFlagVar += "_FLAG"; + + linkFlags += this->Makefile->GetSafeDefinition(exportFlagVar); + linkFlags += " "; + } } - if (linkLanguage.empty()) { - cmSystemTools::Error( - "CMake can not determine linker language for target: " + - target->GetName()); - return; - } + this->AddLanguageFlagsForLinking(flags, target, linkLanguage, buildType); if (pcli) { this->OutputLinkLibraries(pcli, linkLineComputer, linkLibs, frameworkPath, linkPath); } + if (cmSystemTools::IsOn( this->Makefile->GetDefinition("BUILD_SHARED_LIBS"))) { std::string sFlagVar = std::string("CMAKE_SHARED_BUILD_") + @@ -1243,23 +1272,6 @@ void cmLocalGenerator::GetTargetFlags( linkFlags += this->Makefile->GetSafeDefinition(sFlagVar); linkFlags += " "; } - if (target->GetPropertyAsBool("WIN32_EXECUTABLE")) { - linkFlags += - this->Makefile->GetSafeDefinition("CMAKE_CREATE_WIN32_EXE"); - linkFlags += " "; - } else { - linkFlags += - this->Makefile->GetSafeDefinition("CMAKE_CREATE_CONSOLE_EXE"); - linkFlags += " "; - } - if (target->IsExecutableWithExports()) { - std::string exportFlagVar = "CMAKE_EXE_EXPORTS_"; - exportFlagVar += linkLanguage; - exportFlagVar += "_FLAG"; - - linkFlags += this->Makefile->GetSafeDefinition(exportFlagVar); - linkFlags += " "; - } std::string cmp0065Flags = this->GetLinkLibsCMP0065(linkLanguage, *target); @@ -1282,6 +1294,7 @@ void cmLocalGenerator::GetTargetFlags( linkFlags += " "; } } + std::vector<std::string> opts; target->GetLinkOptions(opts, config, linkLanguage); // LINK_OPTIONS are escaped. @@ -1914,7 +1927,9 @@ static void AddVisibilityCompileOption(std::string& flags, strcmp(prop, "protected") != 0 && strcmp(prop, "internal") != 0) { std::ostringstream e; e << "Target " << target->GetName() << " uses unsupported value \"" << prop - << "\" for " << flagDefine << "."; + << "\" for " << flagDefine << "." + << " The supported values are: default, hidden, protected, and " + "internal."; cmSystemTools::Error(e.str()); return; } diff --git a/Tests/CMakeCommands/target_compile_definitions/CMakeLists.txt b/Tests/CMakeCommands/target_compile_definitions/CMakeLists.txt index 7dc7995..a5bc1e1 100644 --- a/Tests/CMakeCommands/target_compile_definitions/CMakeLists.txt +++ b/Tests/CMakeCommands/target_compile_definitions/CMakeLists.txt @@ -34,6 +34,7 @@ target_compile_definitions(consumer CONSUMER_LANG_$<COMPILE_LANGUAGE> LANG_IS_CXX=$<COMPILE_LANGUAGE:CXX> LANG_IS_C=$<COMPILE_LANGUAGE:C> + LANG_IS_C_OR_CXX=$<COMPILE_LANGUAGE:C,CXX> ) if(CMAKE_GENERATOR MATCHES "Visual Studio|Xcode") target_compile_definitions(consumer diff --git a/Tests/CMakeCommands/target_compile_definitions/consumer.c b/Tests/CMakeCommands/target_compile_definitions/consumer.c index bacd4c4..bb65e01 100644 --- a/Tests/CMakeCommands/target_compile_definitions/consumer.c +++ b/Tests/CMakeCommands/target_compile_definitions/consumer.c @@ -35,6 +35,10 @@ # endif #endif +#if !LANG_IS_C_OR_CXX +# error Expected LANG_IS_C_OR_CXX +#endif + void consumer_c() { } diff --git a/Tests/CMakeCommands/target_compile_options/CMakeLists.txt b/Tests/CMakeCommands/target_compile_options/CMakeLists.txt index a24cd53..a7055b1 100644 --- a/Tests/CMakeCommands/target_compile_options/CMakeLists.txt +++ b/Tests/CMakeCommands/target_compile_options/CMakeLists.txt @@ -7,9 +7,11 @@ add_executable(target_compile_options "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp" ) target_compile_options(target_compile_options - PRIVATE $<$<CXX_COMPILER_ID:GNU>:-DMY_PRIVATE_DEFINE> + PRIVATE $<$<CXX_COMPILER_ID:AppleClang,Clang,GNU>:-DMY_PRIVATE_DEFINE> PUBLIC $<$<COMPILE_LANG_AND_ID:CXX,GNU>:-DMY_PUBLIC_DEFINE> + PUBLIC $<$<COMPILE_LANG_AND_ID:CXX,GNU,Clang,AppleClang>:-DMY_MUTLI_COMP_PUBLIC_DEFINE> INTERFACE $<$<CXX_COMPILER_ID:GNU>:-DMY_INTERFACE_DEFINE> + INTERFACE $<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-DMY_MULTI_COMP_INTERFACE_DEFINE> ) if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") @@ -17,6 +19,11 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") PRIVATE "DO_GNU_TESTS" ) +elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + target_compile_definitions(target_compile_options + PRIVATE + "DO_CLANG_TESTS" + ) endif() add_executable(consumer @@ -40,7 +47,7 @@ if(CMAKE_GENERATOR MATCHES "Visual Studio") endif() target_compile_options(consumer - PRIVATE $<$<CXX_COMPILER_ID:GNU>:$<TARGET_PROPERTY:target_compile_options,INTERFACE_COMPILE_OPTIONS>> + PRIVATE $<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:$<TARGET_PROPERTY:target_compile_options,INTERFACE_COMPILE_OPTIONS>> ) if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") @@ -48,6 +55,11 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") PRIVATE "DO_GNU_TESTS" ) +elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + target_compile_definitions(consumer + PRIVATE + "DO_CLANG_TESTS" + ) endif() # Test no items diff --git a/Tests/CMakeCommands/target_compile_options/consumer.cpp b/Tests/CMakeCommands/target_compile_options/consumer.cpp index fe79eb5..78928b4 100644 --- a/Tests/CMakeCommands/target_compile_options/consumer.cpp +++ b/Tests/CMakeCommands/target_compile_options/consumer.cpp @@ -13,6 +13,30 @@ # error Expected MY_INTERFACE_DEFINE # endif +# ifndef MY_MULTI_COMP_INTERFACE_DEFINE +# error Expected MY_MULTI_COMP_INTERFACE_DEFINE +# endif + +# ifndef MY_MUTLI_COMP_PUBLIC_DEFINE +# error Expected MY_MUTLI_COMP_PUBLIC_DEFINE +# endif + +#endif + +#ifdef DO_CLANG_TESTS + +# ifdef MY_PRIVATE_DEFINE +# error Unexpected MY_PRIVATE_DEFINE +# endif + +# ifndef MY_MULTI_COMP_INTERFACE_DEFINE +# error Expected MY_MULTI_COMP_INTERFACE_DEFINE +# endif + +# ifndef MY_MUTLI_COMP_PUBLIC_DEFINE +# error Expected MY_MUTLI_COMP_PUBLIC_DEFINE +# endif + #endif #ifndef CONSUMER_LANG_CXX diff --git a/Tests/CMakeCommands/target_compile_options/main.cpp b/Tests/CMakeCommands/target_compile_options/main.cpp index 829a25e..7608400 100644 --- a/Tests/CMakeCommands/target_compile_options/main.cpp +++ b/Tests/CMakeCommands/target_compile_options/main.cpp @@ -9,12 +9,32 @@ # error Expected MY_PUBLIC_DEFINE # endif +# ifndef MY_MUTLI_COMP_PUBLIC_DEFINE +# error Expected MY_MUTLI_COMP_PUBLIC_DEFINE +# endif + # ifdef MY_INTERFACE_DEFINE # error Unexpected MY_INTERFACE_DEFINE # endif #endif +#ifdef DO_CLANG_TESTS + +# ifndef MY_PRIVATE_DEFINE +# error Expected MY_PRIVATE_DEFINE +# endif + +# ifdef MY_PUBLIC_DEFINE +# error Unexpected MY_PUBLIC_DEFINE +# endif + +# ifndef MY_MUTLI_COMP_PUBLIC_DEFINE +# error Expected MY_MUTLI_COMP_PUBLIC_DEFINE +# endif + +#endif + int main() { return 0; diff --git a/Tests/CMakeOnly/CheckLanguage/CMakeLists.txt b/Tests/CMakeOnly/CheckLanguage/CMakeLists.txt index f5336dc..ca4becb 100644 --- a/Tests/CMakeOnly/CheckLanguage/CMakeLists.txt +++ b/Tests/CMakeOnly/CheckLanguage/CMakeLists.txt @@ -7,7 +7,8 @@ set(expect_C 1) set(expect_CXX 1) unset(expect_Fortran) set(expect_NoSuchLanguage 0) -foreach(lang C CXX Fortran NoSuchLanguage) + +foreach(lang C CXX Fortran CUDA NoSuchLanguage) check_language(${lang}) if(NOT DEFINED CMAKE_${lang}_COMPILER) message(FATAL_ERROR "check_language(${lang}) did not set result") diff --git a/Tests/GeneratorExpression/CMakeLists.txt b/Tests/GeneratorExpression/CMakeLists.txt index 5ba0dc0..3ff2b85 100644 --- a/Tests/GeneratorExpression/CMakeLists.txt +++ b/Tests/GeneratorExpression/CMakeLists.txt @@ -220,6 +220,7 @@ add_custom_target(check-part3 ALL -Dtest_early_termination_2=$<$<1:>:, -Dsystem_name=${CMAKE_HOST_SYSTEM_NAME} -Dtest_platform_id=$<PLATFORM_ID> + -Dtest_platform_id_supported=$<PLATFORM_ID:Linux,Windows,Darwin> -Dtest_platform_id_Linux=$<PLATFORM_ID:Linux> -Dtest_platform_id_Windows=$<PLATFORM_ID:Windows> -Dtest_platform_id_Darwin=$<PLATFORM_ID:Darwin> diff --git a/Tests/GeneratorExpression/check-part3.cmake b/Tests/GeneratorExpression/check-part3.cmake index 9014406..4fb7308 100644 --- a/Tests/GeneratorExpression/check-part3.cmake +++ b/Tests/GeneratorExpression/check-part3.cmake @@ -28,11 +28,16 @@ check(test_early_termination_2 "$<:,") check(test_platform_id "${system_name}") foreach(system Linux Windows Darwin) if(system_name STREQUAL system) + check(test_platform_id_supported 1) check(test_platform_id_${system} 1) + set(platform_supported 1) else() check(test_platform_id_${system} 0) endif() endforeach() +if(NOT platform_supported) + check(test_platform_id_supported 0) +endif() check(lower_case "mi,xed") check(upper_case "MIX,ED") check(make_c_identifier "_4f_oo__bar__") diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index cee996c..7798b62 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -68,6 +68,9 @@ run_cmake_command(cache-empty-entry ${CMAKE_COMMAND} --build ${RunCMake_SOURCE_DIR}/cache-empty-entry/) function(run_ExplicitDirs) + set(RunCMake_TEST_NO_CLEAN 1) + set(RunCMake_TEST_NO_SOURCE_DIR 1) + set(source_dir ${RunCMake_BINARY_DIR}/ExplicitDirsMissing) file(REMOVE_RECURSE "${source_dir}") @@ -76,16 +79,15 @@ function(run_ExplicitDirs) cmake_minimum_required(VERSION 3.13) project(ExplicitDirsMissing LANGUAGES NONE) ]=]) - run_cmake_command(no-S-B ${CMAKE_COMMAND} -E chdir ${source_dir} - ${CMAKE_COMMAND} -DFOO=BAR) + set(RunCMake_TEST_SOURCE_DIR "${source_dir}") + set(RunCMake_TEST_BINARY_DIR "${source_dir}") + run_cmake_with_options(no-S-B -DFOO=BAR) set(source_dir ${RunCMake_SOURCE_DIR}/ExplicitDirs) set(binary_dir ${RunCMake_BINARY_DIR}/ExplicitDirs-build) set(RunCMake_TEST_SOURCE_DIR "${source_dir}") set(RunCMake_TEST_BINARY_DIR "${binary_dir}") - set(RunCMake_TEST_NO_CLEAN 1) - set(RunCMake_TEST_NO_SOURCE_DIR 1) file(REMOVE_RECURSE "${binary_dir}") run_cmake_with_options(S-arg -S ${source_dir} ${binary_dir}) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_custom_command-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_custom_command-stderr.txt index fc3c3de..2ee96ed 100644 --- a/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_custom_command-stderr.txt +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-add_custom_command-stderr.txt @@ -3,7 +3,6 @@ CMake Error at COMPILE_LANG_AND_ID-add_custom_command.cmake:2 \(add_custom_comma \$<COMPILE_LANG_AND_ID> - \$<COMPILE_LANG_AND_ID> expression requires 2 comma separated parameters, - but got 0 instead. + \$<COMPILE_LANG_AND_ID> expression requires at least two parameters. Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-target_sources-stderr.txt b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-target_sources-stderr.txt index 44d8684..3ecbdc3 100644 --- a/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-target_sources-stderr.txt +++ b/Tests/RunCMake/GeneratorExpression/COMPILE_LANG_AND_ID-target_sources-stderr.txt @@ -3,7 +3,6 @@ CMake Error at COMPILE_LANG_AND_ID-target_sources.cmake:2 \(target_sources\): \$<COMPILE_LANG_AND_ID> - \$<COMPILE_LANG_AND_ID> expression requires 2 comma separated parameters, - but got 0 instead. + \$<COMPILE_LANG_AND_ID> expression requires at least two parameters. Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/PolicyScope/dir1/CMakeLists.txt b/Tests/RunCMake/PolicyScope/dir1/CMakeLists.txt index 16bcb36..66ff016 100644 --- a/Tests/RunCMake/PolicyScope/dir1/CMakeLists.txt +++ b/Tests/RunCMake/PolicyScope/dir1/CMakeLists.txt @@ -2,4 +2,4 @@ add_library(foo STATIC foo.cpp) string(TOLOWER ${CMAKE_CXX_COMPILER_ID} compiler_id) -target_compile_definitions(foo PRIVATE Foo=$<CXX_COMPILER_ID:${compiler_id}>) +target_compile_definitions(foo PRIVATE Foo=$<CXX_COMPILER_ID:invalid,${compiler_id}>) diff --git a/Tests/RunCMake/Swift/E.swift b/Tests/RunCMake/Swift/E.swift new file mode 100644 index 0000000..a415467 --- /dev/null +++ b/Tests/RunCMake/Swift/E.swift @@ -0,0 +1,2 @@ +func f() { +} diff --git a/Tests/RunCMake/Swift/RunCMakeTest.cmake b/Tests/RunCMake/Swift/RunCMakeTest.cmake index de99042..4817045 100644 --- a/Tests/RunCMake/Swift/RunCMakeTest.cmake +++ b/Tests/RunCMake/Swift/RunCMakeTest.cmake @@ -6,7 +6,7 @@ if(RunCMake_GENERATOR STREQUAL Xcode) endif() elseif(RunCMake_GENERATOR STREQUAL Ninja) if(CMAKE_Swift_COMPILER) - # Add Ninja-specific Swift tests here. + run_cmake(Win32ExecutableDisallowed) endif() else() run_cmake(NotSupported) diff --git a/Tests/RunCMake/Swift/Win32ExecutableDisallowed-result.txt b/Tests/RunCMake/Swift/Win32ExecutableDisallowed-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/Swift/Win32ExecutableDisallowed-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Swift/Win32ExecutableDisallowed-stderr.txt b/Tests/RunCMake/Swift/Win32ExecutableDisallowed-stderr.txt new file mode 100644 index 0000000..d78101a --- /dev/null +++ b/Tests/RunCMake/Swift/Win32ExecutableDisallowed-stderr.txt @@ -0,0 +1,4 @@ +^CMake Error at Win32ExecutableDisallowed.cmake:[0-9]+ \(add_executable\): + WIN32_EXECUTABLE property is not supported on Swift executables +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/Swift/Win32ExecutableDisallowed.cmake b/Tests/RunCMake/Swift/Win32ExecutableDisallowed.cmake new file mode 100644 index 0000000..02d5447 --- /dev/null +++ b/Tests/RunCMake/Swift/Win32ExecutableDisallowed.cmake @@ -0,0 +1,4 @@ +enable_language(Swift) +add_executable(E E.swift) +set_target_properties(E PROPERTIES + WIN32_EXECUTABLE TRUE) diff --git a/Tests/RunCMake/Syntax/UnterminatedCall1-stderr.txt b/Tests/RunCMake/Syntax/UnterminatedCall1-stderr.txt index 3f52244..f3ee895 100644 --- a/Tests/RunCMake/Syntax/UnterminatedCall1-stderr.txt +++ b/Tests/RunCMake/Syntax/UnterminatedCall1-stderr.txt @@ -1,4 +1,4 @@ -CMake Error at UnterminatedCall1.cmake:2: +CMake Error at UnterminatedCall1.cmake:1: Parse error. Function missing ending "\)". End of file reached. Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/Syntax/UnterminatedCall1.cmake b/Tests/RunCMake/Syntax/UnterminatedCall1.cmake index 1166109..e1d2118 100644 --- a/Tests/RunCMake/Syntax/UnterminatedCall1.cmake +++ b/Tests/RunCMake/Syntax/UnterminatedCall1.cmake @@ -1 +1,4 @@ message( + + +message("Additional message") diff --git a/Tests/RunCMake/Syntax/UnterminatedCall2-stderr.txt b/Tests/RunCMake/Syntax/UnterminatedCall2-stderr.txt index 18656f7..04216c3 100644 --- a/Tests/RunCMake/Syntax/UnterminatedCall2-stderr.txt +++ b/Tests/RunCMake/Syntax/UnterminatedCall2-stderr.txt @@ -1,4 +1,4 @@ -CMake Error at UnterminatedCall2.cmake:4: +CMake Error at UnterminatedCall2.cmake:3: Parse error. Function missing ending "\)". End of file reached. Call Stack \(most recent call first\): CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/Syntax/UnterminatedCall2.cmake b/Tests/RunCMake/Syntax/UnterminatedCall2.cmake index 26e9e62..8d4088d 100644 --- a/Tests/RunCMake/Syntax/UnterminatedCall2.cmake +++ b/Tests/RunCMake/Syntax/UnterminatedCall2.cmake @@ -1,3 +1,6 @@ set(var "\ ") message( + + +message("Additional message") diff --git a/Tests/RunCMake/VisibilityPreset/PropertyTypo-stderr.txt b/Tests/RunCMake/VisibilityPreset/PropertyTypo-stderr.txt index ca8c33f..a63591f 100644 --- a/Tests/RunCMake/VisibilityPreset/PropertyTypo-stderr.txt +++ b/Tests/RunCMake/VisibilityPreset/PropertyTypo-stderr.txt @@ -1 +1 @@ -CMake Error: Target visibility_preset uses unsupported value \"hiden\" for CXX_VISIBILITY_PRESET +CMake Error: Target visibility_preset uses unsupported value \"hiden\" for CXX_VISIBILITY_PRESET. The supported values are: default, hidden, protected, and internal. |