mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-18 17:31:57 +08:00
target_link_libraries: Handle keyword arguments in dedicated code path
This commit is contained in:
@@ -178,93 +178,110 @@ 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 (args[i] == "LINK_INTERFACE_LIBRARIES") {
|
if (keywords.count(args[i])) {
|
||||||
currentProcessingState = ProcessingPlainLinkInterface;
|
// Process this keyword argument.
|
||||||
if (i != 1) {
|
if (args[i] == "LINK_INTERFACE_LIBRARIES") {
|
||||||
mf.IssueMessage(
|
currentProcessingState = ProcessingPlainLinkInterface;
|
||||||
MessageType::FATAL_ERROR,
|
if (i != 1) {
|
||||||
"The LINK_INTERFACE_LIBRARIES option must appear as the second "
|
mf.IssueMessage(
|
||||||
"argument, just after the target name.");
|
MessageType::FATAL_ERROR,
|
||||||
return true;
|
"The LINK_INTERFACE_LIBRARIES option must appear as the "
|
||||||
|
"second argument, just after the target name.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (args[i] == "INTERFACE") {
|
||||||
|
if (i != 1 &&
|
||||||
|
currentProcessingState != ProcessingKeywordPrivateInterface &&
|
||||||
|
currentProcessingState != ProcessingKeywordPublicInterface &&
|
||||||
|
currentProcessingState != ProcessingKeywordLinkInterface) {
|
||||||
|
mf.IssueMessage(MessageType::FATAL_ERROR,
|
||||||
|
"The INTERFACE, PUBLIC or PRIVATE option must "
|
||||||
|
"appear as the second argument, just after the "
|
||||||
|
"target name.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
currentProcessingState = ProcessingKeywordLinkInterface;
|
||||||
|
} else if (args[i] == "LINK_PUBLIC") {
|
||||||
|
if (i != 1 &&
|
||||||
|
currentProcessingState != ProcessingPlainPrivateInterface &&
|
||||||
|
currentProcessingState != ProcessingPlainPublicInterface) {
|
||||||
|
mf.IssueMessage(
|
||||||
|
MessageType::FATAL_ERROR,
|
||||||
|
"The LINK_PUBLIC or LINK_PRIVATE option must appear as the "
|
||||||
|
"second argument, just after the target name.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
currentProcessingState = ProcessingPlainPublicInterface;
|
||||||
|
} else if (args[i] == "PUBLIC") {
|
||||||
|
if (i != 1 &&
|
||||||
|
currentProcessingState != ProcessingKeywordPrivateInterface &&
|
||||||
|
currentProcessingState != ProcessingKeywordPublicInterface &&
|
||||||
|
currentProcessingState != ProcessingKeywordLinkInterface) {
|
||||||
|
mf.IssueMessage(MessageType::FATAL_ERROR,
|
||||||
|
"The INTERFACE, PUBLIC or PRIVATE option must "
|
||||||
|
"appear as the second argument, just after the "
|
||||||
|
"target name.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
currentProcessingState = ProcessingKeywordPublicInterface;
|
||||||
|
} else if (args[i] == "LINK_PRIVATE") {
|
||||||
|
if (i != 1 &&
|
||||||
|
currentProcessingState != ProcessingPlainPublicInterface &&
|
||||||
|
currentProcessingState != ProcessingPlainPrivateInterface) {
|
||||||
|
mf.IssueMessage(
|
||||||
|
MessageType::FATAL_ERROR,
|
||||||
|
"The LINK_PUBLIC or LINK_PRIVATE option must appear as the "
|
||||||
|
"second argument, just after the target name.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
currentProcessingState = ProcessingPlainPrivateInterface;
|
||||||
|
} else if (args[i] == "PRIVATE") {
|
||||||
|
if (i != 1 &&
|
||||||
|
currentProcessingState != ProcessingKeywordPrivateInterface &&
|
||||||
|
currentProcessingState != ProcessingKeywordPublicInterface &&
|
||||||
|
currentProcessingState != ProcessingKeywordLinkInterface) {
|
||||||
|
mf.IssueMessage(MessageType::FATAL_ERROR,
|
||||||
|
"The INTERFACE, PUBLIC or PRIVATE option must "
|
||||||
|
"appear as the second argument, just after the "
|
||||||
|
"target name.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
currentProcessingState = ProcessingKeywordPrivateInterface;
|
||||||
|
} else if (args[i] == "debug") {
|
||||||
|
if (haveLLT) {
|
||||||
|
LinkLibraryTypeSpecifierWarning(mf, llt, DEBUG_LibraryType);
|
||||||
|
}
|
||||||
|
llt = DEBUG_LibraryType;
|
||||||
|
haveLLT = true;
|
||||||
|
} else if (args[i] == "optimized") {
|
||||||
|
if (haveLLT) {
|
||||||
|
LinkLibraryTypeSpecifierWarning(mf, llt, OPTIMIZED_LibraryType);
|
||||||
|
}
|
||||||
|
llt = OPTIMIZED_LibraryType;
|
||||||
|
haveLLT = true;
|
||||||
|
} else if (args[i] == "general") {
|
||||||
|
if (haveLLT) {
|
||||||
|
LinkLibraryTypeSpecifierWarning(mf, llt, GENERAL_LibraryType);
|
||||||
|
}
|
||||||
|
llt = GENERAL_LibraryType;
|
||||||
|
haveLLT = true;
|
||||||
}
|
}
|
||||||
} else if (args[i] == "INTERFACE") {
|
|
||||||
if (i != 1 &&
|
|
||||||
currentProcessingState != ProcessingKeywordPrivateInterface &&
|
|
||||||
currentProcessingState != ProcessingKeywordPublicInterface &&
|
|
||||||
currentProcessingState != ProcessingKeywordLinkInterface) {
|
|
||||||
mf.IssueMessage(
|
|
||||||
MessageType::FATAL_ERROR,
|
|
||||||
"The INTERFACE, PUBLIC or PRIVATE option must appear as the second "
|
|
||||||
"argument, just after the target name.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
currentProcessingState = ProcessingKeywordLinkInterface;
|
|
||||||
} else if (args[i] == "LINK_PUBLIC") {
|
|
||||||
if (i != 1 &&
|
|
||||||
currentProcessingState != ProcessingPlainPrivateInterface &&
|
|
||||||
currentProcessingState != ProcessingPlainPublicInterface) {
|
|
||||||
mf.IssueMessage(
|
|
||||||
MessageType::FATAL_ERROR,
|
|
||||||
"The LINK_PUBLIC or LINK_PRIVATE option must appear as the second "
|
|
||||||
"argument, just after the target name.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
currentProcessingState = ProcessingPlainPublicInterface;
|
|
||||||
} else if (args[i] == "PUBLIC") {
|
|
||||||
if (i != 1 &&
|
|
||||||
currentProcessingState != ProcessingKeywordPrivateInterface &&
|
|
||||||
currentProcessingState != ProcessingKeywordPublicInterface &&
|
|
||||||
currentProcessingState != ProcessingKeywordLinkInterface) {
|
|
||||||
mf.IssueMessage(
|
|
||||||
MessageType::FATAL_ERROR,
|
|
||||||
"The INTERFACE, PUBLIC or PRIVATE option must appear as the second "
|
|
||||||
"argument, just after the target name.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
currentProcessingState = ProcessingKeywordPublicInterface;
|
|
||||||
} else if (args[i] == "LINK_PRIVATE") {
|
|
||||||
if (i != 1 && currentProcessingState != ProcessingPlainPublicInterface &&
|
|
||||||
currentProcessingState != ProcessingPlainPrivateInterface) {
|
|
||||||
mf.IssueMessage(
|
|
||||||
MessageType::FATAL_ERROR,
|
|
||||||
"The LINK_PUBLIC or LINK_PRIVATE option must appear as the second "
|
|
||||||
"argument, just after the target name.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
currentProcessingState = ProcessingPlainPrivateInterface;
|
|
||||||
} else if (args[i] == "PRIVATE") {
|
|
||||||
if (i != 1 &&
|
|
||||||
currentProcessingState != ProcessingKeywordPrivateInterface &&
|
|
||||||
currentProcessingState != ProcessingKeywordPublicInterface &&
|
|
||||||
currentProcessingState != ProcessingKeywordLinkInterface) {
|
|
||||||
mf.IssueMessage(
|
|
||||||
MessageType::FATAL_ERROR,
|
|
||||||
"The INTERFACE, PUBLIC or PRIVATE option must appear as the second "
|
|
||||||
"argument, just after the target name.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
currentProcessingState = ProcessingKeywordPrivateInterface;
|
|
||||||
} else if (args[i] == "debug") {
|
|
||||||
if (haveLLT) {
|
|
||||||
LinkLibraryTypeSpecifierWarning(mf, llt, DEBUG_LibraryType);
|
|
||||||
}
|
|
||||||
llt = DEBUG_LibraryType;
|
|
||||||
haveLLT = true;
|
|
||||||
} else if (args[i] == "optimized") {
|
|
||||||
if (haveLLT) {
|
|
||||||
LinkLibraryTypeSpecifierWarning(mf, llt, OPTIMIZED_LibraryType);
|
|
||||||
}
|
|
||||||
llt = OPTIMIZED_LibraryType;
|
|
||||||
haveLLT = true;
|
|
||||||
} else if (args[i] == "general") {
|
|
||||||
if (haveLLT) {
|
|
||||||
LinkLibraryTypeSpecifierWarning(mf, llt, GENERAL_LibraryType);
|
|
||||||
}
|
|
||||||
llt = GENERAL_LibraryType;
|
|
||||||
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;
|
||||||
|
Reference in New Issue
Block a user