/src/CMake/Source/cmGetSourceFilePropertyCommand.cxx
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #include "cmGetSourceFilePropertyCommand.h" |
4 | | |
5 | | #include <cm/string_view> |
6 | | #include <cmext/string_view> |
7 | | |
8 | | #include "cmExecutionStatus.h" |
9 | | #include "cmMakefile.h" |
10 | | #include "cmSourceFilePropertyHelper.h" |
11 | | #include "cmValue.h" |
12 | | |
13 | | bool cmGetSourceFilePropertyCommand(std::vector<std::string> const& args, |
14 | | cmExecutionStatus& status) |
15 | 0 | { |
16 | 0 | std::vector<std::string>::size_type args_size = args.size(); |
17 | 0 | if (args_size != 3 && args_size != 5) { |
18 | 0 | status.SetError("called with incorrect number of arguments"); |
19 | 0 | return false; |
20 | 0 | } |
21 | | |
22 | 0 | std::vector<std::string> source_file_directories; |
23 | 0 | std::vector<std::string> source_file_target_directories; |
24 | 0 | bool source_file_directory_option_enabled = false; |
25 | 0 | bool source_file_target_option_enabled = false; |
26 | |
|
27 | 0 | int property_arg_index = 2; |
28 | 0 | if (args[2] == "DIRECTORY"_s && args_size == 5) { |
29 | 0 | property_arg_index = 4; |
30 | 0 | source_file_directory_option_enabled = true; |
31 | 0 | source_file_directories.push_back(args[3]); |
32 | 0 | } else if (args[2] == "TARGET_DIRECTORY"_s && args_size == 5) { |
33 | 0 | property_arg_index = 4; |
34 | 0 | source_file_target_option_enabled = true; |
35 | 0 | source_file_target_directories.push_back(args[3]); |
36 | 0 | } |
37 | |
|
38 | 0 | std::string const& var = args[0]; |
39 | 0 | std::string const& sourceName = args[1]; |
40 | 0 | std::string const& propName = args[property_arg_index]; |
41 | |
|
42 | 0 | cmValue prop; |
43 | 0 | auto result = cmGetSourceFileProperty( |
44 | 0 | sourceName, propName, status, source_file_directory_option_enabled, |
45 | 0 | source_file_target_option_enabled, source_file_directories, |
46 | 0 | source_file_target_directories, prop); |
47 | |
|
48 | 0 | if (result == cmGetSourceFilePropertyResult::Success) { |
49 | 0 | if (prop) { |
50 | 0 | status.GetMakefile().AddDefinition(var, *prop); |
51 | 0 | return true; |
52 | 0 | } |
53 | 0 | status.GetMakefile().AddDefinition(var, "NOTFOUND"); |
54 | 0 | return true; |
55 | 0 | } |
56 | 0 | if (result == cmGetSourceFilePropertyResult::SourceNotFound || |
57 | 0 | result == cmGetSourceFilePropertyResult::Error) { |
58 | 0 | status.GetMakefile().AddDefinition(var, "NOTFOUND"); |
59 | 0 | return true; |
60 | 0 | } |
61 | 0 | return false; |
62 | 0 | } |