summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-02-15 21:49:07 (GMT)
committerBrad King <brad.king@kitware.com>2022-02-15 22:17:49 (GMT)
commit5571a316489ff71e4139e967464a7ad97574fce2 (patch)
tree9ee0d900df0ad70f488baebf80f1b80d44107619
parent42590df9f9fe07ba2aa0bbc19069a6f8cf561cb1 (diff)
downloadCMake-5571a316489ff71e4139e967464a7ad97574fce2.zip
CMake-5571a316489ff71e4139e967464a7ad97574fce2.tar.gz
CMake-5571a316489ff71e4139e967464a7ad97574fce2.tar.bz2
target_link_libraries: Handle keyword arguments in dedicated code path
-rw-r--r--Source/cmTargetLinkLibrariesCommand.cxx183
1 files changed, 100 insertions, 83 deletions
diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx
index 38b1601..1cd8a7e 100644
--- a/Source/cmTargetLinkLibrariesCommand.cxx
+++ b/Source/cmTargetLinkLibrariesCommand.cxx
@@ -178,93 +178,110 @@ bool cmTargetLinkLibrariesCommand(std::vector<std::string> const& args,
// specification if the keyword is encountered as the first argument.
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
// of debug and optimized that can be used.
for (unsigned int i = 1; i < args.size(); ++i) {
- if (args[i] == "LINK_INTERFACE_LIBRARIES") {
- currentProcessingState = ProcessingPlainLinkInterface;
- if (i != 1) {
- mf.IssueMessage(
- MessageType::FATAL_ERROR,
- "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);
+ if (keywords.count(args[i])) {
+ // Process this keyword argument.
+ if (args[i] == "LINK_INTERFACE_LIBRARIES") {
+ currentProcessingState = ProcessingPlainLinkInterface;
+ if (i != 1) {
+ mf.IssueMessage(
+ MessageType::FATAL_ERROR,
+ "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;
}
- llt = GENERAL_LibraryType;
- haveLLT = true;
} else if (haveLLT) {
// The link type was specified by the previous argument.
haveLLT = false;