cmGetSorceFilePropertyCommand: Simplify string comparisons

This commit is contained in:
Deniz Bahadir
2024-03-28 14:16:10 +01:00
parent 1ff6c1eecf
commit e04af1e9c2

View File

@@ -2,6 +2,9 @@
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmGetSourceFilePropertyCommand.h"
#include <cm/string_view>
#include <cmext/string_view>
#include "cmExecutionStatus.h"
#include "cmMakefile.h"
#include "cmSetPropertyCommand.h"
@@ -23,11 +26,11 @@ bool cmGetSourceFilePropertyCommand(std::vector<std::string> const& args,
bool source_file_target_option_enabled = false;
int property_arg_index = 2;
if (args[2] == "DIRECTORY" && args_size == 5) {
if (args[2] == "DIRECTORY"_s && args_size == 5) {
property_arg_index = 4;
source_file_directory_option_enabled = true;
source_file_directories.push_back(args[3]);
} else if (args[2] == "TARGET_DIRECTORY" && args_size == 5) {
} else if (args[2] == "TARGET_DIRECTORY"_s && args_size == 5) {
property_arg_index = 4;
source_file_target_option_enabled = true;
source_file_target_directories.push_back(args[3]);
@@ -44,6 +47,7 @@ bool cmGetSourceFilePropertyCommand(std::vector<std::string> const& args,
}
std::string const& var = args[0];
std::string const& propName = args[property_arg_index];
bool source_file_paths_should_be_absolute =
source_file_directory_option_enabled || source_file_target_option_enabled;
std::string const file =
@@ -53,14 +57,14 @@ bool cmGetSourceFilePropertyCommand(std::vector<std::string> const& args,
cmSourceFile* sf = mf.GetSource(file);
// for the location we must create a source file first
if (!sf && args[property_arg_index] == "LOCATION") {
if (!sf && propName == "LOCATION"_s) {
sf = mf.CreateSource(file);
}
if (sf) {
cmValue prop = nullptr;
if (!args[property_arg_index].empty()) {
prop = sf->GetPropertyForUser(args[property_arg_index]);
if (!propName.empty()) {
prop = sf->GetPropertyForUser(propName);
}
if (prop) {
// Set the value on the original Makefile scope, not the scope of the