1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-19 11:18:40 +08:00

target_link_libraries: Handle keyword arguments in dedicated code path

This commit is contained in:
Brad King
2022-02-15 16:49:07 -05:00
parent 42590df9f9
commit 5571a31648

View File

@@ -178,16 +178,31 @@ bool cmTargetLinkLibrariesCommand(std::vector<std::string> const& args,
// specification if the keyword is encountered as the first argument. // specification if the keyword is encountered as the first argument.
ProcessingState currentProcessingState = ProcessingLinkLibraries; ProcessingState currentProcessingState = ProcessingLinkLibraries;
// Keep this list in sync with the keyword dispatch below.
static std::unordered_set<std::string> const keywords{
"LINK_INTERFACE_LIBRARIES",
"INTERFACE",
"LINK_PUBLIC",
"PUBLIC",
"LINK_PRIVATE",
"PRIVATE",
"debug",
"optimized",
"general",
};
// Add libraries, note that there is an optional prefix // Add libraries, note that there is an optional prefix
// of debug and optimized that can be used. // of debug and optimized that can be used.
for (unsigned int i = 1; i < args.size(); ++i) { for (unsigned int i = 1; i < args.size(); ++i) {
if (keywords.count(args[i])) {
// Process this keyword argument.
if (args[i] == "LINK_INTERFACE_LIBRARIES") { if (args[i] == "LINK_INTERFACE_LIBRARIES") {
currentProcessingState = ProcessingPlainLinkInterface; currentProcessingState = ProcessingPlainLinkInterface;
if (i != 1) { if (i != 1) {
mf.IssueMessage( mf.IssueMessage(
MessageType::FATAL_ERROR, MessageType::FATAL_ERROR,
"The LINK_INTERFACE_LIBRARIES option must appear as the second " "The LINK_INTERFACE_LIBRARIES option must appear as the "
"argument, just after the target name."); "second argument, just after the target name.");
return true; return true;
} }
} else if (args[i] == "INTERFACE") { } else if (args[i] == "INTERFACE") {
@@ -195,10 +210,10 @@ bool cmTargetLinkLibrariesCommand(std::vector<std::string> const& args,
currentProcessingState != ProcessingKeywordPrivateInterface && currentProcessingState != ProcessingKeywordPrivateInterface &&
currentProcessingState != ProcessingKeywordPublicInterface && currentProcessingState != ProcessingKeywordPublicInterface &&
currentProcessingState != ProcessingKeywordLinkInterface) { currentProcessingState != ProcessingKeywordLinkInterface) {
mf.IssueMessage( mf.IssueMessage(MessageType::FATAL_ERROR,
MessageType::FATAL_ERROR, "The INTERFACE, PUBLIC or PRIVATE option must "
"The INTERFACE, PUBLIC or PRIVATE option must appear as the second " "appear as the second argument, just after the "
"argument, just after the target name."); "target name.");
return true; return true;
} }
currentProcessingState = ProcessingKeywordLinkInterface; currentProcessingState = ProcessingKeywordLinkInterface;
@@ -208,8 +223,8 @@ bool cmTargetLinkLibrariesCommand(std::vector<std::string> const& args,
currentProcessingState != ProcessingPlainPublicInterface) { currentProcessingState != ProcessingPlainPublicInterface) {
mf.IssueMessage( mf.IssueMessage(
MessageType::FATAL_ERROR, MessageType::FATAL_ERROR,
"The LINK_PUBLIC or LINK_PRIVATE option must appear as the second " "The LINK_PUBLIC or LINK_PRIVATE option must appear as the "
"argument, just after the target name."); "second argument, just after the target name.");
return true; return true;
} }
currentProcessingState = ProcessingPlainPublicInterface; currentProcessingState = ProcessingPlainPublicInterface;
@@ -218,20 +233,21 @@ bool cmTargetLinkLibrariesCommand(std::vector<std::string> const& args,
currentProcessingState != ProcessingKeywordPrivateInterface && currentProcessingState != ProcessingKeywordPrivateInterface &&
currentProcessingState != ProcessingKeywordPublicInterface && currentProcessingState != ProcessingKeywordPublicInterface &&
currentProcessingState != ProcessingKeywordLinkInterface) { currentProcessingState != ProcessingKeywordLinkInterface) {
mf.IssueMessage( mf.IssueMessage(MessageType::FATAL_ERROR,
MessageType::FATAL_ERROR, "The INTERFACE, PUBLIC or PRIVATE option must "
"The INTERFACE, PUBLIC or PRIVATE option must appear as the second " "appear as the second argument, just after the "
"argument, just after the target name."); "target name.");
return true; return true;
} }
currentProcessingState = ProcessingKeywordPublicInterface; currentProcessingState = ProcessingKeywordPublicInterface;
} else if (args[i] == "LINK_PRIVATE") { } else if (args[i] == "LINK_PRIVATE") {
if (i != 1 && currentProcessingState != ProcessingPlainPublicInterface && if (i != 1 &&
currentProcessingState != ProcessingPlainPublicInterface &&
currentProcessingState != ProcessingPlainPrivateInterface) { currentProcessingState != ProcessingPlainPrivateInterface) {
mf.IssueMessage( mf.IssueMessage(
MessageType::FATAL_ERROR, MessageType::FATAL_ERROR,
"The LINK_PUBLIC or LINK_PRIVATE option must appear as the second " "The LINK_PUBLIC or LINK_PRIVATE option must appear as the "
"argument, just after the target name."); "second argument, just after the target name.");
return true; return true;
} }
currentProcessingState = ProcessingPlainPrivateInterface; currentProcessingState = ProcessingPlainPrivateInterface;
@@ -240,10 +256,10 @@ bool cmTargetLinkLibrariesCommand(std::vector<std::string> const& args,
currentProcessingState != ProcessingKeywordPrivateInterface && currentProcessingState != ProcessingKeywordPrivateInterface &&
currentProcessingState != ProcessingKeywordPublicInterface && currentProcessingState != ProcessingKeywordPublicInterface &&
currentProcessingState != ProcessingKeywordLinkInterface) { currentProcessingState != ProcessingKeywordLinkInterface) {
mf.IssueMessage( mf.IssueMessage(MessageType::FATAL_ERROR,
MessageType::FATAL_ERROR, "The INTERFACE, PUBLIC or PRIVATE option must "
"The INTERFACE, PUBLIC or PRIVATE option must appear as the second " "appear as the second argument, just after the "
"argument, just after the target name."); "target name.");
return true; return true;
} }
currentProcessingState = ProcessingKeywordPrivateInterface; currentProcessingState = ProcessingKeywordPrivateInterface;
@@ -265,6 +281,7 @@ bool cmTargetLinkLibrariesCommand(std::vector<std::string> const& args,
} }
llt = GENERAL_LibraryType; llt = GENERAL_LibraryType;
haveLLT = true; haveLLT = true;
}
} else if (haveLLT) { } else if (haveLLT) {
// The link type was specified by the previous argument. // The link type was specified by the previous argument.
haveLLT = false; haveLLT = false;