Coverage Report

Created: 2026-04-29 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmTarget.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 "cmTarget.h"
4
5
#include <algorithm>
6
#include <cassert>
7
#include <functional>
8
#include <iterator>
9
#include <map>
10
#include <set>
11
#include <sstream>
12
#include <unordered_map>
13
#include <unordered_set>
14
15
#include <cm/memory>
16
#include <cm/string_view>
17
#include <cmext/algorithm>
18
#include <cmext/string_view>
19
20
#include "cmsys/RegularExpression.hxx"
21
22
#include "cmAlgorithms.h"
23
#include "cmCustomCommand.h"
24
#include "cmDiagnostics.h"
25
#include "cmFileSet.h"
26
#include "cmFileSetMetadata.h"
27
#include "cmFindPackageStack.h"
28
#include "cmGeneratorExpression.h"
29
#include "cmGlobalGenerator.h"
30
#include "cmList.h"
31
#include "cmListFileCache.h"
32
#include "cmMakefile.h"
33
#include "cmMessageType.h"
34
#include "cmProperty.h"
35
#include "cmPropertyDefinition.h"
36
#include "cmPropertyMap.h"
37
#include "cmRange.h"
38
#include "cmSourceFile.h"
39
#include "cmSourceFileLocation.h"
40
#include "cmSourceFileLocationKind.h"
41
#include "cmState.h"
42
#include "cmStateDirectory.h"
43
#include "cmStateSnapshot.h"
44
#include "cmSystemTools.h"
45
#include "cmTargetPropertyComputer.h"
46
#include "cmValue.h"
47
#include "cmXcFramework.h"
48
#include "cmake.h"
49
50
template <>
51
std::string const& cmTargetPropertyComputer::ImportedLocation<cmTarget>(
52
  cmTarget const* tgt, std::string const& config)
53
0
{
54
0
  static std::string loc;
55
0
  assert(tgt->IsImported());
56
0
  loc = tgt->ImportedGetFullPath(config, cmStateEnums::RuntimeBinaryArtifact);
57
0
  return loc;
58
0
}
59
60
template <>
61
cmValue cmTargetPropertyComputer::GetSources<cmTarget>(cmTarget const* tgt)
62
0
{
63
0
  cmBTStringRange entries = tgt->GetSourceEntries();
64
0
  if (entries.empty()) {
65
0
    return nullptr;
66
0
  }
67
68
0
  std::ostringstream ss;
69
0
  char const* sep = "";
70
0
  for (auto const& entry : entries) {
71
0
    cmList files{ entry.Value };
72
0
    for (std::string const& file : files) {
73
0
      if ((cmHasLiteralPrefix(file, "$<TARGET_OBJECTS:") &&
74
0
           file.back() == '>') ||
75
0
          cmGeneratorExpression::Find(file) == std::string::npos) {
76
0
        ss << sep;
77
0
        sep = ";";
78
0
        ss << file;
79
0
      } else {
80
0
        cmSourceFile* sf = tgt->GetMakefile()->GetOrCreateSource(file);
81
        // Construct what is known about this source file location.
82
0
        cmSourceFileLocation const& location = sf->GetLocation();
83
0
        std::string sname = location.GetDirectory();
84
0
        if (!sname.empty()) {
85
0
          sname += "/";
86
0
        }
87
0
        sname += location.GetName();
88
89
0
        ss << sep;
90
0
        sep = ";";
91
        // Append this list entry.
92
0
        ss << sname;
93
0
      }
94
0
    }
95
0
  }
96
0
  static std::string srcs;
97
0
  srcs = ss.str();
98
0
  return cmValue(srcs);
99
0
}
100
101
namespace {
102
struct FileSetEntries
103
{
104
  FileSetEntries(cm::string_view propertyName)
105
0
    : PropertyName(propertyName)
106
0
  {
107
0
  }
108
109
  cm::string_view const PropertyName;
110
  std::vector<BT<std::string>> Entries;
111
};
112
113
struct FileSetType
114
{
115
  FileSetType(cm::string_view typeName,
116
              cm::static_string_view defaultDirectoryProperty,
117
              cm::static_string_view defaultPathProperty,
118
              cm::static_string_view directoryPrefix,
119
              cm::static_string_view pathPrefix,
120
              cm::static_string_view typeDescription,
121
              cm::static_string_view defaultDescription,
122
              cm::static_string_view arbitraryDescription,
123
              FileSetEntries selfEntries, FileSetEntries interfaceEntries)
124
0
    : TypeName(typeName)
125
0
    , DefaultDirectoryProperty(defaultDirectoryProperty)
126
0
    , DefaultPathProperty(defaultPathProperty)
127
0
    , DirectoryPrefix(directoryPrefix)
128
0
    , PathPrefix(pathPrefix)
129
0
    , TypeDescription(typeDescription)
130
0
    , DefaultDescription(defaultDescription)
131
0
    , ArbitraryDescription(arbitraryDescription)
132
0
    , SelfEntries(std::move(selfEntries))
133
0
    , InterfaceEntries(std::move(interfaceEntries))
134
0
  {
135
0
  }
136
137
  cm::string_view const TypeName;
138
  cm::static_string_view const DefaultDirectoryProperty;
139
  cm::static_string_view const DefaultPathProperty;
140
  cm::static_string_view const DirectoryPrefix;
141
  cm::static_string_view const PathPrefix;
142
  cm::static_string_view const TypeDescription;
143
  cm::static_string_view const DefaultDescription;
144
  cm::static_string_view const ArbitraryDescription;
145
146
  FileSetEntries SelfEntries;
147
  FileSetEntries InterfaceEntries;
148
149
  enum class Action
150
  {
151
    Set,
152
    Append,
153
  };
154
155
  template <typename ValueType>
156
  bool WriteProperties(cmTarget* tgt, cmTargetInternals* impl,
157
                       std::string const& prop, ValueType value,
158
                       Action action);
159
  std::pair<bool, cmValue> ReadProperties(cmTarget const* tgt,
160
                                          cmTargetInternals const* impl,
161
                                          std::string const& prop) const;
162
163
  void AddFileSet(std::string const& name, cm::FileSetMetadata::Visibility vis,
164
                  cmListFileBacktrace bt);
165
};
166
167
struct UsageRequirementProperty
168
{
169
  enum class AppendEmpty
170
  {
171
    Yes,
172
    No,
173
  };
174
175
  UsageRequirementProperty(cm::static_string_view name,
176
                           AppendEmpty appendEmpty = AppendEmpty::No)
177
0
    : Name(name)
178
0
    , AppendBehavior(appendEmpty)
179
0
  {
180
0
  }
181
182
  void CopyFromEntries(cmBTStringRange entries)
183
0
  {
184
0
    cm::append(this->Entries, entries);
185
0
  }
186
187
  enum class Action
188
  {
189
    Set,
190
    Prepend,
191
    Append,
192
  };
193
194
  template <typename ValueType>
195
  bool Write(cmTargetInternals const* impl,
196
             cm::optional<cmListFileBacktrace> const& bt,
197
             std::string const& prop, ValueType value, Action action);
198
  template <typename ValueType>
199
  void WriteDirect(cmTargetInternals const* impl,
200
                   cm::optional<cmListFileBacktrace> const& bt,
201
                   ValueType value, Action action);
202
  void WriteDirect(BT<std::string> value, Action action);
203
  std::pair<bool, cmValue> Read(std::string const& prop) const;
204
205
  cm::static_string_view const Name;
206
  AppendEmpty const AppendBehavior;
207
208
  std::vector<BT<std::string>> Entries;
209
};
210
211
struct TargetProperty
212
{
213
  enum class InitCondition
214
  {
215
    // Always initialize the property.
216
    Always,
217
    // Never initialize the property.
218
    Never,
219
    // Only initialize if the target can compile sources.
220
    CanCompileSources,
221
    // Only apply to Xcode generators.
222
    NeedsXcode,
223
    // Only apply to Xcode generators on targets that can compile sources.
224
    NeedsXcodeAndCanCompileSources,
225
    // Needs to be a "normal" target (any non-global, non-utility target).
226
    NormalTarget,
227
    // Any non-imported target.
228
    NonImportedTarget,
229
    // Needs to be a "normal" target (any non-global, non-utility target) that
230
    // is not `IMPORTED`.
231
    NormalNonImportedTarget,
232
    // Needs to be a "normal" target with an artifact (no `INTERFACE`
233
    // libraries).
234
    TargetWithArtifact,
235
    // Needs to be a "normal" target with an artifact that is not an
236
    // executable.
237
    NonExecutableWithArtifact,
238
    // Needs to be a linkable library target (no `OBJECT` or `MODULE`
239
    // libraries).
240
    LinkableLibraryTarget,
241
    // Needs to be an executable.
242
    ExecutableTarget,
243
    // Needs to be a shared library (`SHARED`).
244
    SharedLibraryTarget,
245
    // Needs to be a target with meaningful symbol exports (`SHARED` or
246
    // `EXECUTABLE`).
247
    TargetWithSymbolExports,
248
    // Targets with "commands" associated with them. Basically everything
249
    // except global and `INTERFACE` targets.
250
    TargetWithCommands,
251
  };
252
253
  enum class Repetition
254
  {
255
    Once,
256
    PerConfig,
257
    PerConfigPrefix,
258
  };
259
260
  TargetProperty(cm::static_string_view name)
261
12
    : Name(name)
262
12
  {
263
12
  }
264
265
  TargetProperty(cm::static_string_view name, cm::static_string_view dflt,
266
                 InitCondition init)
267
36
    : Name(name)
268
36
    , Default(dflt)
269
36
    , InitConditional(init)
270
36
  {
271
36
  }
272
273
  TargetProperty(cm::static_string_view name, InitCondition init)
274
736
    : Name(name)
275
736
    , InitConditional(init)
276
736
  {
277
736
  }
278
279
  TargetProperty(cm::static_string_view name, InitCondition init,
280
                 Repetition repeat)
281
36
    : Name(name)
282
36
    , InitConditional(init)
283
36
    , Repeat(repeat)
284
36
  {
285
36
  }
286
287
  cm::static_string_view const Name;
288
  // Explicit initialization is needed for AppleClang in Xcode 8 and below
289
  // NOLINTNEXTLINE(readability-redundant-member-init)
290
  cm::optional<cm::static_string_view> const Default = {};
291
  InitCondition const InitConditional = InitCondition::Always;
292
  Repetition const Repeat = Repetition::Once;
293
};
294
295
#define IC TargetProperty::InitCondition
296
#define R TargetProperty::Repetition
297
298
/* clang-format off */
299
#define COMMON_LANGUAGE_PROPERTIES(lang)                                      \
300
  { #lang "_COMPILER_LAUNCHER"_s, IC::CanCompileSources },                    \
301
  { #lang "_STANDARD"_s, IC::CanCompileSources },                             \
302
  { #lang "_STANDARD_REQUIRED"_s, IC::CanCompileSources },                    \
303
  { #lang "_EXTENSIONS"_s, IC::CanCompileSources },                           \
304
  { #lang "_VISIBILITY_PRESET"_s, IC::CanCompileSources }
305
/* clang-format on */
306
307
TargetProperty const StaticTargetProperties[] = {
308
  /* clang-format off */
309
  // -- Debugger Properties
310
  { "DEBUGGER_WORKING_DIRECTORY"_s, IC::ExecutableTarget },
311
  // Compilation properties
312
  { "COMPILE_WARNING_AS_ERROR"_s, IC::CanCompileSources },
313
  { "INTERPROCEDURAL_OPTIMIZATION"_s, IC::CanCompileSources },
314
  { "INTERPROCEDURAL_OPTIMIZATION_"_s, IC::TargetWithArtifact, R::PerConfig },
315
  { "NO_SYSTEM_FROM_IMPORTED"_s, IC::CanCompileSources },
316
  // Set to `True` for `SHARED` and `MODULE` targets.
317
  { "POSITION_INDEPENDENT_CODE"_s, IC::CanCompileSources },
318
  { "VISIBILITY_INLINES_HIDDEN"_s, IC::CanCompileSources },
319
  // -- Features
320
  // ---- PCH
321
  { "DISABLE_PRECOMPILE_HEADERS"_s, IC::CanCompileSources },
322
  { "PCH_WARN_INVALID"_s, "ON"_s, IC::CanCompileSources },
323
  { "PCH_INSTANTIATE_TEMPLATES"_s, "ON"_s, IC::CanCompileSources },
324
  // -- Platforms
325
  // ---- Android
326
  { "ANDROID_API"_s, IC::CanCompileSources },
327
  { "ANDROID_API_MIN"_s, IC::CanCompileSources },
328
  { "ANDROID_ARCH"_s, IC::CanCompileSources },
329
  { "ANDROID_ASSETS_DIRECTORIES"_s, IC::CanCompileSources },
330
  { "ANDROID_JAVA_SOURCE_DIR"_s, IC::CanCompileSources },
331
  { "ANDROID_STL_TYPE"_s, IC::CanCompileSources },
332
  // ---- macOS
333
  { "OSX_ARCHITECTURES"_s, IC::CanCompileSources },
334
  // ---- Windows
335
  { "MSVC_DEBUG_INFORMATION_FORMAT"_s, IC::CanCompileSources },
336
  { "MSVC_RUNTIME_CHECKS"_s, IC::CanCompileSources },
337
  { "MSVC_RUNTIME_LIBRARY"_s, IC::CanCompileSources },
338
  { "VS_JUST_MY_CODE_DEBUGGING"_s, IC::CanCompileSources },
339
  { "VS_DEBUGGER_COMMAND"_s, IC::ExecutableTarget },
340
  { "VS_DEBUGGER_COMMAND_ARGUMENTS"_s, IC::ExecutableTarget },
341
  { "VS_DEBUGGER_ENVIRONMENT"_s, IC::ExecutableTarget },
342
  { "VS_DEBUGGER_WORKING_DIRECTORY"_s, IC::ExecutableTarget },
343
  { "VS_USE_DEBUG_LIBRARIES"_s, IC::NonImportedTarget },
344
  // ---- OpenWatcom
345
  { "WATCOM_RUNTIME_LIBRARY"_s, IC::CanCompileSources },
346
  // ---- AIX
347
  { "AIX_SHARED_LIBRARY_ARCHIVE"_s, IC::SharedLibraryTarget },
348
  // -- Language
349
  // ---- C
350
  COMMON_LANGUAGE_PROPERTIES(C),
351
  // ---- C++
352
  COMMON_LANGUAGE_PROPERTIES(CXX),
353
  { "CXX_MODULE_STD"_s, IC::CanCompileSources },
354
  // ---- CSharp
355
  { "DOTNET_SDK"_s, IC::NonImportedTarget },
356
  { "DOTNET_TARGET_FRAMEWORK"_s, IC::TargetWithCommands },
357
  { "DOTNET_TARGET_FRAMEWORK_VERSION"_s, IC::TargetWithCommands },
358
  // ---- CUDA
359
  COMMON_LANGUAGE_PROPERTIES(CUDA),
360
  { "CUDA_SEPARABLE_COMPILATION"_s, IC::CanCompileSources },
361
  { "CUDA_ARCHITECTURES"_s, IC::CanCompileSources },
362
  // ---- Fortran
363
  { "Fortran_FORMAT"_s, IC::CanCompileSources },
364
  { "Fortran_MODULE_DIRECTORY"_s, IC::CanCompileSources },
365
  { "Fortran_COMPILER_LAUNCHER"_s, IC::CanCompileSources },
366
  { "Fortran_PREPROCESS"_s, IC::CanCompileSources },
367
  { "Fortran_VISIBILITY_PRESET"_s, IC::CanCompileSources },
368
  // ---- HIP
369
  COMMON_LANGUAGE_PROPERTIES(HIP),
370
  { "HIP_ARCHITECTURES"_s, IC::CanCompileSources },
371
  // ---- ISPC
372
  { "ISPC_COMPILER_LAUNCHER"_s, IC::CanCompileSources },
373
  { "ISPC_HEADER_DIRECTORY"_s, IC::CanCompileSources },
374
  { "ISPC_HEADER_SUFFIX"_s, "_ispc.h"_s, IC::CanCompileSources },
375
  { "ISPC_INSTRUCTION_SETS"_s, IC::CanCompileSources },
376
  // ---- Objective C
377
  COMMON_LANGUAGE_PROPERTIES(OBJC),
378
  // ---- Objective C++
379
  COMMON_LANGUAGE_PROPERTIES(OBJCXX),
380
  // ---- Swift
381
  { "Swift_LANGUAGE_VERSION"_s, IC::CanCompileSources },
382
  { "Swift_MODULE_DIRECTORY"_s, IC::CanCompileSources },
383
  { "Swift_COMPILATION_MODE"_s, IC::CanCompileSources },
384
  { "Swift_SEPARATE_MODULE_EMISSION"_s, IC::CanCompileSources },
385
  // ---- Rust
386
  { "Rust_EDITION"_s, IC::CanCompileSources },
387
  { "Rust_MAIN_CRATE_ROOT"_s, IC::CanCompileSources },
388
  // ---- moc
389
  { "AUTOMOC"_s, IC::CanCompileSources },
390
  { "AUTOMOC_COMPILER_PREDEFINES"_s, IC::CanCompileSources },
391
  { "AUTOMOC_INCLUDE_DIRECTORIES"_s, IC::CanCompileSources },
392
  { "AUTOMOC_MACRO_NAMES"_s, IC::CanCompileSources },
393
  { "AUTOMOC_MOC_OPTIONS"_s, IC::CanCompileSources },
394
  { "AUTOMOC_PATH_PREFIX"_s, IC::CanCompileSources },
395
  { "AUTOMOC_EXECUTABLE"_s, IC::CanCompileSources },
396
  // ---- uic
397
  { "AUTOUIC"_s, IC::CanCompileSources },
398
  { "AUTOUIC_OPTIONS"_s, IC::CanCompileSources },
399
  { "AUTOUIC_SEARCH_PATHS"_s, IC::CanCompileSources },
400
  { "AUTOUIC_EXECUTABLE"_s, IC::CanCompileSources },
401
  // ---- rcc
402
  { "AUTORCC"_s, IC::CanCompileSources },
403
  { "AUTORCC_OPTIONS"_s, IC::CanCompileSources },
404
  { "AUTORCC_EXECUTABLE"_s, IC::CanCompileSources },
405
406
  // Linking properties
407
  { "LINKER_TYPE"_s, IC::CanCompileSources },
408
  { "LINK_WARNING_AS_ERROR"_s, IC::CanCompileSources },
409
  { "ENABLE_EXPORTS"_s, IC::TargetWithSymbolExports },
410
  { "LINK_LIBRARIES_ONLY_TARGETS"_s, IC::NormalNonImportedTarget },
411
  { "LINK_LIBRARIES_STRATEGY"_s, IC::NormalNonImportedTarget },
412
  { "LINK_SEARCH_START_STATIC"_s, IC::CanCompileSources },
413
  { "LINK_SEARCH_END_STATIC"_s, IC::CanCompileSources },
414
  // Initialize per-configuration name postfix property from the variable only
415
  // for non-executable targets.  This preserves compatibility with previous
416
  // CMake versions in which executables did not support this variable.
417
  // Projects may still specify the property directly.
418
  { "_POSTFIX"_s, IC::NonExecutableWithArtifact, R::PerConfigPrefix },
419
  // -- Dependent library lookup
420
  { "MACOSX_RPATH"_s, IC::CanCompileSources },
421
  // ---- Build
422
  { "BUILD_RPATH"_s, IC::CanCompileSources },
423
  { "BUILD_RPATH_USE_ORIGIN"_s, IC::CanCompileSources },
424
  { "SKIP_BUILD_RPATH"_s, "OFF"_s, IC::CanCompileSources },
425
  { "BUILD_WITH_INSTALL_RPATH"_s, "OFF"_s, IC::CanCompileSources },
426
  { "BUILD_WITH_INSTALL_NAME_DIR"_s, IC::CanCompileSources },
427
  // ---- Install
428
  { "INSTALL_NAME_DIR"_s, IC::CanCompileSources },
429
  { "INSTALL_OBJECT_NAME_STRATEGY"_s, IC::CanCompileSources },
430
  { "INSTALL_OBJECT_ONLY_USE_DESTINATION"_s, IC::CanCompileSources },
431
  { "INSTALL_REMOVE_ENVIRONMENT_RPATH"_s, IC::CanCompileSources },
432
  { "INSTALL_RPATH"_s, ""_s, IC::CanCompileSources },
433
  { "INSTALL_RPATH_USE_LINK_PATH"_s, "OFF"_s, IC::CanCompileSources },
434
  // -- Platforms
435
  // ---- AIX
436
  { "AIX_EXPORT_ALL_SYMBOLS"_s, IC::TargetWithSymbolExports },
437
  // ---- Android
438
  { "ANDROID_GUI"_s, IC::ExecutableTarget },
439
  { "ANDROID_JAR_DIRECTORIES"_s, IC::CanCompileSources },
440
  { "ANDROID_JAR_DEPENDENCIES"_s, IC::CanCompileSources },
441
  { "ANDROID_NATIVE_LIB_DIRECTORIES"_s, IC::CanCompileSources },
442
  { "ANDROID_NATIVE_LIB_DEPENDENCIES"_s, IC::CanCompileSources },
443
  { "ANDROID_PROGUARD"_s, IC::CanCompileSources },
444
  { "ANDROID_PROGUARD_CONFIG_PATH"_s, IC::CanCompileSources },
445
  { "ANDROID_SECURE_PROPS_PATH"_s, IC::CanCompileSources },
446
  // ---- iOS
447
  { "IOS_INSTALL_COMBINED"_s, IC::CanCompileSources },
448
  // ---- macOS
449
  { "FRAMEWORK_MULTI_CONFIG_POSTFIX_"_s, IC::LinkableLibraryTarget, R::PerConfig },
450
  // ---- Windows
451
  { "DLL_NAME_WITH_SOVERSION"_s, IC::SharedLibraryTarget },
452
  { "GNUtoMS"_s, IC::CanCompileSources },
453
  { "WIN32_EXECUTABLE"_s, IC::CanCompileSources },
454
  { "WINDOWS_EXPORT_ALL_SYMBOLS"_s, IC::TargetWithSymbolExports },
455
  // -- Languages
456
  // ---- C
457
  { "C_LINKER_LAUNCHER"_s, IC::CanCompileSources },
458
  // ---- C++
459
  { "CXX_LINKER_LAUNCHER"_s, IC::CanCompileSources },
460
  // ---- CUDA
461
  { "CUDA_LINKER_LAUNCHER"_s, IC::CanCompileSources },
462
  { "CUDA_RESOLVE_DEVICE_SYMBOLS"_s, IC::CanCompileSources },
463
  { "CUDA_RUNTIME_LIBRARY"_s, IC::CanCompileSources },
464
  // ---- HIP
465
  { "HIP_LINKER_LAUNCHER"_s, IC::CanCompileSources },
466
  { "HIP_RUNTIME_LIBRARY"_s, IC::CanCompileSources },
467
  // ---- Objective C
468
  { "OBJC_LINKER_LAUNCHER"_s, IC::CanCompileSources },
469
  // ---- Objective C++
470
  { "OBJCXX_LINKER_LAUNCHER"_s, IC::CanCompileSources },
471
  // ---- Fortran
472
  { "Fortran_LINKER_LAUNCHER"_s, IC::CanCompileSources },
473
474
  // Static analysis
475
  { "SKIP_LINTING"_s, IC::CanCompileSources },
476
  // -- C
477
  { "C_CLANG_TIDY"_s, IC::CanCompileSources },
478
  { "C_CLANG_TIDY_EXPORT_FIXES_DIR"_s, IC::CanCompileSources },
479
  { "C_CPPLINT"_s, IC::CanCompileSources },
480
  { "C_CPPCHECK"_s, IC::CanCompileSources },
481
  { "C_ICSTAT"_s, IC::CanCompileSources },
482
  { "C_INCLUDE_WHAT_YOU_USE"_s, IC::CanCompileSources },
483
  { "C_PVS_STUDIO"_s, IC::CanCompileSources },
484
  // -- C++
485
  { "CXX_CLANG_TIDY"_s, IC::CanCompileSources },
486
  { "CXX_CLANG_TIDY_EXPORT_FIXES_DIR"_s, IC::CanCompileSources },
487
  { "CXX_CPPLINT"_s, IC::CanCompileSources },
488
  { "CXX_CPPCHECK"_s, IC::CanCompileSources },
489
  { "CXX_ICSTAT"_s, IC::CanCompileSources },
490
  { "CXX_INCLUDE_WHAT_YOU_USE"_s, IC::CanCompileSources },
491
  { "CXX_PVS_STUDIO"_s, IC::CanCompileSources },
492
  // -- Objective C
493
  { "OBJC_CLANG_TIDY"_s, IC::CanCompileSources },
494
  { "OBJC_CLANG_TIDY_EXPORT_FIXES_DIR"_s, IC::CanCompileSources },
495
  // -- Objective C++
496
  { "OBJCXX_CLANG_TIDY"_s, IC::CanCompileSources },
497
  { "OBJCXX_CLANG_TIDY_EXPORT_FIXES_DIR"_s, IC::CanCompileSources },
498
  // -- Linking
499
  { "LINK_WHAT_YOU_USE"_s, IC::CanCompileSources },
500
501
  // Build graph properties
502
  { "LINK_DEPENDS_NO_SHARED"_s, IC::CanCompileSources },
503
  { "UNITY_BUILD"_s, IC::CanCompileSources },
504
  { "UNITY_BUILD_UNIQUE_ID"_s, IC::CanCompileSources },
505
  { "UNITY_BUILD_BATCH_SIZE"_s, "8"_s, IC::CanCompileSources },
506
  { "UNITY_BUILD_MODE"_s, "BATCH"_s, IC::CanCompileSources },
507
  { "UNITY_BUILD_RELOCATABLE"_s, IC::CanCompileSources },
508
  { "OPTIMIZE_DEPENDENCIES"_s, IC::CanCompileSources },
509
  { "VERIFY_INTERFACE_HEADER_SETS"_s },
510
  { "VERIFY_PRIVATE_HEADER_SETS"_s },
511
  // -- Android
512
  { "ANDROID_ANT_ADDITIONAL_OPTIONS"_s, IC::CanCompileSources },
513
  { "ANDROID_PROCESS_MAX"_s, IC::CanCompileSources },
514
  { "ANDROID_SKIP_ANT_STEP"_s, IC::CanCompileSources },
515
  // -- Autogen
516
  { "AUTOGEN_COMMAND_LINE_LENGTH_MAX"_s, IC::CanCompileSources },
517
  { "AUTOGEN_ORIGIN_DEPENDS"_s, IC::CanCompileSources },
518
  { "AUTOGEN_PARALLEL"_s, IC::CanCompileSources },
519
  { "AUTOGEN_USE_SYSTEM_INCLUDE"_s, IC::CanCompileSources },
520
  { "AUTOGEN_BETTER_GRAPH_MULTI_CONFIG"_s, IC::CanCompileSources },
521
  // -- moc
522
  { "AUTOMOC_DEPEND_FILTERS"_s, IC::CanCompileSources },
523
  // -- C++
524
  { "CXX_SCAN_FOR_MODULES"_s, IC::CanCompileSources },
525
  // -- Ninja
526
  { "JOB_POOL_COMPILE"_s, IC::CanCompileSources },
527
  { "JOB_POOL_LINK"_s, IC::CanCompileSources },
528
  { "JOB_POOL_PRECOMPILE_HEADER"_s, IC::CanCompileSources },
529
  // -- Visual Studio
530
  { "VS_NO_COMPILE_BATCHING"_s, IC::CanCompileSources },
531
  { "VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION"_s, IC::CanCompileSources},
532
533
  // Output location properties
534
  { "ARCHIVE_OUTPUT_DIRECTORY"_s, IC::CanCompileSources },
535
  { "ARCHIVE_OUTPUT_DIRECTORY_"_s, IC::TargetWithArtifact, R::PerConfig },
536
  { "COMPILE_PDB_OUTPUT_DIRECTORY"_s, IC::CanCompileSources },
537
  { "COMPILE_PDB_OUTPUT_DIRECTORY_"_s, IC::TargetWithArtifact, R::PerConfig },
538
  { "LIBRARY_OUTPUT_DIRECTORY"_s, IC::CanCompileSources },
539
  { "LIBRARY_OUTPUT_DIRECTORY_"_s, IC::TargetWithArtifact, R::PerConfig },
540
  { "PDB_OUTPUT_DIRECTORY"_s, IC::CanCompileSources },
541
  { "PDB_OUTPUT_DIRECTORY_"_s, IC::TargetWithArtifact, R::PerConfig },
542
  { "RUNTIME_OUTPUT_DIRECTORY"_s, IC::CanCompileSources },
543
  { "RUNTIME_OUTPUT_DIRECTORY_"_s, IC::TargetWithArtifact, R::PerConfig },
544
545
  // macOS bundle properties
546
  { "FRAMEWORK"_s, IC::CanCompileSources },
547
  { "FRAMEWORK_MULTI_CONFIG_POSTFIX"_s, IC::CanCompileSources },
548
  { "MACOSX_BUNDLE"_s, IC::CanCompileSources },
549
550
  // Usage requirement properties
551
  { "LINK_INTERFACE_LIBRARIES"_s, IC::CanCompileSources },
552
  { "MAP_IMPORTED_CONFIG_"_s, IC::NormalTarget, R::PerConfig },
553
  { "EXPORT_FIND_PACKAGE_NAME"_s, IC::NormalTarget },
554
555
  // Metadata
556
  { "CROSSCOMPILING_EMULATOR"_s, IC::ExecutableTarget },
557
  { "EXPORT_BUILD_DATABASE"_s, IC::CanCompileSources },
558
  { "EXPORT_COMPILE_COMMANDS"_s, IC::CanCompileSources },
559
  { "FOLDER"_s },
560
  { "TEST_LAUNCHER"_s, IC::ExecutableTarget },
561
562
  // Xcode properties
563
  { "XCODE_GENERATE_SCHEME"_s, IC::NeedsXcode },
564
565
#ifdef __APPLE__
566
  { "XCODE_SCHEME_ADDRESS_SANITIZER"_s, IC::NeedsXcodeAndCanCompileSources },
567
  { "XCODE_SCHEME_ADDRESS_SANITIZER_USE_AFTER_RETURN"_s, IC::NeedsXcodeAndCanCompileSources },
568
  { "XCODE_SCHEME_DEBUG_DOCUMENT_VERSIONING"_s, IC::NeedsXcodeAndCanCompileSources },
569
  { "XCODE_SCHEME_ENABLE_GPU_FRAME_CAPTURE_MODE"_s, IC::NeedsXcodeAndCanCompileSources },
570
  { "XCODE_SCHEME_THREAD_SANITIZER"_s, IC::NeedsXcodeAndCanCompileSources },
571
  { "XCODE_SCHEME_THREAD_SANITIZER_STOP"_s, IC::NeedsXcodeAndCanCompileSources },
572
  { "XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER"_s, IC::NeedsXcodeAndCanCompileSources },
573
  { "XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER_STOP"_s, IC::NeedsXcodeAndCanCompileSources },
574
  { "XCODE_SCHEME_LAUNCH_CONFIGURATION"_s, IC::NeedsXcodeAndCanCompileSources },
575
  { "XCODE_SCHEME_TEST_CONFIGURATION"_s, IC::NeedsXcodeAndCanCompileSources },
576
  { "XCODE_SCHEME_ENABLE_GPU_API_VALIDATION"_s, IC::NeedsXcodeAndCanCompileSources },
577
  { "XCODE_SCHEME_ENABLE_GPU_SHADER_VALIDATION"_s, IC::NeedsXcodeAndCanCompileSources },
578
  { "XCODE_SCHEME_WORKING_DIRECTORY"_s, IC::NeedsXcodeAndCanCompileSources },
579
  { "XCODE_SCHEME_DISABLE_MAIN_THREAD_CHECKER"_s, IC::NeedsXcodeAndCanCompileSources },
580
  { "XCODE_SCHEME_MAIN_THREAD_CHECKER_STOP"_s, IC::NeedsXcodeAndCanCompileSources },
581
  { "XCODE_SCHEME_MALLOC_SCRIBBLE"_s, IC::NeedsXcodeAndCanCompileSources },
582
  { "XCODE_SCHEME_MALLOC_GUARD_EDGES"_s, IC::NeedsXcodeAndCanCompileSources },
583
  { "XCODE_SCHEME_GUARD_MALLOC"_s, IC::NeedsXcodeAndCanCompileSources },
584
  { "XCODE_SCHEME_LAUNCH_MODE"_s, IC::NeedsXcodeAndCanCompileSources },
585
  { "XCODE_SCHEME_LLDB_INIT_FILE"_s, IC::NeedsXcodeAndCanCompileSources },
586
  { "XCODE_SCHEME_ZOMBIE_OBJECTS"_s, IC::NeedsXcodeAndCanCompileSources },
587
  { "XCODE_SCHEME_MALLOC_STACK"_s, IC::NeedsXcodeAndCanCompileSources },
588
  { "XCODE_SCHEME_DYNAMIC_LINKER_API_USAGE"_s, IC::NeedsXcodeAndCanCompileSources },
589
  { "XCODE_SCHEME_DYNAMIC_LIBRARY_LOADS"_s, IC::NeedsXcodeAndCanCompileSources },
590
  { "XCODE_SCHEME_ENVIRONMENT"_s, IC::NeedsXcodeAndCanCompileSources },
591
  { "XCODE_LINK_BUILD_PHASE_MODE"_s, "NONE"_s, IC::NeedsXcodeAndCanCompileSources },
592
#endif
593
  /* clang-format on */
594
};
595
596
#undef COMMON_LANGUAGE_PROPERTIES
597
#undef IC
598
#undef R
599
}
600
601
class cmTargetInternals
602
{
603
public:
604
  cmStateEnums::TargetType TargetType;
605
  cmTarget::Origin Origin = cmTarget::Origin::Unknown;
606
  cmMakefile* Makefile;
607
  cmPolicies::PolicyMap PolicyMap;
608
  cmTarget const* TemplateTarget;
609
  std::string Name;
610
  std::string InstallPath;
611
  std::string RuntimeInstallPath;
612
  cmPropertyMap Properties;
613
  bool IsGeneratorProvided;
614
  bool HaveInstallRule;
615
  bool IsDLLPlatform;
616
  bool IsAIX;
617
  bool IsApple;
618
  bool IsAndroid;
619
  bool BuildInterfaceIncludesAppended;
620
  bool PerConfig;
621
  bool IsSymbolic;
622
  bool IsForTryCompile{ false };
623
  cmTarget::Visibility TargetVisibility;
624
  std::set<BT<std::pair<std::string, bool>>> Utilities;
625
  std::set<std::string> CodegenDependencies;
626
  std::vector<cmCustomCommand> PreBuildCommands;
627
  std::vector<cmCustomCommand> PreLinkCommands;
628
  std::vector<cmCustomCommand> PostBuildCommands;
629
  std::vector<cmInstallTargetGenerator*> InstallGenerators;
630
  std::set<std::string> SystemIncludeDirectories;
631
  cmTarget::LinkLibraryVectorType OriginalLinkLibraries;
632
  std::map<std::string, BTs<std::string>> LanguageStandardProperties;
633
  std::map<cmTargetExport const*, std::vector<std::string>>
634
    InstallIncludeDirectoriesEntries;
635
  std::vector<std::pair<cmTarget::TLLSignature, cmListFileContext>>
636
    TLLCommands;
637
  std::map<std::string, cmFileSet> FileSets;
638
  cmListFileBacktrace Backtrace;
639
  cmFindPackageStack FindPackageStack;
640
641
  UsageRequirementProperty IncludeDirectories;
642
  UsageRequirementProperty CompileOptions;
643
  UsageRequirementProperty CompileFeatures;
644
  UsageRequirementProperty CompileDefinitions;
645
  UsageRequirementProperty PrecompileHeaders;
646
  UsageRequirementProperty Sources;
647
  UsageRequirementProperty LinkOptions;
648
  UsageRequirementProperty LinkDirectories;
649
  UsageRequirementProperty LinkLibraries;
650
  UsageRequirementProperty InterfaceLinkLibraries;
651
  UsageRequirementProperty InterfaceLinkLibrariesDirect;
652
  UsageRequirementProperty InterfaceLinkLibrariesDirectExclude;
653
  UsageRequirementProperty ImportedCxxModulesIncludeDirectories;
654
  UsageRequirementProperty ImportedCxxModulesCompileDefinitions;
655
  UsageRequirementProperty ImportedCxxModulesCompileFeatures;
656
  UsageRequirementProperty ImportedCxxModulesCompileOptions;
657
  UsageRequirementProperty ImportedCxxModulesLinkLibraries;
658
659
  std::unordered_map<cm::string_view, FileSetType> FileSetTypes;
660
661
  cmTargetInternals();
662
663
  bool IsImported() const;
664
665
  bool CheckImportedLibName(std::string const& prop,
666
                            std::string const& value) const;
667
668
  template <typename ValueType>
669
  void AddDirectoryToFileSet(cmTarget* self, std::string const& fileSetName,
670
                             ValueType value, cm::string_view fileSetType,
671
                             cm::string_view description,
672
                             FileSetType::Action action);
673
  template <typename ValueType>
674
  void AddPathToFileSet(cmTarget* self, std::string const& fileSetName,
675
                        ValueType value, cm::string_view fileSetType,
676
                        cm::string_view description,
677
                        FileSetType::Action action);
678
  cmValue GetFileSetDirectories(cmTarget const* self,
679
                                std::string const& fileSetName,
680
                                cm::string_view fileSetType) const;
681
  cmValue GetFileSetPaths(cmTarget const* self, std::string const& fileSetName,
682
                          cm::string_view fileSetType) const;
683
684
  cmListFileBacktrace GetBacktrace(
685
    cm::optional<cmListFileBacktrace> const& bt) const
686
0
  {
687
0
    return bt ? *bt : this->Makefile->GetBacktrace();
688
0
  }
689
};
690
691
cmTargetInternals::cmTargetInternals()
692
0
  : IncludeDirectories("INCLUDE_DIRECTORIES"_s)
693
0
  , CompileOptions("COMPILE_OPTIONS"_s)
694
0
  , CompileFeatures("COMPILE_FEATURES"_s)
695
0
  , CompileDefinitions("COMPILE_DEFINITIONS"_s)
696
0
  , PrecompileHeaders("PRECOMPILE_HEADERS"_s)
697
0
  , Sources("SOURCES"_s, UsageRequirementProperty::AppendEmpty::Yes)
698
0
  , LinkOptions("LINK_OPTIONS"_s)
699
0
  , LinkDirectories("LINK_DIRECTORIES"_s)
700
0
  , LinkLibraries("LINK_LIBRARIES"_s)
701
0
  , InterfaceLinkLibraries("INTERFACE_LINK_LIBRARIES"_s)
702
0
  , InterfaceLinkLibrariesDirect("INTERFACE_LINK_LIBRARIES_DIRECT"_s)
703
0
  , InterfaceLinkLibrariesDirectExclude(
704
0
      "INTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE"_s)
705
0
  , ImportedCxxModulesIncludeDirectories(
706
0
      "IMPORTED_CXX_MODULES_INCLUDE_DIRECTORIES"_s)
707
0
  , ImportedCxxModulesCompileDefinitions(
708
0
      "IMPORTED_CXX_MODULES_COMPILE_DEFINITIONS"_s)
709
0
  , ImportedCxxModulesCompileFeatures(
710
0
      "IMPORTED_CXX_MODULES_COMPILE_FEATURES"_s)
711
0
  , ImportedCxxModulesCompileOptions("IMPORTED_CXX_MODULES_COMPILE_OPTIONS"_s)
712
0
  , ImportedCxxModulesLinkLibraries("IMPORTED_CXX_MODULES_LINK_LIBRARIES"_s)
713
0
  , FileSetTypes{ { cm::FileSetMetadata::HEADERS,
714
0
                    { cm::FileSetMetadata::HEADERS, "HEADER_DIRS"_s,
715
0
                      "HEADER_SET"_s, "HEADER_DIRS_"_s, "HEADER_SET_"_s,
716
0
                      "Header"_s, "The default header set"_s, "Header set"_s,
717
0
                      FileSetEntries{ "HEADER_SETS"_s },
718
0
                      FileSetEntries{ "INTERFACE_HEADER_SETS"_s } } },
719
0
                  { cm::FileSetMetadata::SOURCES,
720
0
                    { cm::FileSetMetadata::SOURCES, "SOURCE_DIRS"_s,
721
0
                      "SOURCE_SET"_s, "SOURCE_DIRS_"_s, "SOURCE_SET_"_s,
722
0
                      "Source"_s, "The default source set"_s, "Source set"_s,
723
0
                      FileSetEntries{ "SOURCE_SETS"_s },
724
0
                      FileSetEntries{ "INTERFACE_SOURCE_SETS"_s } } },
725
0
                  { cm::FileSetMetadata::CXX_MODULES,
726
0
                    { cm::FileSetMetadata::CXX_MODULES, "CXX_MODULE_DIRS"_s,
727
0
                      "CXX_MODULE_SET"_s, "CXX_MODULE_DIRS_"_s,
728
0
                      "CXX_MODULE_SET_"_s, "C++ module"_s,
729
0
                      "The default C++ module set"_s, "C++ module set"_s,
730
0
                      FileSetEntries{ "CXX_MODULE_SETS"_s },
731
0
                      FileSetEntries{ "INTERFACE_CXX_MODULE_SETS"_s } } } }
732
0
{
733
0
}
734
735
template <typename ValueType>
736
bool FileSetType::WriteProperties(cmTarget* tgt, cmTargetInternals* impl,
737
                                  std::string const& prop, ValueType value,
738
                                  Action action)
739
0
{
740
0
  if (prop == this->DefaultDirectoryProperty) {
741
0
    impl->AddDirectoryToFileSet(tgt, std::string(this->TypeName), value,
742
0
                                this->TypeName, this->DefaultDescription,
743
0
                                action);
744
0
    return true;
745
0
  }
746
0
  if (prop == this->DefaultPathProperty) {
747
0
    impl->AddPathToFileSet(tgt, std::string(this->TypeName), value,
748
0
                           this->TypeName, this->DefaultDescription, action);
749
0
    return true;
750
0
  }
751
0
  if (cmHasPrefix(prop, this->DirectoryPrefix)) {
752
0
    auto fileSetName = prop.substr(this->DirectoryPrefix.size());
753
0
    if (fileSetName.empty()) {
754
0
      impl->Makefile->IssueMessage(
755
0
        MessageType::FATAL_ERROR,
756
0
        cmStrCat(this->ArbitraryDescription, " name cannot be empty."));
757
0
    } else {
758
0
      impl->AddDirectoryToFileSet(
759
0
        tgt, fileSetName, value, this->TypeName,
760
0
        cmStrCat(this->ArbitraryDescription, " \"", fileSetName, '"'), action);
761
0
    }
762
0
    return true;
763
0
  }
764
0
  if (cmHasPrefix(prop, this->PathPrefix)) {
765
0
    auto fileSetName = prop.substr(this->PathPrefix.size());
766
0
    if (fileSetName.empty()) {
767
0
      impl->Makefile->IssueMessage(
768
0
        MessageType::FATAL_ERROR,
769
0
        cmStrCat(this->ArbitraryDescription, " name cannot be empty."));
770
0
    } else {
771
0
      impl->AddPathToFileSet(
772
0
        tgt, fileSetName, value, this->TypeName,
773
0
        cmStrCat(this->ArbitraryDescription, " \"", fileSetName, '"'), action);
774
0
    }
775
0
    return true;
776
0
  }
777
0
  return false;
778
0
}
Unexecuted instantiation: cmTarget.cxx:bool (anonymous namespace)::FileSetType::WriteProperties<cmValue>(cmTarget*, cmTargetInternals*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cmValue, (anonymous namespace)::FileSetType::Action)
Unexecuted instantiation: cmTarget.cxx:bool (anonymous namespace)::FileSetType::WriteProperties<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(cmTarget*, cmTargetInternals*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, (anonymous namespace)::FileSetType::Action)
779
780
std::pair<bool, cmValue> FileSetType::ReadProperties(
781
  cmTarget const* tgt, cmTargetInternals const* impl,
782
  std::string const& prop) const
783
0
{
784
0
  bool did_read = false;
785
0
  cmValue value = nullptr;
786
0
  if (prop == this->DefaultDirectoryProperty) {
787
0
    value = impl->GetFileSetDirectories(tgt, std::string(this->TypeName),
788
0
                                        this->TypeName);
789
0
    did_read = true;
790
0
  } else if (prop == this->DefaultPathProperty) {
791
0
    value =
792
0
      impl->GetFileSetPaths(tgt, std::string(this->TypeName), this->TypeName);
793
0
    did_read = true;
794
0
  } else if (prop == this->SelfEntries.PropertyName) {
795
0
    static std::string output;
796
0
    output = cmList::to_string(this->SelfEntries.Entries);
797
0
    value = cmValue(output);
798
0
    did_read = true;
799
0
  } else if (prop == this->InterfaceEntries.PropertyName) {
800
0
    static std::string output;
801
0
    output = cmList::to_string(this->InterfaceEntries.Entries);
802
0
    value = cmValue(output);
803
0
    did_read = true;
804
0
  } else if (cmHasPrefix(prop, this->DirectoryPrefix)) {
805
0
    std::string fileSetName = prop.substr(this->DirectoryPrefix.size());
806
0
    if (!fileSetName.empty()) {
807
0
      value = impl->GetFileSetDirectories(tgt, fileSetName, this->TypeName);
808
0
    }
809
0
    did_read = true;
810
0
  } else if (cmHasPrefix(prop, this->PathPrefix)) {
811
0
    std::string fileSetName = prop.substr(this->PathPrefix.size());
812
0
    if (!fileSetName.empty()) {
813
0
      value = impl->GetFileSetPaths(tgt, fileSetName, this->TypeName);
814
0
    }
815
0
    did_read = true;
816
0
  }
817
0
  return { did_read, value };
818
0
}
819
820
void FileSetType::AddFileSet(std::string const& name,
821
                             cm::FileSetMetadata::Visibility vis,
822
                             cmListFileBacktrace bt)
823
0
{
824
0
  if (cm::FileSetMetadata::VisibilityIsForSelf(vis)) {
825
0
    this->SelfEntries.Entries.emplace_back(name, bt);
826
0
  }
827
0
  if (cm::FileSetMetadata::VisibilityIsForInterface(vis)) {
828
0
    this->InterfaceEntries.Entries.emplace_back(name, std::move(bt));
829
0
  }
830
0
}
831
832
template <typename ValueType>
833
bool UsageRequirementProperty::Write(
834
  cmTargetInternals const* impl, cm::optional<cmListFileBacktrace> const& bt,
835
  std::string const& prop, ValueType value, Action action)
836
0
{
837
0
  if (prop == this->Name) {
838
0
    this->WriteDirect(impl, bt, value, action);
839
0
    return true;
840
0
  }
841
0
  return false;
842
0
}
843
844
template <typename ValueType>
845
void UsageRequirementProperty::WriteDirect(
846
  cmTargetInternals const* impl, cm::optional<cmListFileBacktrace> const& bt,
847
  ValueType value, Action action)
848
0
{
849
0
  if (action == Action::Set) {
850
0
    this->Entries.clear();
851
0
  }
852
0
  if (value) {
853
0
    cmListFileBacktrace lfbt = impl->GetBacktrace(bt);
854
0
    if (action == Action::Prepend) {
855
0
      this->Entries.emplace(this->Entries.begin(), value, lfbt);
856
0
    } else if (action == Action::Set || cmNonempty(value) ||
857
0
               this->AppendBehavior == AppendEmpty::Yes) {
858
0
      this->Entries.emplace_back(value, lfbt);
859
0
    }
860
0
  }
861
0
}
862
863
void UsageRequirementProperty::WriteDirect(BT<std::string> value,
864
                                           Action action)
865
0
{
866
0
  if (action == Action::Set) {
867
0
    this->Entries.clear();
868
0
  }
869
0
  if (action == Action::Prepend) {
870
0
    this->Entries.emplace(this->Entries.begin(), std::move(value));
871
0
  } else {
872
0
    this->Entries.emplace_back(std::move(value));
873
0
  }
874
0
}
875
876
std::pair<bool, cmValue> UsageRequirementProperty::Read(
877
  std::string const& prop) const
878
0
{
879
0
  bool did_read = false;
880
0
  cmValue value = nullptr;
881
0
  if (prop == this->Name) {
882
0
    if (!this->Entries.empty()) {
883
      // Storage to back the returned `cmValue`.
884
0
      static std::string output;
885
0
      output = cmList::to_string(this->Entries);
886
0
      value = cmValue(output);
887
0
    }
888
0
    did_read = true;
889
0
  }
890
0
  return { did_read, value };
891
0
}
892
893
cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
894
                   Visibility vis, cmMakefile* mf, PerConfig perConfig)
895
0
  : impl(cm::make_unique<cmTargetInternals>())
896
0
{
897
0
  assert(mf);
898
0
  this->impl->TargetType = type;
899
0
  this->impl->Makefile = mf;
900
0
  this->impl->Name = name;
901
0
  this->impl->TemplateTarget = nullptr;
902
0
  this->impl->IsGeneratorProvided = false;
903
0
  this->impl->HaveInstallRule = false;
904
0
  this->impl->IsDLLPlatform = false;
905
0
  this->impl->IsAIX = false;
906
0
  this->impl->IsApple = false;
907
0
  this->impl->IsAndroid = false;
908
0
  this->impl->IsSymbolic = false;
909
0
  this->impl->TargetVisibility = vis;
910
0
  this->impl->BuildInterfaceIncludesAppended = false;
911
0
  this->impl->PerConfig = (perConfig == PerConfig::Yes);
912
913
  // Check whether this is a DLL platform.
914
0
  this->impl->IsDLLPlatform =
915
0
    !this->impl->Makefile->GetSafeDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")
916
0
       .empty();
917
918
  // Check whether we are targeting AIX.
919
0
  {
920
0
    std::string const& systemName =
921
0
      this->impl->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME");
922
0
    this->impl->IsAIX = (systemName == "AIX" || systemName == "OS400");
923
0
  }
924
925
  // Check whether we are targeting Apple.
926
0
  this->impl->IsApple = this->impl->Makefile->IsOn("APPLE");
927
928
  // Check whether we are targeting an Android platform.
929
0
  this->impl->IsAndroid = (this->impl->Makefile->GetSafeDefinition(
930
0
                             "CMAKE_SYSTEM_NAME") == "Android");
931
932
  // Save the backtrace of target construction.
933
0
  this->impl->Backtrace = this->impl->Makefile->GetBacktrace();
934
0
  if (this->impl->IsImported()) {
935
0
    this->impl->FindPackageStack = this->impl->Makefile->GetFindPackageStack();
936
0
  }
937
938
0
  if (this->IsNormal()) {
939
    // Initialize the INCLUDE_DIRECTORIES property based on the current value
940
    // of the same directory property:
941
0
    this->impl->IncludeDirectories.CopyFromEntries(
942
0
      this->impl->Makefile->GetIncludeDirectoriesEntries());
943
944
0
    {
945
0
      auto const& sysInc = this->impl->Makefile->GetSystemIncludeDirectories();
946
0
      this->impl->SystemIncludeDirectories.insert(sysInc.begin(),
947
0
                                                  sysInc.end());
948
0
    }
949
950
0
    this->impl->CompileOptions.CopyFromEntries(
951
0
      this->impl->Makefile->GetCompileOptionsEntries());
952
0
    this->impl->LinkOptions.CopyFromEntries(
953
0
      this->impl->Makefile->GetLinkOptionsEntries());
954
0
    this->impl->LinkDirectories.CopyFromEntries(
955
0
      this->impl->Makefile->GetLinkDirectoriesEntries());
956
0
  }
957
958
  // Record current policies for later use.
959
0
  this->impl->Makefile->RecordPolicies(this->impl->PolicyMap);
960
961
0
  std::set<TargetProperty::InitCondition> metConditions;
962
0
  metConditions.insert(TargetProperty::InitCondition::Always);
963
0
  if (this->CanCompileSources()) {
964
0
    metConditions.insert(TargetProperty::InitCondition::CanCompileSources);
965
0
  }
966
0
  if (this->GetGlobalGenerator()->IsXcode()) {
967
0
    metConditions.insert(TargetProperty::InitCondition::NeedsXcode);
968
0
    if (this->CanCompileSources()) {
969
0
      metConditions.insert(
970
0
        TargetProperty::InitCondition::NeedsXcodeAndCanCompileSources);
971
0
    }
972
0
  }
973
0
  if (!this->IsImported()) {
974
0
    metConditions.insert(TargetProperty::InitCondition::NonImportedTarget);
975
0
  }
976
0
  if (this->impl->TargetType != cmStateEnums::UTILITY &&
977
0
      this->impl->TargetType != cmStateEnums::GLOBAL_TARGET) {
978
0
    metConditions.insert(TargetProperty::InitCondition::NormalTarget);
979
0
    if (this->IsNormal()) {
980
0
      metConditions.insert(
981
0
        TargetProperty::InitCondition::NormalNonImportedTarget);
982
0
    }
983
0
    if (this->impl->TargetType != cmStateEnums::INTERFACE_LIBRARY) {
984
0
      metConditions.insert(TargetProperty::InitCondition::TargetWithArtifact);
985
0
      if (this->impl->TargetType != cmStateEnums::EXECUTABLE) {
986
0
        metConditions.insert(
987
0
          TargetProperty::InitCondition::NonExecutableWithArtifact);
988
0
      }
989
0
    }
990
0
    if (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
991
0
        this->impl->TargetType == cmStateEnums::STATIC_LIBRARY) {
992
0
      metConditions.insert(
993
0
        TargetProperty::InitCondition::LinkableLibraryTarget);
994
0
    }
995
0
    if (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY) {
996
0
      metConditions.insert(TargetProperty::InitCondition::SharedLibraryTarget);
997
0
    }
998
0
  }
999
0
  if (this->impl->TargetType == cmStateEnums::EXECUTABLE) {
1000
0
    metConditions.insert(TargetProperty::InitCondition::ExecutableTarget);
1001
0
  }
1002
0
  if (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
1003
0
      this->impl->TargetType == cmStateEnums::EXECUTABLE) {
1004
0
    metConditions.insert(
1005
0
      TargetProperty::InitCondition::TargetWithSymbolExports);
1006
0
  }
1007
0
  if (this->impl->TargetType <= cmStateEnums::GLOBAL_TARGET) {
1008
0
    metConditions.insert(TargetProperty::InitCondition::TargetWithCommands);
1009
0
  }
1010
1011
0
  std::vector<std::string> configNames =
1012
0
    mf->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig);
1013
0
  for (auto& config : configNames) {
1014
0
    config = cmSystemTools::UpperCase(config);
1015
0
  }
1016
1017
0
  std::string defKey;
1018
0
  defKey.reserve(128);
1019
0
  defKey += "CMAKE_";
1020
0
  auto initProperty = [this, mf, &defKey](std::string const& property,
1021
0
                                          char const* default_value) {
1022
    // special init for ENABLE_EXPORTS
1023
    // For SHARED_LIBRARY, only CMAKE_SHARED_LIBRARY_ENABLE_EXPORTS variable
1024
    // is used
1025
    // For EXECUTABLE, CMAKE_EXECUTABLE_ENABLE_EXPORTS or else
1026
    // CMAKE_ENABLE_EXPORTS variables are used
1027
0
    if (property == "ENABLE_EXPORTS"_s) {
1028
      // Replace everything after "CMAKE_"
1029
0
      defKey.replace(
1030
0
        defKey.begin() + 6, defKey.end(),
1031
0
        cmStrCat(this->impl->TargetType == cmStateEnums::EXECUTABLE
1032
0
                   ? "EXECUTABLE"
1033
0
                   : "SHARED_LIBRARY",
1034
0
                 '_', property));
1035
0
      if (cmValue value = mf->GetDefinition(defKey)) {
1036
0
        this->SetProperty(property, value);
1037
0
        return;
1038
0
      }
1039
0
      if (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY) {
1040
0
        if (default_value) {
1041
0
          this->SetProperty(property, default_value);
1042
0
        }
1043
0
        return;
1044
0
      }
1045
0
    }
1046
1047
    // Imported targets must set AIX_SHARED_LIBRARY_ARCHIVE explicitly.
1048
0
    if (this->IsImported() && property == "AIX_SHARED_LIBRARY_ARCHIVE"_s) {
1049
0
      return;
1050
0
    }
1051
1052
    // Replace everything after "CMAKE_"
1053
0
    defKey.replace(defKey.begin() + 6, defKey.end(), property);
1054
0
    if (cmValue value = mf->GetDefinition(defKey)) {
1055
0
      this->SetProperty(property, value);
1056
0
    } else if (default_value) {
1057
0
      this->SetProperty(property, default_value);
1058
0
    }
1059
0
  };
1060
1061
0
  std::string dflt_storage;
1062
0
  for (auto const& tp : StaticTargetProperties) {
1063
    // Ignore properties that we have not met the condition for.
1064
0
    if (!metConditions.count(tp.InitConditional)) {
1065
0
      continue;
1066
0
    }
1067
1068
0
    char const* dflt = nullptr;
1069
0
    if (tp.Default) {
1070
0
      dflt_storage = std::string(*tp.Default);
1071
0
      dflt = dflt_storage.c_str();
1072
0
    }
1073
1074
0
    if (tp.Repeat == TargetProperty::Repetition::Once) {
1075
0
      initProperty(std::string(tp.Name), dflt);
1076
0
    } else {
1077
0
      std::string propertyName;
1078
0
      for (auto const& configName : configNames) {
1079
0
        if (tp.Repeat == TargetProperty::Repetition::PerConfig) {
1080
0
          propertyName = cmStrCat(tp.Name, configName);
1081
0
        } else if (tp.Repeat == TargetProperty::Repetition::PerConfigPrefix) {
1082
0
          propertyName = cmStrCat(configName, tp.Name);
1083
0
        }
1084
0
        initProperty(propertyName, dflt);
1085
0
      }
1086
0
    }
1087
0
  }
1088
1089
  // Clean up some property defaults.
1090
0
  if (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
1091
0
      this->impl->TargetType == cmStateEnums::MODULE_LIBRARY) {
1092
0
    this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
1093
0
  }
1094
1095
  // check for "CMAKE_VS_GLOBALS" variable and set up target properties
1096
  // if any
1097
0
  cmValue globals = mf->GetDefinition("CMAKE_VS_GLOBALS");
1098
0
  if (globals) {
1099
0
    std::string const genName = mf->GetGlobalGenerator()->GetName();
1100
0
    if (cmHasLiteralPrefix(genName, "Visual Studio")) {
1101
0
      cmList props{ *globals };
1102
0
      std::string const vsGlobal = "VS_GLOBAL_";
1103
0
      for (std::string const& i : props) {
1104
        // split NAME=VALUE
1105
0
        std::string::size_type const assignment = i.find('=');
1106
0
        if (assignment != std::string::npos) {
1107
0
          std::string const propName = vsGlobal + i.substr(0, assignment);
1108
0
          std::string const propValue = i.substr(assignment + 1);
1109
0
          initProperty(propName, propValue.c_str());
1110
0
        }
1111
0
      }
1112
0
    }
1113
0
  }
1114
1115
0
  if (!this->IsNormal() || mf->GetPropertyAsBool("SYSTEM")) {
1116
0
    this->SetProperty("SYSTEM", "ON");
1117
0
  }
1118
1119
0
  for (auto const& prop : mf->GetState()->GetPropertyDefinitions().GetMap()) {
1120
0
    auto iter = prop.second.find(cmProperty::TARGET);
1121
0
    if (iter != prop.second.end()) {
1122
0
      if (!iter->second.GetInitializeFromVariable().empty()) {
1123
0
        if (auto value =
1124
0
              mf->GetDefinition(iter->second.GetInitializeFromVariable())) {
1125
0
          this->SetProperty(prop.first, value);
1126
0
        }
1127
0
      }
1128
0
    }
1129
0
  }
1130
0
}
1131
1132
0
cmTarget::cmTarget(cmTarget&&) noexcept = default;
1133
0
cmTarget::~cmTarget() = default;
1134
1135
0
cmTarget& cmTarget::operator=(cmTarget&&) noexcept = default;
1136
1137
cmStateEnums::TargetType cmTarget::GetType() const
1138
0
{
1139
0
  return this->impl->TargetType;
1140
0
}
1141
1142
void cmTarget::SetOrigin(Origin origin)
1143
0
{
1144
0
  assert(origin != cmTarget::Origin::Unknown);
1145
0
  assert(this->impl->Origin == cmTarget::Origin::Unknown);
1146
0
  this->impl->Origin = origin;
1147
0
}
1148
1149
cmTarget::Origin cmTarget::GetOrigin() const
1150
0
{
1151
0
  return this->impl->Origin;
1152
0
}
1153
1154
cmMakefile* cmTarget::GetMakefile() const
1155
0
{
1156
0
  return this->impl->Makefile;
1157
0
}
1158
1159
cmPolicies::PolicyMap const& cmTarget::GetPolicyMap() const
1160
0
{
1161
0
  return this->impl->PolicyMap;
1162
0
}
1163
1164
std::string const& cmTarget::GetName() const
1165
0
{
1166
0
  return this->impl->Name;
1167
0
}
1168
1169
std::string const& cmTarget::GetTemplateName() const
1170
0
{
1171
0
  if (this->impl->TemplateTarget) {
1172
0
    return this->impl->TemplateTarget->GetTemplateName();
1173
0
  }
1174
0
  return this->impl->Name;
1175
0
}
1176
1177
cmPolicies::PolicyStatus cmTarget::GetPolicyStatus(
1178
  cmPolicies::PolicyID policy) const
1179
0
{
1180
0
  return this->impl->PolicyMap.Get(policy);
1181
0
}
1182
1183
cmGlobalGenerator* cmTarget::GetGlobalGenerator() const
1184
0
{
1185
0
  return this->impl->Makefile->GetGlobalGenerator();
1186
0
}
1187
1188
BTs<std::string> const* cmTarget::GetLanguageStandardProperty(
1189
  std::string const& propertyName) const
1190
0
{
1191
0
  auto entry = this->impl->LanguageStandardProperties.find(propertyName);
1192
0
  if (entry != this->impl->LanguageStandardProperties.end()) {
1193
0
    return &entry->second;
1194
0
  }
1195
1196
0
  return nullptr;
1197
0
}
1198
1199
void cmTarget::SetLanguageStandardProperty(std::string const& lang,
1200
                                           std::string const& value,
1201
                                           std::string const& feature)
1202
0
{
1203
0
  cmListFileBacktrace featureBacktrace;
1204
0
  for (auto const& entry : this->impl->CompileFeatures.Entries) {
1205
0
    if (entry.Value == feature) {
1206
0
      featureBacktrace = entry.Backtrace;
1207
0
      break;
1208
0
    }
1209
0
  }
1210
1211
0
  BTs<std::string>& languageStandardProperty =
1212
0
    this->impl->LanguageStandardProperties[cmStrCat(lang, "_STANDARD")];
1213
0
  if (languageStandardProperty.Value != value) {
1214
0
    languageStandardProperty.Value = value;
1215
0
    languageStandardProperty.Backtraces.clear();
1216
0
  }
1217
0
  languageStandardProperty.Backtraces.emplace_back(featureBacktrace);
1218
0
}
1219
1220
void cmTarget::AddUtility(std::string const& name, bool cross,
1221
                          cmMakefile const* mf)
1222
0
{
1223
0
  this->impl->Utilities.insert(BT<std::pair<std::string, bool>>(
1224
0
    { name, cross }, mf ? mf->GetBacktrace() : cmListFileBacktrace()));
1225
0
}
1226
1227
void cmTarget::AddUtility(BT<std::pair<std::string, bool>> util)
1228
0
{
1229
0
  this->impl->Utilities.emplace(std::move(util));
1230
0
}
1231
1232
void cmTarget::AddCodegenDependency(std::string const& name)
1233
0
{
1234
0
  this->impl->CodegenDependencies.emplace(name);
1235
0
}
1236
1237
std::set<std::string> const& cmTarget::GetCodegenDeps() const
1238
0
{
1239
0
  return this->impl->CodegenDependencies;
1240
0
}
1241
1242
std::set<BT<std::pair<std::string, bool>>> const& cmTarget::GetUtilities()
1243
  const
1244
0
{
1245
0
  return this->impl->Utilities;
1246
0
}
1247
1248
cmListFileBacktrace const& cmTarget::GetBacktrace() const
1249
0
{
1250
0
  return this->impl->Backtrace;
1251
0
}
1252
1253
cmFindPackageStack const& cmTarget::GetFindPackageStack() const
1254
0
{
1255
0
  return this->impl->FindPackageStack;
1256
0
}
1257
1258
bool cmTarget::IsExecutableWithExports() const
1259
0
{
1260
0
  return (this->GetType() == cmStateEnums::EXECUTABLE &&
1261
0
          this->GetPropertyAsBool("ENABLE_EXPORTS"));
1262
0
}
1263
1264
bool cmTarget::IsSharedLibraryWithExports() const
1265
0
{
1266
0
  return (this->GetType() == cmStateEnums::SHARED_LIBRARY &&
1267
0
          this->GetPropertyAsBool("ENABLE_EXPORTS"));
1268
0
}
1269
1270
bool cmTarget::IsFrameworkOnApple() const
1271
0
{
1272
0
  return ((this->GetType() == cmStateEnums::SHARED_LIBRARY ||
1273
0
           this->GetType() == cmStateEnums::STATIC_LIBRARY) &&
1274
0
          this->IsApple() && this->GetPropertyAsBool("FRAMEWORK"));
1275
0
}
1276
1277
bool cmTarget::IsArchivedAIXSharedLibrary() const
1278
0
{
1279
0
  if (this->GetType() == cmStateEnums::SHARED_LIBRARY && this->IsAIX()) {
1280
0
    cmValue value = this->GetProperty("AIX_SHARED_LIBRARY_ARCHIVE");
1281
0
    if (!value.IsEmpty()) {
1282
0
      return value.IsOn();
1283
0
    }
1284
0
    if (this->IsImported()) {
1285
0
      return false;
1286
0
    }
1287
0
    switch (this->GetPolicyStatusCMP0182()) {
1288
0
      case cmPolicies::WARN:
1289
0
      case cmPolicies::OLD:
1290
        // The OLD behavior's default is to disable shared library archives.
1291
0
        break;
1292
0
      case cmPolicies::NEW:
1293
        // The NEW behavior's default is to enable shared library archives.
1294
0
        return true;
1295
0
    }
1296
0
  }
1297
0
  return false;
1298
0
}
1299
1300
bool cmTarget::IsAppBundleOnApple() const
1301
0
{
1302
0
  return (this->GetType() == cmStateEnums::EXECUTABLE && this->IsApple() &&
1303
0
          this->GetPropertyAsBool("MACOSX_BUNDLE"));
1304
0
}
1305
1306
bool cmTarget::IsAndroidGuiExecutable() const
1307
0
{
1308
0
  return (this->GetType() == cmStateEnums::EXECUTABLE &&
1309
0
          this->impl->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI"));
1310
0
}
1311
1312
bool cmTarget::HasKnownObjectFileLocation(std::string* reason) const
1313
0
{
1314
0
  return this->GetGlobalGenerator()->HasKnownObjectFileLocation(*this, reason);
1315
0
}
1316
1317
std::vector<cmCustomCommand> const& cmTarget::GetPreBuildCommands() const
1318
0
{
1319
0
  return this->impl->PreBuildCommands;
1320
0
}
1321
1322
void cmTarget::AddPreBuildCommand(cmCustomCommand const& cmd)
1323
0
{
1324
0
  this->impl->PreBuildCommands.push_back(cmd);
1325
0
}
1326
1327
void cmTarget::AddPreBuildCommand(cmCustomCommand&& cmd)
1328
0
{
1329
0
  this->impl->PreBuildCommands.push_back(std::move(cmd));
1330
0
}
1331
1332
std::vector<cmCustomCommand> const& cmTarget::GetPreLinkCommands() const
1333
0
{
1334
0
  return this->impl->PreLinkCommands;
1335
0
}
1336
1337
void cmTarget::AddPreLinkCommand(cmCustomCommand const& cmd)
1338
0
{
1339
0
  this->impl->PreLinkCommands.push_back(cmd);
1340
0
}
1341
1342
void cmTarget::AddPreLinkCommand(cmCustomCommand&& cmd)
1343
0
{
1344
0
  this->impl->PreLinkCommands.push_back(std::move(cmd));
1345
0
}
1346
1347
std::vector<cmCustomCommand> const& cmTarget::GetPostBuildCommands() const
1348
0
{
1349
0
  return this->impl->PostBuildCommands;
1350
0
}
1351
1352
void cmTarget::AddPostBuildCommand(cmCustomCommand const& cmd)
1353
0
{
1354
0
  this->impl->PostBuildCommands.push_back(cmd);
1355
0
}
1356
1357
void cmTarget::AddPostBuildCommand(cmCustomCommand&& cmd)
1358
0
{
1359
0
  this->impl->PostBuildCommands.push_back(std::move(cmd));
1360
0
}
1361
1362
void cmTarget::AddTracedSources(std::vector<std::string> const& srcs)
1363
0
{
1364
0
  if (!srcs.empty()) {
1365
0
    this->impl->Sources.WriteDirect(this->impl.get(), {},
1366
0
                                    cmValue(cmJoin(srcs, ";")),
1367
0
                                    UsageRequirementProperty::Action::Append);
1368
0
  }
1369
0
}
1370
1371
void cmTarget::AddSources(std::vector<std::string> const& srcs)
1372
0
{
1373
0
  std::vector<std::string> srcFiles;
1374
0
  for (std::string const& filename : srcs) {
1375
0
    if (!cmGeneratorExpression::StartsWithGeneratorExpression(filename)) {
1376
0
      this->impl->Makefile->GetOrCreateSource(filename);
1377
0
    }
1378
0
    srcFiles.emplace_back(filename);
1379
0
  }
1380
0
  this->AddTracedSources(srcFiles);
1381
0
}
1382
1383
struct CreateLocation
1384
{
1385
  cmMakefile const* Makefile;
1386
1387
  CreateLocation(cmMakefile const* mf)
1388
0
    : Makefile(mf)
1389
0
  {
1390
0
  }
1391
1392
  cmSourceFileLocation operator()(std::string const& filename) const
1393
0
  {
1394
0
    return cmSourceFileLocation(this->Makefile, filename);
1395
0
  }
1396
};
1397
1398
struct LocationMatcher
1399
{
1400
  cmSourceFileLocation const& Needle;
1401
1402
  LocationMatcher(cmSourceFileLocation const& needle)
1403
0
    : Needle(needle)
1404
0
  {
1405
0
  }
1406
1407
  bool operator()(cmSourceFileLocation& loc)
1408
0
  {
1409
0
    return loc.Matches(this->Needle);
1410
0
  }
1411
};
1412
1413
struct TargetPropertyEntryFinder
1414
{
1415
private:
1416
  cmSourceFileLocation const& Needle;
1417
1418
public:
1419
  TargetPropertyEntryFinder(cmSourceFileLocation const& needle)
1420
0
    : Needle(needle)
1421
0
  {
1422
0
  }
1423
1424
  bool operator()(BT<std::string> const& entry)
1425
0
  {
1426
0
    cmList files{ entry.Value };
1427
0
    std::vector<cmSourceFileLocation> locations;
1428
0
    locations.reserve(files.size());
1429
0
    std::transform(files.begin(), files.end(), std::back_inserter(locations),
1430
0
                   CreateLocation(this->Needle.GetMakefile()));
1431
1432
0
    return std::find_if(locations.begin(), locations.end(),
1433
0
                        LocationMatcher(this->Needle)) != locations.end();
1434
0
  }
1435
};
1436
1437
cmSourceFile* cmTarget::AddSource(std::string const& src, bool before)
1438
0
{
1439
0
  cmSourceFileLocation sfl(this->impl->Makefile, src,
1440
0
                           cmSourceFileLocationKind::Known);
1441
0
  auto const& sources = this->impl->Sources.Entries;
1442
0
  if (std::find_if(sources.begin(), sources.end(),
1443
0
                   TargetPropertyEntryFinder(sfl)) == sources.end()) {
1444
0
    this->impl->Sources.WriteDirect(
1445
0
      this->impl.get(), {}, cmValue(src),
1446
0
      before ? UsageRequirementProperty::Action::Prepend
1447
0
             : UsageRequirementProperty::Action::Append);
1448
0
  }
1449
0
  if (cmGeneratorExpression::Find(src) != std::string::npos) {
1450
0
    return nullptr;
1451
0
  }
1452
0
  return this->impl->Makefile->GetOrCreateSource(
1453
0
    src, false, cmSourceFileLocationKind::Known);
1454
0
}
1455
1456
void cmTarget::ClearDependencyInformation(cmMakefile& mf) const
1457
0
{
1458
0
  std::string depname = cmStrCat(this->GetName(), "_LIB_DEPENDS");
1459
0
  mf.RemoveCacheDefinition(depname);
1460
0
}
1461
1462
std::string cmTarget::GetDebugGeneratorExpressions(
1463
  std::string const& value, cmTargetLinkLibraryType llt) const
1464
0
{
1465
0
  if (llt == GENERAL_LibraryType) {
1466
0
    return value;
1467
0
  }
1468
1469
  // Get the list of configurations considered to be DEBUG.
1470
0
  std::vector<std::string> debugConfigs =
1471
0
    this->impl->Makefile->GetCMakeInstance()->GetDebugConfigs();
1472
1473
0
  std::string configString = "$<CONFIG:" + debugConfigs[0] + ">";
1474
1475
0
  if (debugConfigs.size() > 1) {
1476
0
    for (std::string const& conf : cmMakeRange(debugConfigs).advance(1)) {
1477
0
      configString += ",$<CONFIG:" + conf + ">";
1478
0
    }
1479
0
    configString = "$<OR:" + configString + ">";
1480
0
  }
1481
1482
0
  if (llt == OPTIMIZED_LibraryType) {
1483
0
    configString = "$<NOT:" + configString + ">";
1484
0
  }
1485
0
  return "$<" + configString + ":" + value + ">";
1486
0
}
1487
1488
static std::string targetNameGenex(std::string const& lib)
1489
0
{
1490
0
  return "$<TARGET_NAME:" + lib + ">";
1491
0
}
1492
1493
bool cmTarget::PushTLLCommandTrace(TLLSignature signature,
1494
                                   cmListFileContext const& lfc)
1495
0
{
1496
0
  bool ret = true;
1497
0
  if (!this->impl->TLLCommands.empty()) {
1498
0
    if (this->impl->TLLCommands.back().first != signature) {
1499
0
      ret = false;
1500
0
    }
1501
0
  }
1502
0
  if (this->impl->TLLCommands.empty() ||
1503
0
      this->impl->TLLCommands.back().second != lfc) {
1504
0
    this->impl->TLLCommands.emplace_back(signature, lfc);
1505
0
  }
1506
0
  return ret;
1507
0
}
1508
1509
void cmTarget::GetTllSignatureTraces(std::ostream& s, TLLSignature sig) const
1510
0
{
1511
0
  char const* sigString =
1512
0
    (sig == cmTarget::KeywordTLLSignature ? "keyword" : "plain");
1513
0
  s << "The uses of the " << sigString << " signature are here:\n";
1514
0
  for (auto const& cmd : this->impl->TLLCommands) {
1515
0
    if (cmd.first == sig) {
1516
0
      cmListFileContext lfc = cmd.second;
1517
0
      lfc.FilePath = cmSystemTools::RelativeIfUnder(
1518
0
        this->impl->Makefile->GetState()->GetSourceDirectory(), lfc.FilePath);
1519
0
      s << " * " << lfc << '\n';
1520
0
    }
1521
0
  }
1522
0
}
1523
1524
std::string const& cmTarget::GetInstallPath() const
1525
0
{
1526
0
  return this->impl->InstallPath;
1527
0
}
1528
1529
void cmTarget::SetInstallPath(std::string const& name)
1530
0
{
1531
0
  this->impl->InstallPath = name;
1532
0
}
1533
1534
std::string const& cmTarget::GetRuntimeInstallPath() const
1535
0
{
1536
0
  return this->impl->RuntimeInstallPath;
1537
0
}
1538
1539
void cmTarget::SetRuntimeInstallPath(std::string const& name)
1540
0
{
1541
0
  this->impl->RuntimeInstallPath = name;
1542
0
}
1543
1544
bool cmTarget::GetHaveInstallRule() const
1545
0
{
1546
0
  return this->impl->HaveInstallRule;
1547
0
}
1548
1549
void cmTarget::SetHaveInstallRule(bool hir)
1550
0
{
1551
0
  this->impl->HaveInstallRule = hir;
1552
0
}
1553
1554
void cmTarget::AddInstallGenerator(cmInstallTargetGenerator* g)
1555
0
{
1556
0
  this->impl->InstallGenerators.emplace_back(g);
1557
0
}
1558
1559
std::vector<cmInstallTargetGenerator*> const& cmTarget::GetInstallGenerators()
1560
  const
1561
0
{
1562
0
  return this->impl->InstallGenerators;
1563
0
}
1564
1565
bool cmTarget::GetIsGeneratorProvided() const
1566
0
{
1567
0
  return this->impl->IsGeneratorProvided;
1568
0
}
1569
1570
void cmTarget::SetIsGeneratorProvided(bool igp)
1571
0
{
1572
0
  this->impl->IsGeneratorProvided = igp;
1573
0
}
1574
1575
cmTarget::LinkLibraryVectorType const& cmTarget::GetOriginalLinkLibraries()
1576
  const
1577
0
{
1578
0
  return this->impl->OriginalLinkLibraries;
1579
0
}
1580
1581
void cmTarget::AddLinkLibrary(cmMakefile& mf, std::string const& lib,
1582
                              cmTargetLinkLibraryType llt)
1583
0
{
1584
0
  cmTarget* tgt = mf.FindTargetToUse(lib);
1585
0
  {
1586
0
    bool const isNonImportedTarget = tgt && !tgt->IsImported();
1587
1588
0
    std::string const libName =
1589
0
      (isNonImportedTarget && llt != GENERAL_LibraryType)
1590
0
      ? targetNameGenex(lib)
1591
0
      : lib;
1592
0
    this->AppendProperty("LINK_LIBRARIES",
1593
0
                         this->GetDebugGeneratorExpressions(libName, llt),
1594
0
                         mf.GetBacktrace());
1595
0
  }
1596
1597
0
  if (cmGeneratorExpression::Find(lib) != std::string::npos ||
1598
0
      (tgt &&
1599
0
       (tgt->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
1600
0
        tgt->GetType() == cmStateEnums::OBJECT_LIBRARY)) ||
1601
0
      (this->impl->Name == lib)) {
1602
0
    return;
1603
0
  }
1604
1605
0
  this->impl->OriginalLinkLibraries.emplace_back(lib, llt);
1606
1607
  // Add the explicit dependency information for libraries. This is
1608
  // simply a set of libraries separated by ";". There should always
1609
  // be a trailing ";". These library names are not canonical, in that
1610
  // they may be "-framework x", "-ly", "/path/libz.a", etc.
1611
  // We shouldn't remove duplicates here because external libraries
1612
  // may be purposefully duplicated to handle recursive dependencies,
1613
  // and we removing one instance will break the link line. Duplicates
1614
  // will be appropriately eliminated at emit time.
1615
0
  if (this->impl->TargetType >= cmStateEnums::STATIC_LIBRARY &&
1616
0
      this->impl->TargetType <= cmStateEnums::MODULE_LIBRARY &&
1617
0
      (this->GetPolicyStatusCMP0073() == cmPolicies::OLD ||
1618
0
       this->GetPolicyStatusCMP0073() == cmPolicies::WARN)) {
1619
0
    std::string targetEntry = cmStrCat(this->impl->Name, "_LIB_DEPENDS");
1620
0
    std::string dependencies;
1621
0
    cmValue old_val = mf.GetDefinition(targetEntry);
1622
0
    if (old_val) {
1623
0
      dependencies += *old_val;
1624
0
    }
1625
0
    switch (llt) {
1626
0
      case GENERAL_LibraryType:
1627
0
        dependencies += "general";
1628
0
        break;
1629
0
      case DEBUG_LibraryType:
1630
0
        dependencies += "debug";
1631
0
        break;
1632
0
      case OPTIMIZED_LibraryType:
1633
0
        dependencies += "optimized";
1634
0
        break;
1635
0
    }
1636
0
    dependencies += ";";
1637
0
    dependencies += lib;
1638
0
    dependencies += ";";
1639
0
    mf.AddCacheDefinition(targetEntry, dependencies,
1640
0
                          "Dependencies for the target", cmStateEnums::STATIC);
1641
0
  }
1642
0
}
1643
1644
void cmTarget::AddSystemIncludeDirectories(std::set<std::string> const& incs)
1645
0
{
1646
0
  this->impl->SystemIncludeDirectories.insert(incs.begin(), incs.end());
1647
0
}
1648
1649
std::set<std::string> const& cmTarget::GetSystemIncludeDirectories() const
1650
0
{
1651
0
  return this->impl->SystemIncludeDirectories;
1652
0
}
1653
1654
void cmTarget::AddInstallIncludeDirectories(cmTargetExport const& te,
1655
                                            cmStringRange incs)
1656
0
{
1657
0
  std::copy(
1658
0
    incs.begin(), incs.end(),
1659
0
    std::back_inserter(this->impl->InstallIncludeDirectoriesEntries[&te]));
1660
0
}
1661
1662
cmStringRange cmTarget::GetInstallIncludeDirectoriesEntries(
1663
  cmTargetExport const& te) const
1664
0
{
1665
0
  auto i = this->impl->InstallIncludeDirectoriesEntries.find(&te);
1666
0
  if (i == this->impl->InstallIncludeDirectoriesEntries.end()) {
1667
0
    decltype(i->second) empty;
1668
0
    return cmMakeRange(empty);
1669
0
  }
1670
0
  return cmMakeRange(i->second);
1671
0
}
1672
1673
cmBTStringRange cmTarget::GetIncludeDirectoriesEntries() const
1674
0
{
1675
0
  return cmMakeRange(this->impl->IncludeDirectories.Entries);
1676
0
}
1677
1678
cmBTStringRange cmTarget::GetCompileOptionsEntries() const
1679
0
{
1680
0
  return cmMakeRange(this->impl->CompileOptions.Entries);
1681
0
}
1682
1683
cmBTStringRange cmTarget::GetCompileFeaturesEntries() const
1684
0
{
1685
0
  return cmMakeRange(this->impl->CompileFeatures.Entries);
1686
0
}
1687
1688
cmBTStringRange cmTarget::GetCompileDefinitionsEntries() const
1689
0
{
1690
0
  return cmMakeRange(this->impl->CompileDefinitions.Entries);
1691
0
}
1692
1693
cmBTStringRange cmTarget::GetPrecompileHeadersEntries() const
1694
0
{
1695
0
  return cmMakeRange(this->impl->PrecompileHeaders.Entries);
1696
0
}
1697
1698
cmBTStringRange cmTarget::GetSourceEntries() const
1699
0
{
1700
0
  return cmMakeRange(this->impl->Sources.Entries);
1701
0
}
1702
1703
cmBTStringRange cmTarget::GetLinkOptionsEntries() const
1704
0
{
1705
0
  return cmMakeRange(this->impl->LinkOptions.Entries);
1706
0
}
1707
1708
cmBTStringRange cmTarget::GetLinkDirectoriesEntries() const
1709
0
{
1710
0
  return cmMakeRange(this->impl->LinkDirectories.Entries);
1711
0
}
1712
1713
cmBTStringRange cmTarget::GetLinkImplementationEntries() const
1714
0
{
1715
0
  return cmMakeRange(this->impl->LinkLibraries.Entries);
1716
0
}
1717
1718
cmBTStringRange cmTarget::GetLinkInterfaceEntries() const
1719
0
{
1720
0
  return cmMakeRange(this->impl->InterfaceLinkLibraries.Entries);
1721
0
}
1722
1723
cmBTStringRange cmTarget::GetLinkInterfaceDirectEntries() const
1724
0
{
1725
0
  return cmMakeRange(this->impl->InterfaceLinkLibrariesDirect.Entries);
1726
0
}
1727
1728
cmBTStringRange cmTarget::GetLinkInterfaceDirectExcludeEntries() const
1729
0
{
1730
0
  return cmMakeRange(this->impl->InterfaceLinkLibrariesDirectExclude.Entries);
1731
0
}
1732
1733
void cmTarget::CopyPolicyStatuses(cmTarget const* tgt)
1734
0
{
1735
  // Normal targets cannot be the target of a copy.
1736
0
  assert(!this->IsNormal());
1737
  // Imported targets cannot be the target of a copy.
1738
0
  assert(!this->IsImported());
1739
1740
  // Only imported or normal targets can be the source of a copy.
1741
0
  assert(tgt->IsImported() || tgt->IsNormal());
1742
1743
0
  this->impl->PolicyMap = tgt->impl->PolicyMap;
1744
0
  this->impl->TemplateTarget = tgt;
1745
0
}
1746
1747
void cmTarget::CopyCxxModulesEntries(cmTarget const* tgt)
1748
0
{
1749
  // Normal targets cannot be the target of a copy.
1750
0
  assert(!this->IsNormal());
1751
  // Imported targets cannot be the target of a copy.
1752
0
  assert(!this->IsImported());
1753
  // Only imported or normal targets can be the source of a copy.
1754
0
  assert(tgt->IsImported() || tgt->IsNormal());
1755
1756
0
  this->impl->IncludeDirectories.Entries.clear();
1757
0
  this->impl->CompileDefinitions.Entries.clear();
1758
0
  this->impl->CompileFeatures.Entries.clear();
1759
0
  this->impl->CompileOptions.Entries.clear();
1760
0
  this->impl->LinkLibraries.Entries.clear();
1761
1762
0
  if (tgt->IsImported()) {
1763
0
    this->impl->IncludeDirectories.CopyFromEntries(
1764
0
      cmMakeRange(tgt->impl->ImportedCxxModulesIncludeDirectories.Entries));
1765
0
    this->impl->CompileDefinitions.CopyFromEntries(
1766
0
      cmMakeRange(tgt->impl->ImportedCxxModulesCompileDefinitions.Entries));
1767
0
    this->impl->CompileFeatures.CopyFromEntries(
1768
0
      cmMakeRange(tgt->impl->ImportedCxxModulesCompileFeatures.Entries));
1769
0
    this->impl->CompileOptions.CopyFromEntries(
1770
0
      cmMakeRange(tgt->impl->ImportedCxxModulesCompileOptions.Entries));
1771
0
    this->impl->LinkLibraries.CopyFromEntries(
1772
0
      cmMakeRange(tgt->impl->ImportedCxxModulesLinkLibraries.Entries));
1773
0
  } else {
1774
0
    this->impl->IncludeDirectories.CopyFromEntries(
1775
0
      cmMakeRange(tgt->impl->IncludeDirectories.Entries));
1776
0
    this->impl->CompileDefinitions.CopyFromEntries(
1777
0
      cmMakeRange(tgt->impl->CompileDefinitions.Entries));
1778
0
    this->impl->CompileFeatures.CopyFromEntries(
1779
0
      cmMakeRange(tgt->impl->CompileFeatures.Entries));
1780
0
    this->impl->CompileOptions.CopyFromEntries(
1781
0
      cmMakeRange(tgt->impl->CompileOptions.Entries));
1782
0
    this->impl->LinkLibraries.CopyFromEntries(
1783
0
      cmMakeRange(tgt->impl->LinkLibraries.Entries));
1784
0
  }
1785
1786
  // Copy the C++ module fileset entries from `tgt`'s `INTERFACE` to this
1787
  // target's `PRIVATE`.
1788
0
  auto& entries = this->impl->FileSetTypes.at(cm::FileSetMetadata::CXX_MODULES)
1789
0
                    .SelfEntries.Entries;
1790
0
  entries.clear();
1791
0
  entries = tgt->impl->FileSetTypes.at(cm::FileSetMetadata::CXX_MODULES)
1792
0
              .InterfaceEntries.Entries;
1793
0
}
1794
1795
void cmTarget::CopyCxxModulesProperties(cmTarget const* tgt)
1796
0
{
1797
  // Normal targets cannot be the target of a copy.
1798
0
  assert(!this->IsNormal());
1799
  // Imported targets cannot be the target of a copy.
1800
0
  assert(!this->IsImported());
1801
  // Only imported or normal targets can be the source of a copy.
1802
0
  assert(tgt->IsImported() || tgt->IsNormal());
1803
1804
  // The list of properties that are relevant here include:
1805
  // - compilation-specific properties for any language or platform
1806
  // - compilation-specific properties for C++
1807
  // - build graph-specific properties that affect compilation
1808
  // - IDE metadata properties
1809
  // - static analysis properties
1810
1811
0
  static std::string const propertiesToCopy[] = {
1812
    // Compilation properties
1813
0
    "DEFINE_SYMBOL",
1814
0
    "DEPRECATION",
1815
0
    "NO_SYSTEM_FROM_IMPORTED",
1816
0
    "POSITION_INDEPENDENT_CODE",
1817
0
    "VISIBILITY_INLINES_HIDDEN",
1818
    // -- Platforms
1819
    // ---- Android
1820
0
    "ANDROID_API",
1821
0
    "ANDROID_API_MIN",
1822
0
    "ANDROID_ARCH",
1823
0
    "ANDROID_STL_TYPE",
1824
    // ---- macOS
1825
0
    "OSX_ARCHITECTURES",
1826
    // ---- Windows
1827
0
    "MSVC_DEBUG_INFORMATION_FORMAT",
1828
0
    "MSVC_RUNTIME_CHECKS",
1829
0
    "MSVC_RUNTIME_LIBRARY",
1830
0
    "VS_PLATFORM_TOOLSET",
1831
    // ---- OpenWatcom
1832
0
    "WATCOM_RUNTIME_LIBRARY",
1833
    // -- Language
1834
    // ---- C++
1835
0
    "CXX_COMPILER_LAUNCHER",
1836
0
    "CXX_STANDARD",
1837
0
    "CXX_STANDARD_REQUIRED",
1838
0
    "CXX_EXTENSIONS",
1839
0
    "CXX_VISIBILITY_PRESET",
1840
0
    "CXX_MODULE_STD",
1841
1842
    // Static analysis
1843
0
    "CXX_CLANG_TIDY",
1844
0
    "CXX_CLANG_TIDY_EXPORT_FIXES_DIR",
1845
0
    "CXX_CPPLINT",
1846
0
    "CXX_CPPCHECK",
1847
0
    "CXX_ICSTAT",
1848
0
    "CXX_INCLUDE_WHAT_YOU_USE",
1849
0
    "CXX_PVS_STUDIO",
1850
0
    "SKIP_LINTING",
1851
1852
    // Build graph properties
1853
0
    "EXCLUDE_FROM_ALL",
1854
0
    "EXCLUDE_FROM_DEFAULT_BUILD",
1855
0
    "OPTIMIZE_DEPENDENCIES",
1856
    // -- Ninja
1857
0
    "JOB_POOL_COMPILE",
1858
    // -- Visual Studio
1859
0
    "VS_NO_COMPILE_BATCHING",
1860
0
    "VS_PROJECT_IMPORT",
1861
1862
    // Metadata
1863
0
    "EchoString",
1864
0
    "EXPORT_COMPILE_COMMANDS",
1865
    // Do *not* copy this property; it should be re-initialized at synthesis
1866
    // time from the `CMAKE_EXPORT_BUILD_DATABASE` variable as `IMPORTED`
1867
    // targets ignore the property initialization.
1868
    // "EXPORT_BUILD_DATABASE",
1869
0
    "FOLDER",
1870
0
    "LABELS",
1871
0
    "PROJECT_LABEL",
1872
0
    "SYSTEM",
1873
0
  };
1874
1875
0
  auto copyProperty = [this, tgt](std::string const& prop) -> cmValue {
1876
0
    cmValue value = tgt->GetProperty(prop);
1877
    // Always set the property; it may have been explicitly unset.
1878
0
    this->SetProperty(prop, value);
1879
0
    return value;
1880
0
  };
1881
1882
0
  for (auto const& prop : propertiesToCopy) {
1883
0
    copyProperty(prop);
1884
0
  }
1885
1886
0
  static cm::static_string_view const perConfigPropertiesToCopy[] = {
1887
0
    "EXCLUDE_FROM_DEFAULT_BUILD_"_s,
1888
0
    "IMPORTED_CXX_MODULES_"_s,
1889
0
    "MAP_IMPORTED_CONFIG_"_s,
1890
0
    "OSX_ARCHITECTURES_"_s,
1891
0
  };
1892
1893
0
  std::vector<std::string> configNames =
1894
0
    this->impl->Makefile->GetGeneratorConfigs(cmMakefile::ExcludeEmptyConfig);
1895
0
  for (std::string const& configName : configNames) {
1896
0
    std::string configUpper = cmSystemTools::UpperCase(configName);
1897
0
    for (auto const& perConfigProp : perConfigPropertiesToCopy) {
1898
0
      copyProperty(cmStrCat(perConfigProp, configUpper));
1899
0
    }
1900
0
  }
1901
1902
0
  if (this->GetGlobalGenerator()->IsXcode()) {
1903
0
    cmValue xcodeGenerateScheme = copyProperty("XCODE_GENERATE_SCHEME");
1904
1905
    // TODO: Make sure these show up on the imported target in the first place
1906
    // XCODE_ATTRIBUTE_???
1907
1908
0
    if (xcodeGenerateScheme.IsOn()) {
1909
#ifdef __APPLE__
1910
      static std::string const xcodeSchemePropertiesToCopy[] = {
1911
        // FIXME: Do all of these apply? Do they matter?
1912
        "XCODE_SCHEME_ADDRESS_SANITIZER",
1913
        "XCODE_SCHEME_ADDRESS_SANITIZER_USE_AFTER_RETURN",
1914
        "XCODE_SCHEME_DISABLE_MAIN_THREAD_CHECKER",
1915
        "XCODE_SCHEME_DYNAMIC_LIBRARY_LOADS",
1916
        "XCODE_SCHEME_DYNAMIC_LINKER_API_USAGE",
1917
        "XCODE_SCHEME_ENABLE_GPU_API_VALIDATION",
1918
        "XCODE_SCHEME_ENABLE_GPU_SHADER_VALIDATION",
1919
        "XCODE_SCHEME_GUARD_MALLOC",
1920
        "XCODE_SCHEME_LAUNCH_CONFIGURATION",
1921
        "XCODE_SCHEME_MAIN_THREAD_CHECKER_STOP",
1922
        "XCODE_SCHEME_MALLOC_GUARD_EDGES",
1923
        "XCODE_SCHEME_MALLOC_SCRIBBLE",
1924
        "XCODE_SCHEME_MALLOC_STACK",
1925
        "XCODE_SCHEME_THREAD_SANITIZER",
1926
        "XCODE_SCHEME_THREAD_SANITIZER_STOP",
1927
        "XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER",
1928
        "XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER_STOP",
1929
        "XCODE_SCHEME_ZOMBIE_OBJECTS",
1930
      };
1931
1932
      for (auto const& xcodeProperty : xcodeSchemePropertiesToCopy) {
1933
        copyProperty(xcodeProperty);
1934
      }
1935
#endif
1936
0
    }
1937
0
  }
1938
0
}
1939
1940
namespace {
1941
std::vector<BT<std::string>> EmptyEntries;
1942
}
1943
1944
cmBTStringRange cmTarget::GetFileSetsEntries(cm::string_view type) const
1945
0
{
1946
0
  if (cm::contains(this->impl->FileSetTypes, type)) {
1947
0
    return cmMakeRange(this->impl->FileSetTypes.at(type).SelfEntries.Entries);
1948
0
  }
1949
0
  return cmMakeRange(EmptyEntries);
1950
0
}
1951
1952
cmBTStringRange cmTarget::GetInterfaceFileSetsEntries(
1953
  cm::string_view type) const
1954
0
{
1955
0
  if (cm::contains(this->impl->FileSetTypes, type)) {
1956
0
    return cmMakeRange(
1957
0
      this->impl->FileSetTypes.at(type).InterfaceEntries.Entries);
1958
0
  }
1959
0
  return cmMakeRange(EmptyEntries);
1960
0
}
1961
1962
namespace {
1963
#define MAKE_PROP(PROP) const std::string prop##PROP = #PROP
1964
MAKE_PROP(C_STANDARD);
1965
MAKE_PROP(CXX_STANDARD);
1966
MAKE_PROP(CUDA_STANDARD);
1967
MAKE_PROP(HIP_STANDARD);
1968
MAKE_PROP(OBJC_STANDARD);
1969
MAKE_PROP(OBJCXX_STANDARD);
1970
MAKE_PROP(COMPILE_DEFINITIONS);
1971
MAKE_PROP(COMPILE_FEATURES);
1972
MAKE_PROP(COMPILE_OPTIONS);
1973
MAKE_PROP(PRECOMPILE_HEADERS);
1974
MAKE_PROP(CUDA_CUBIN_COMPILATION);
1975
MAKE_PROP(CUDA_FATBIN_COMPILATION);
1976
MAKE_PROP(CUDA_OPTIX_COMPILATION);
1977
MAKE_PROP(CUDA_PTX_COMPILATION);
1978
MAKE_PROP(IMPORTED);
1979
MAKE_PROP(IMPORTED_GLOBAL);
1980
MAKE_PROP(INCLUDE_DIRECTORIES);
1981
MAKE_PROP(LINK_OPTIONS);
1982
MAKE_PROP(IMPORTED_CXX_MODULES_INCLUDE_DIRECTORIES);
1983
MAKE_PROP(IMPORTED_CXX_MODULES_COMPILE_DEFINITIONS);
1984
MAKE_PROP(IMPORTED_CXX_MODULES_COMPILE_FEATURES);
1985
MAKE_PROP(IMPORTED_CXX_MODULES_COMPILE_OPTIONS);
1986
MAKE_PROP(IMPORTED_CXX_MODULES_LINK_LIBRARIES);
1987
MAKE_PROP(LINK_DIRECTORIES);
1988
MAKE_PROP(LINK_LIBRARIES);
1989
MAKE_PROP(MANUALLY_ADDED_DEPENDENCIES);
1990
MAKE_PROP(NAME);
1991
MAKE_PROP(SOURCES);
1992
MAKE_PROP(SYMBOLIC);
1993
MAKE_PROP(TYPE);
1994
MAKE_PROP(BINARY_DIR);
1995
MAKE_PROP(SOURCE_DIR);
1996
MAKE_PROP(FALSE);
1997
MAKE_PROP(TRUE);
1998
MAKE_PROP(INTERFACE_LINK_LIBRARIES);
1999
MAKE_PROP(INTERFACE_LINK_LIBRARIES_DIRECT);
2000
MAKE_PROP(INTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE);
2001
#undef MAKE_PROP
2002
}
2003
2004
namespace {
2005
2006
enum class ReadOnlyCondition
2007
{
2008
  All,
2009
  Imported,
2010
  NonImported,
2011
};
2012
2013
struct ReadOnlyProperty
2014
{
2015
  ReadOnlyProperty(ReadOnlyCondition cond)
2016
0
    : Condition{ cond }
2017
0
  {
2018
0
  }
2019
  ReadOnlyProperty(ReadOnlyCondition cond, cmPolicies::PolicyID id)
2020
0
    : Condition{ cond }
2021
0
    , Policy{ id }
2022
0
  {
2023
0
  }
2024
2025
  ReadOnlyCondition Condition;
2026
  cm::optional<cmPolicies::PolicyID> Policy;
2027
2028
  std::string message(std::string const& prop, cmTarget* target) const
2029
0
  {
2030
0
    std::string msg;
2031
0
    if (this->Condition == ReadOnlyCondition::All) {
2032
0
      msg = " property is read-only for target(\"";
2033
0
    } else if (this->Condition == ReadOnlyCondition::Imported) {
2034
0
      msg = " property can't be set on imported targets(\"";
2035
0
    } else if (this->Condition == ReadOnlyCondition::NonImported) {
2036
0
      msg = " property can't be set on non-imported targets(\"";
2037
0
    }
2038
0
    return cmStrCat(prop, msg, target->GetName(), "\")\n");
2039
0
  }
2040
2041
  bool isReadOnly(std::string const& prop, cmMakefile* context,
2042
                  cmTarget* target) const
2043
0
  {
2044
0
    auto importedTarget = target->IsImported();
2045
0
    bool matchingCondition = true;
2046
0
    if ((!importedTarget && this->Condition == ReadOnlyCondition::Imported) ||
2047
0
        (importedTarget &&
2048
0
         this->Condition == ReadOnlyCondition::NonImported)) {
2049
0
      matchingCondition = false;
2050
0
    }
2051
0
    if (!matchingCondition) {
2052
      // Not read-only in this scenario
2053
0
      return false;
2054
0
    }
2055
2056
0
    bool readOnly = true;
2057
0
    if (!this->Policy) {
2058
      // No policy associated, so is always read-only
2059
0
      context->IssueMessage(MessageType::FATAL_ERROR,
2060
0
                            this->message(prop, target));
2061
0
    } else {
2062
0
      switch (target->GetPolicyStatus(*this->Policy)) {
2063
0
        case cmPolicies::WARN:
2064
0
          context->IssueDiagnostic(
2065
0
            cmDiagnostics::CMD_AUTHOR,
2066
0
            cmPolicies::GetPolicyWarning(cmPolicies::CMP0160) + "\n" +
2067
0
              this->message(prop, target));
2068
0
          CM_FALLTHROUGH;
2069
0
        case cmPolicies::OLD:
2070
0
          readOnly = false;
2071
0
          break;
2072
0
        case cmPolicies::NEW:
2073
0
          context->IssueMessage(MessageType::FATAL_ERROR,
2074
0
                                this->message(prop, target));
2075
0
          break;
2076
0
      }
2077
0
    }
2078
0
    return readOnly;
2079
0
  }
2080
};
2081
2082
bool IsSettableProperty(cmMakefile* context, cmTarget* target,
2083
                        std::string const& prop)
2084
0
{
2085
0
  using ROC = ReadOnlyCondition;
2086
0
  static std::unordered_map<std::string, ReadOnlyProperty> const readOnlyProps{
2087
0
    { "EXPORT_NAME", { ROC::Imported } },
2088
0
    { "HEADER_SETS", { ROC::All } },
2089
0
    { "IMPORTED_GLOBAL", { ROC::NonImported } },
2090
0
    { "INTERFACE_HEADER_SETS", { ROC::All } },
2091
0
    { "MANUALLY_ADDED_DEPENDENCIES", { ROC::All } },
2092
0
    { "NAME", { ROC::All } },
2093
0
    { "SOURCES", { ROC::Imported } },
2094
0
    { "SYMBOLIC", { ROC::All } },
2095
0
    { "TYPE", { ROC::All } },
2096
0
    { "ALIAS_GLOBAL", { ROC::All, cmPolicies::CMP0160 } },
2097
0
    { "BINARY_DIR", { ROC::All, cmPolicies::CMP0160 } },
2098
0
    { "CXX_MODULE_SETS", { ROC::All, cmPolicies::CMP0160 } },
2099
0
    { "IMPORTED", { ROC::All, cmPolicies::CMP0160 } },
2100
0
    { "INTERFACE_CXX_MODULE_SETS", { ROC::All, cmPolicies::CMP0160 } },
2101
0
    { "LOCATION", { ROC::All, cmPolicies::CMP0160 } },
2102
0
    { "LOCATION_CONFIG", { ROC::All, cmPolicies::CMP0160 } },
2103
0
    { "SOURCE_DIR", { ROC::All, cmPolicies::CMP0160 } }
2104
0
  };
2105
2106
0
  auto it = readOnlyProps.find(prop);
2107
2108
0
  if (it != readOnlyProps.end()) {
2109
0
    return !(it->second.isReadOnly(prop, context, target));
2110
0
  }
2111
0
  return true;
2112
0
}
2113
}
2114
2115
void cmTarget::SetSymbolic(bool const value)
2116
0
{
2117
0
  this->impl->IsSymbolic = value;
2118
0
}
2119
2120
void cmTarget::SetProperty(std::string const& prop, cmValue value)
2121
0
{
2122
0
  if (!IsSettableProperty(this->impl->Makefile, this, prop)) {
2123
0
    return;
2124
0
  }
2125
2126
0
  UsageRequirementProperty* usageRequirements[] = {
2127
0
    &this->impl->IncludeDirectories,
2128
0
    &this->impl->CompileOptions,
2129
0
    &this->impl->CompileFeatures,
2130
0
    &this->impl->CompileDefinitions,
2131
0
    &this->impl->PrecompileHeaders,
2132
0
    &this->impl->Sources,
2133
0
    &this->impl->LinkOptions,
2134
0
    &this->impl->LinkDirectories,
2135
0
    &this->impl->LinkLibraries,
2136
0
    &this->impl->InterfaceLinkLibraries,
2137
0
    &this->impl->InterfaceLinkLibrariesDirect,
2138
0
    &this->impl->InterfaceLinkLibrariesDirectExclude,
2139
0
    &this->impl->ImportedCxxModulesIncludeDirectories,
2140
0
    &this->impl->ImportedCxxModulesCompileDefinitions,
2141
0
    &this->impl->ImportedCxxModulesCompileFeatures,
2142
0
    &this->impl->ImportedCxxModulesCompileOptions,
2143
0
    &this->impl->ImportedCxxModulesLinkLibraries,
2144
0
  };
2145
2146
0
  for (auto* usageRequirement : usageRequirements) {
2147
0
    if (usageRequirement->Write(this->impl.get(), {}, prop, value,
2148
0
                                UsageRequirementProperty::Action::Set)) {
2149
0
      return;
2150
0
    }
2151
0
  }
2152
2153
0
  for (auto& fileSetType : this->impl->FileSetTypes) {
2154
0
    if (fileSetType.second.WriteProperties(this, this->impl.get(), prop, value,
2155
0
                                           FileSetType::Action::Set)) {
2156
0
      return;
2157
0
    }
2158
0
  }
2159
2160
0
  if (prop == propIMPORTED_GLOBAL) {
2161
0
    if (!value.IsOn()) {
2162
0
      std::ostringstream e;
2163
0
      e << "IMPORTED_GLOBAL property can't be set to FALSE on targets (\""
2164
0
        << this->impl->Name << "\")\n";
2165
0
      this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str());
2166
0
      return;
2167
0
    }
2168
    /* no need to change anything if value does not change */
2169
0
    if (!this->IsImportedGloballyVisible()) {
2170
0
      this->impl->TargetVisibility = Visibility::ImportedGlobally;
2171
0
      this->GetGlobalGenerator()->IndexTarget(this);
2172
0
    }
2173
0
  } else if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME") &&
2174
0
             !this->impl->CheckImportedLibName(
2175
0
               prop,
2176
0
               value ? value
2177
0
                     : std::string{})) { // NOLINT(bugprone-branch-clone)
2178
    /* error was reported by check method */
2179
0
  } else if (prop == propCUDA_CUBIN_COMPILATION ||
2180
0
             prop == propCUDA_FATBIN_COMPILATION ||
2181
0
             prop == propCUDA_OPTIX_COMPILATION ||
2182
0
             prop == propCUDA_PTX_COMPILATION) {
2183
0
    auto const& compiler =
2184
0
      this->impl->Makefile->GetSafeDefinition("CMAKE_CUDA_COMPILER_ID");
2185
0
    auto const& compilerVersion =
2186
0
      this->impl->Makefile->GetSafeDefinition("CMAKE_CUDA_COMPILER_VERSION");
2187
0
    if (this->GetType() != cmStateEnums::OBJECT_LIBRARY) {
2188
0
      auto e =
2189
0
        cmStrCat(prop, " property can only be applied to OBJECT targets(",
2190
0
                 this->impl->Name, ")\n");
2191
0
      this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e);
2192
0
      return;
2193
0
    }
2194
0
    bool const flag_found =
2195
0
      (prop == propCUDA_PTX_COMPILATION &&
2196
0
       this->impl->Makefile->GetDefinition("_CMAKE_CUDA_PTX_FLAG")) ||
2197
0
      (prop == propCUDA_CUBIN_COMPILATION &&
2198
0
       this->impl->Makefile->GetDefinition("_CMAKE_CUDA_CUBIN_FLAG")) ||
2199
0
      (prop == propCUDA_FATBIN_COMPILATION &&
2200
0
       this->impl->Makefile->GetDefinition("_CMAKE_CUDA_FATBIN_FLAG")) ||
2201
0
      (prop == propCUDA_OPTIX_COMPILATION &&
2202
0
       this->impl->Makefile->GetDefinition("_CMAKE_CUDA_OPTIX_FLAG"));
2203
0
    if (flag_found) {
2204
0
      this->impl->Properties.SetProperty(prop, value);
2205
0
    } else {
2206
0
      auto e = cmStrCat(prop, " property is not supported by ", compiler,
2207
0
                        "  compiler version ", compilerVersion, '.');
2208
0
      this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e);
2209
0
      return;
2210
0
    }
2211
0
  } else if (prop == propC_STANDARD || prop == propCXX_STANDARD ||
2212
0
             prop == propCUDA_STANDARD || prop == propHIP_STANDARD ||
2213
0
             prop == propOBJC_STANDARD || prop == propOBJCXX_STANDARD) {
2214
0
    if (value) {
2215
0
      this->impl->LanguageStandardProperties[prop] =
2216
0
        BTs<std::string>(value, this->impl->Makefile->GetBacktrace());
2217
0
    } else {
2218
0
      this->impl->LanguageStandardProperties.erase(prop);
2219
0
    }
2220
0
  } else {
2221
0
    this->impl->Properties.SetProperty(prop, value);
2222
0
  }
2223
0
}
2224
2225
void cmTarget::AppendProperty(std::string const& prop,
2226
                              std::string const& value,
2227
                              cm::optional<cmListFileBacktrace> const& bt,
2228
                              bool asString)
2229
0
{
2230
0
  if (!IsSettableProperty(this->impl->Makefile, this, prop)) {
2231
0
    return;
2232
0
  }
2233
0
  if (prop == "IMPORTED_GLOBAL") {
2234
0
    this->impl->Makefile->IssueMessage(
2235
0
      MessageType::FATAL_ERROR,
2236
0
      cmStrCat("IMPORTED_GLOBAL property can't be appended, only set on "
2237
0
               "imported targets (\"",
2238
0
               this->impl->Name, "\")\n"));
2239
0
  }
2240
2241
0
  UsageRequirementProperty* usageRequirements[] = {
2242
0
    &this->impl->IncludeDirectories,
2243
0
    &this->impl->CompileOptions,
2244
0
    &this->impl->CompileFeatures,
2245
0
    &this->impl->CompileDefinitions,
2246
0
    &this->impl->PrecompileHeaders,
2247
0
    &this->impl->Sources,
2248
0
    &this->impl->LinkOptions,
2249
0
    &this->impl->LinkDirectories,
2250
0
    &this->impl->LinkLibraries,
2251
0
    &this->impl->InterfaceLinkLibraries,
2252
0
    &this->impl->InterfaceLinkLibrariesDirect,
2253
0
    &this->impl->InterfaceLinkLibrariesDirectExclude,
2254
0
    &this->impl->ImportedCxxModulesIncludeDirectories,
2255
0
    &this->impl->ImportedCxxModulesCompileDefinitions,
2256
0
    &this->impl->ImportedCxxModulesCompileFeatures,
2257
0
    &this->impl->ImportedCxxModulesCompileOptions,
2258
0
    &this->impl->ImportedCxxModulesLinkLibraries,
2259
0
  };
2260
2261
0
  for (auto* usageRequirement : usageRequirements) {
2262
0
    if (usageRequirement->Write(this->impl.get(), bt, prop, cmValue(value),
2263
0
                                UsageRequirementProperty::Action::Append)) {
2264
0
      return;
2265
0
    }
2266
0
  }
2267
2268
0
  for (auto& fileSetType : this->impl->FileSetTypes) {
2269
0
    if (fileSetType.second.WriteProperties(this, this->impl.get(), prop, value,
2270
0
                                           FileSetType::Action::Append)) {
2271
0
      return;
2272
0
    }
2273
0
  }
2274
2275
0
  if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME")) {
2276
0
    this->impl->Makefile->IssueMessage(
2277
0
      MessageType::FATAL_ERROR, prop + " property may not be APPENDed.");
2278
0
  } else if (prop == "C_STANDARD" || prop == "CXX_STANDARD" ||
2279
0
             prop == "CUDA_STANDARD" || prop == "HIP_STANDARD" ||
2280
0
             prop == "OBJC_STANDARD" || prop == "OBJCXX_STANDARD") {
2281
0
    this->impl->Makefile->IssueMessage(
2282
0
      MessageType::FATAL_ERROR, prop + " property may not be appended.");
2283
0
  } else {
2284
0
    this->impl->Properties.AppendProperty(prop, value, asString);
2285
0
  }
2286
0
}
2287
2288
template <typename ValueType>
2289
void cmTargetInternals::AddDirectoryToFileSet(cmTarget* self,
2290
                                              std::string const& fileSetName,
2291
                                              ValueType value,
2292
                                              cm::string_view fileSetType,
2293
                                              cm::string_view description,
2294
                                              FileSetType::Action action)
2295
0
{
2296
0
  auto* fileSet = self->GetFileSet(fileSetName);
2297
0
  if (!fileSet) {
2298
0
    this->Makefile->IssueMessage(
2299
0
      MessageType::FATAL_ERROR,
2300
0
      cmStrCat(description, "has not yet been created."));
2301
0
    return;
2302
0
  }
2303
0
  if (fileSet->GetType() != fileSetType) {
2304
0
    this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
2305
0
                                 cmStrCat("File set \"", fileSetName,
2306
0
                                          "\" is not of type \"", fileSetType,
2307
0
                                          "\"."));
2308
0
    return;
2309
0
  }
2310
0
  if (action == FileSetType::Action::Set) {
2311
0
    fileSet->ClearDirectoryEntries();
2312
0
  }
2313
0
  if (cmNonempty(value)) {
2314
0
    fileSet->AddDirectoryEntry(
2315
0
      BT<std::string>(value, this->Makefile->GetBacktrace()));
2316
0
  }
2317
0
}
Unexecuted instantiation: cmTarget.cxx:void cmTargetInternals::AddDirectoryToFileSet<cmValue>(cmTarget*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cmValue, std::__1::basic_string_view<char, std::__1::char_traits<char> >, std::__1::basic_string_view<char, std::__1::char_traits<char> >, (anonymous namespace)::FileSetType::Action)
Unexecuted instantiation: cmTarget.cxx:void cmTargetInternals::AddDirectoryToFileSet<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(cmTarget*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string_view<char, std::__1::char_traits<char> >, std::__1::basic_string_view<char, std::__1::char_traits<char> >, (anonymous namespace)::FileSetType::Action)
2318
2319
template <typename ValueType>
2320
void cmTargetInternals::AddPathToFileSet(cmTarget* self,
2321
                                         std::string const& fileSetName,
2322
                                         ValueType value,
2323
                                         cm::string_view fileSetType,
2324
                                         cm::string_view description,
2325
                                         FileSetType::Action action)
2326
0
{
2327
0
  auto* fileSet = self->GetFileSet(fileSetName);
2328
0
  if (!fileSet) {
2329
0
    this->Makefile->IssueMessage(
2330
0
      MessageType::FATAL_ERROR,
2331
0
      cmStrCat(description, "has not yet been created."));
2332
0
    return;
2333
0
  }
2334
0
  if (fileSet->GetType() != fileSetType) {
2335
0
    this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
2336
0
                                 cmStrCat("File set \"", fileSetName,
2337
0
                                          "\" is not of type \"", fileSetType,
2338
0
                                          "\"."));
2339
0
    return;
2340
0
  }
2341
0
  if (action == FileSetType::Action::Set) {
2342
0
    fileSet->ClearFileEntries();
2343
0
  }
2344
0
  if (cmNonempty(value)) {
2345
0
    fileSet->AddFileEntry(
2346
0
      BT<std::string>(value, this->Makefile->GetBacktrace()));
2347
0
  }
2348
0
}
Unexecuted instantiation: cmTarget.cxx:void cmTargetInternals::AddPathToFileSet<cmValue>(cmTarget*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cmValue, std::__1::basic_string_view<char, std::__1::char_traits<char> >, std::__1::basic_string_view<char, std::__1::char_traits<char> >, (anonymous namespace)::FileSetType::Action)
Unexecuted instantiation: cmTarget.cxx:void cmTargetInternals::AddPathToFileSet<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(cmTarget*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string_view<char, std::__1::char_traits<char> >, std::__1::basic_string_view<char, std::__1::char_traits<char> >, (anonymous namespace)::FileSetType::Action)
2349
2350
cmValue cmTargetInternals::GetFileSetDirectories(
2351
  cmTarget const* self, std::string const& fileSetName,
2352
  cm::string_view fileSetType) const
2353
0
{
2354
0
  auto const* fileSet = self->GetFileSet(fileSetName);
2355
0
  if (!fileSet) {
2356
0
    return nullptr;
2357
0
  }
2358
0
  if (fileSet->GetType() != fileSetType) {
2359
0
    this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
2360
0
                                 cmStrCat("File set \"", fileSetName,
2361
0
                                          "\" is not of type \"", fileSetType,
2362
0
                                          "\"."));
2363
0
    return nullptr;
2364
0
  }
2365
0
  static std::string output;
2366
0
  output = cmList::to_string(fileSet->GetDirectoryEntries());
2367
0
  return cmValue(output);
2368
0
}
2369
2370
cmValue cmTargetInternals::GetFileSetPaths(cmTarget const* self,
2371
                                           std::string const& fileSetName,
2372
                                           cm::string_view fileSetType) const
2373
0
{
2374
0
  auto const* fileSet = self->GetFileSet(fileSetName);
2375
0
  if (!fileSet) {
2376
0
    return nullptr;
2377
0
  }
2378
0
  if (fileSet->GetType() != fileSetType) {
2379
0
    this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
2380
0
                                 cmStrCat("File set \"", fileSetName,
2381
0
                                          "\" is not of type \"", fileSetType,
2382
0
                                          "\"."));
2383
0
    return nullptr;
2384
0
  }
2385
0
  static std::string output;
2386
0
  output = cmList::to_string(fileSet->GetFileEntries());
2387
0
  return cmValue(output);
2388
0
}
2389
2390
void cmTarget::AppendBuildInterfaceIncludes()
2391
0
{
2392
0
  if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
2393
0
      this->GetType() != cmStateEnums::STATIC_LIBRARY &&
2394
0
      this->GetType() != cmStateEnums::MODULE_LIBRARY &&
2395
0
      this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
2396
0
      !this->IsExecutableWithExports()) {
2397
0
    return;
2398
0
  }
2399
0
  if (this->impl->BuildInterfaceIncludesAppended) {
2400
0
    return;
2401
0
  }
2402
0
  this->impl->BuildInterfaceIncludesAppended = true;
2403
2404
0
  if (this->impl->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE")) {
2405
0
    std::string dirs = this->impl->Makefile->GetCurrentBinaryDirectory();
2406
0
    if (!dirs.empty()) {
2407
0
      dirs += ';';
2408
0
    }
2409
0
    dirs += this->impl->Makefile->GetCurrentSourceDirectory();
2410
0
    if (!dirs.empty()) {
2411
0
      this->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
2412
0
                           ("$<BUILD_INTERFACE:" + dirs + ">"));
2413
0
    }
2414
0
  }
2415
0
}
2416
2417
namespace {
2418
bool CheckLinkLibraryPattern(UsageRequirementProperty const& usage,
2419
                             cmake* context)
2420
0
{
2421
  // Look for <LINK_LIBRARY:> and </LINK_LIBRARY:> internal tags
2422
0
  static cmsys::RegularExpression linkPattern(
2423
0
    "(^|;)(</?LINK_(LIBRARY|GROUP):[^;>]*>)(;|$)");
2424
2425
0
  bool isValid = true;
2426
2427
0
  for (auto const& item : usage.Entries) {
2428
0
    if (!linkPattern.find(item.Value)) {
2429
0
      continue;
2430
0
    }
2431
2432
0
    isValid = false;
2433
2434
    // Report an error.
2435
0
    context->IssueMessage(
2436
0
      MessageType::FATAL_ERROR,
2437
0
      cmStrCat(
2438
0
        "Property ", usage.Name, " contains the invalid item \"",
2439
0
        linkPattern.match(2), "\". The ", usage.Name,
2440
0
        " property may contain the generator-expression \"$<LINK_",
2441
0
        linkPattern.match(3),
2442
0
        ":...>\" which may be used to specify how the libraries are linked."),
2443
0
      item.Backtrace);
2444
0
  }
2445
2446
0
  return isValid;
2447
0
}
2448
}
2449
2450
void cmTarget::FinalizeTargetConfiguration(cmBTStringRange compileDefinitions)
2451
0
{
2452
0
  if (this->GetType() == cmStateEnums::GLOBAL_TARGET) {
2453
0
    return;
2454
0
  }
2455
2456
0
  if (!CheckLinkLibraryPattern(this->impl->LinkLibraries,
2457
0
                               this->GetMakefile()->GetCMakeInstance()) ||
2458
0
      !CheckLinkLibraryPattern(this->impl->InterfaceLinkLibraries,
2459
0
                               this->GetMakefile()->GetCMakeInstance()) ||
2460
0
      !CheckLinkLibraryPattern(this->impl->InterfaceLinkLibrariesDirect,
2461
0
                               this->GetMakefile()->GetCMakeInstance())) {
2462
0
    return;
2463
0
  }
2464
2465
0
  this->AppendBuildInterfaceIncludes();
2466
2467
0
  if (this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
2468
0
    return;
2469
0
  }
2470
2471
0
  for (auto const& def : compileDefinitions) {
2472
0
    this->InsertCompileDefinition(def);
2473
0
  }
2474
0
}
2475
2476
void cmTarget::InsertInclude(BT<std::string> const& entry, bool before)
2477
0
{
2478
0
  this->impl->IncludeDirectories.WriteDirect(
2479
0
    entry,
2480
0
    before ? UsageRequirementProperty::Action::Prepend
2481
0
           : UsageRequirementProperty::Action::Append);
2482
0
}
2483
2484
void cmTarget::InsertCompileOption(BT<std::string> const& entry, bool before)
2485
0
{
2486
0
  this->impl->CompileOptions.WriteDirect(
2487
0
    entry,
2488
0
    before ? UsageRequirementProperty::Action::Prepend
2489
0
           : UsageRequirementProperty::Action::Append);
2490
0
}
2491
2492
void cmTarget::InsertCompileDefinition(BT<std::string> const& entry)
2493
0
{
2494
0
  this->impl->CompileDefinitions.WriteDirect(
2495
0
    entry, UsageRequirementProperty::Action::Append);
2496
0
}
2497
2498
void cmTarget::InsertLinkOption(BT<std::string> const& entry, bool before)
2499
0
{
2500
0
  this->impl->LinkOptions.WriteDirect(
2501
0
    entry,
2502
0
    before ? UsageRequirementProperty::Action::Prepend
2503
0
           : UsageRequirementProperty::Action::Append);
2504
0
}
2505
2506
void cmTarget::InsertLinkDirectory(BT<std::string> const& entry, bool before)
2507
0
{
2508
0
  this->impl->LinkDirectories.WriteDirect(
2509
0
    entry,
2510
0
    before ? UsageRequirementProperty::Action::Prepend
2511
0
           : UsageRequirementProperty::Action::Append);
2512
0
}
2513
2514
void cmTarget::InsertPrecompileHeader(BT<std::string> const& entry)
2515
0
{
2516
0
  this->impl->PrecompileHeaders.WriteDirect(
2517
0
    entry, UsageRequirementProperty::Action::Append);
2518
0
}
2519
2520
namespace {
2521
void CheckLINK_INTERFACE_LIBRARIES(std::string const& prop,
2522
                                   std::string const& value,
2523
                                   cmMakefile* context, bool imported)
2524
0
{
2525
  // Support imported and non-imported versions of the property.
2526
0
  char const* base = (imported ? "IMPORTED_LINK_INTERFACE_LIBRARIES"
2527
0
                               : "LINK_INTERFACE_LIBRARIES");
2528
2529
  // Look for link-type keywords in the value.
2530
0
  static cmsys::RegularExpression keys("(^|;)(debug|optimized|general)(;|$)");
2531
0
  if (keys.find(value)) {
2532
    // Report an error.
2533
0
    std::ostringstream e;
2534
0
    e << "Property " << prop << " may not contain link-type keyword \""
2535
0
      << keys.match(2) << "\".  "
2536
0
      << "The " << base << " property has a per-configuration "
2537
0
      << "version called " << base << "_<CONFIG> which may be "
2538
0
      << "used to specify per-configuration rules.";
2539
0
    if (!imported) {
2540
0
      e << "  "
2541
0
        << "Alternatively, an IMPORTED library may be created, configured "
2542
0
        << "with a per-configuration location, and then named in the "
2543
0
        << "property value.  "
2544
0
        << "See the add_library command's IMPORTED mode for details."
2545
0
        << "\n"
2546
0
        << "If you have a list of libraries that already contains the "
2547
0
        << "keyword, use the target_link_libraries command with its "
2548
0
        << "LINK_INTERFACE_LIBRARIES mode to set the property.  "
2549
0
        << "The command automatically recognizes link-type keywords and sets "
2550
0
        << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
2551
0
        << "properties accordingly.";
2552
0
    }
2553
0
    context->IssueMessage(MessageType::FATAL_ERROR, e.str());
2554
0
  }
2555
0
}
2556
2557
void CheckINTERFACE_LINK_LIBRARIES(std::string const& value,
2558
                                   cmMakefile* context)
2559
0
{
2560
  // Look for link-type keywords in the value.
2561
0
  static cmsys::RegularExpression keys("(^|;)(debug|optimized|general)(;|$)");
2562
0
  if (keys.find(value)) {
2563
    // Report an error.
2564
0
    std::ostringstream e;
2565
2566
0
    e << "Property INTERFACE_LINK_LIBRARIES may not contain link-type "
2567
0
         "keyword \""
2568
0
      << keys.match(2)
2569
0
      << "\".  The INTERFACE_LINK_LIBRARIES "
2570
0
         "property may contain configuration-sensitive generator-expressions "
2571
0
         "which may be used to specify per-configuration rules.";
2572
2573
0
    context->IssueMessage(MessageType::FATAL_ERROR, e.str());
2574
0
  }
2575
0
}
2576
2577
void CheckIMPORTED_GLOBAL(cmTarget const* target, cmMakefile* context)
2578
0
{
2579
0
  auto const& targets = context->GetOwnedImportedTargets();
2580
0
  auto it =
2581
0
    std::find_if(targets.begin(), targets.end(),
2582
0
                 [&](std::unique_ptr<cmTarget> const& importTarget) -> bool {
2583
0
                   return target == importTarget.get();
2584
0
                 });
2585
0
  if (it == targets.end()) {
2586
0
    std::ostringstream e;
2587
0
    e << "Attempt to promote imported target \"" << target->GetName()
2588
0
      << "\" to global scope (by setting IMPORTED_GLOBAL) "
2589
0
         "which is not built in this directory.";
2590
0
    context->IssueMessage(MessageType::FATAL_ERROR, e.str());
2591
0
  }
2592
0
}
2593
}
2594
2595
void cmTarget::CheckProperty(std::string const& prop,
2596
                             cmMakefile* context) const
2597
0
{
2598
  // Certain properties need checking.
2599
0
  if (cmHasLiteralPrefix(prop, "LINK_INTERFACE_LIBRARIES")) {
2600
0
    if (cmValue value = this->GetProperty(prop)) {
2601
0
      CheckLINK_INTERFACE_LIBRARIES(prop, *value, context, false);
2602
0
    }
2603
0
  } else if (cmHasLiteralPrefix(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES")) {
2604
0
    if (cmValue value = this->GetProperty(prop)) {
2605
0
      CheckLINK_INTERFACE_LIBRARIES(prop, *value, context, true);
2606
0
    }
2607
0
  } else if (prop == "INTERFACE_LINK_LIBRARIES") {
2608
0
    if (cmValue value = this->GetProperty(prop)) {
2609
0
      CheckINTERFACE_LINK_LIBRARIES(*value, context);
2610
0
    }
2611
0
  } else if (prop == "IMPORTED_GLOBAL") {
2612
0
    if (this->IsImported()) {
2613
0
      CheckIMPORTED_GLOBAL(this, context);
2614
0
    }
2615
0
  }
2616
0
}
2617
2618
cmValue cmTarget::GetComputedProperty(std::string const& prop,
2619
                                      cmMakefile& mf) const
2620
0
{
2621
0
  return cmTargetPropertyComputer::GetProperty(this, prop, mf);
2622
0
}
2623
2624
cmValue cmTarget::GetProperty(std::string const& prop) const
2625
0
{
2626
0
  static std::unordered_set<std::string> const specialProps{
2627
0
    propC_STANDARD,
2628
0
    propCXX_STANDARD,
2629
0
    propCUDA_STANDARD,
2630
0
    propHIP_STANDARD,
2631
0
    propOBJC_STANDARD,
2632
0
    propOBJCXX_STANDARD,
2633
0
    propLINK_LIBRARIES,
2634
0
    propTYPE,
2635
0
    propINCLUDE_DIRECTORIES,
2636
0
    propCOMPILE_FEATURES,
2637
0
    propCOMPILE_OPTIONS,
2638
0
    propCOMPILE_DEFINITIONS,
2639
0
    propPRECOMPILE_HEADERS,
2640
0
    propLINK_OPTIONS,
2641
0
    propLINK_DIRECTORIES,
2642
0
    propIMPORTED,
2643
0
    propIMPORTED_GLOBAL,
2644
0
    propMANUALLY_ADDED_DEPENDENCIES,
2645
0
    propNAME,
2646
0
    propBINARY_DIR,
2647
0
    propSOURCE_DIR,
2648
0
    propSOURCES,
2649
0
    propSYMBOLIC,
2650
0
    propINTERFACE_LINK_LIBRARIES,
2651
0
    propINTERFACE_LINK_LIBRARIES_DIRECT,
2652
0
    propINTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE,
2653
0
    propIMPORTED_CXX_MODULES_INCLUDE_DIRECTORIES,
2654
0
    propIMPORTED_CXX_MODULES_COMPILE_DEFINITIONS,
2655
0
    propIMPORTED_CXX_MODULES_COMPILE_FEATURES,
2656
0
    propIMPORTED_CXX_MODULES_COMPILE_OPTIONS,
2657
0
    propIMPORTED_CXX_MODULES_LINK_LIBRARIES,
2658
0
  };
2659
0
  if (specialProps.count(prop)) {
2660
0
    if (prop == propC_STANDARD || prop == propCXX_STANDARD ||
2661
0
        prop == propCUDA_STANDARD || prop == propHIP_STANDARD ||
2662
0
        prop == propOBJC_STANDARD || prop == propOBJCXX_STANDARD) {
2663
0
      auto propertyIter = this->impl->LanguageStandardProperties.find(prop);
2664
0
      if (propertyIter == this->impl->LanguageStandardProperties.end()) {
2665
0
        return nullptr;
2666
0
      }
2667
0
      return cmValue(propertyIter->second.Value);
2668
0
    }
2669
2670
0
    if (prop == propSYMBOLIC) {
2671
0
      return this->IsSymbolic() ? cmValue(propTRUE) : cmValue(propFALSE);
2672
0
    }
2673
2674
0
    UsageRequirementProperty const* usageRequirements[] = {
2675
0
      &this->impl->IncludeDirectories,
2676
0
      &this->impl->CompileOptions,
2677
0
      &this->impl->CompileFeatures,
2678
0
      &this->impl->CompileDefinitions,
2679
0
      &this->impl->PrecompileHeaders,
2680
0
      &this->impl->Sources,
2681
0
      &this->impl->LinkOptions,
2682
0
      &this->impl->LinkDirectories,
2683
0
      &this->impl->LinkLibraries,
2684
0
      &this->impl->InterfaceLinkLibraries,
2685
0
      &this->impl->InterfaceLinkLibrariesDirect,
2686
0
      &this->impl->InterfaceLinkLibrariesDirectExclude,
2687
0
      &this->impl->ImportedCxxModulesIncludeDirectories,
2688
0
      &this->impl->ImportedCxxModulesCompileDefinitions,
2689
0
      &this->impl->ImportedCxxModulesCompileFeatures,
2690
0
      &this->impl->ImportedCxxModulesCompileOptions,
2691
0
      &this->impl->ImportedCxxModulesLinkLibraries,
2692
0
    };
2693
2694
0
    for (auto const* usageRequirement : usageRequirements) {
2695
0
      auto value = usageRequirement->Read(prop);
2696
0
      if (value.first) {
2697
0
        return value.second;
2698
0
      }
2699
0
    }
2700
2701
    // the type property returns what type the target is
2702
0
    if (prop == propTYPE) {
2703
0
      return cmValue(cmState::GetTargetTypeName(this->GetType()));
2704
0
    }
2705
0
    if (prop == propMANUALLY_ADDED_DEPENDENCIES) {
2706
0
      if (this->impl->Utilities.empty()) {
2707
0
        return nullptr;
2708
0
      }
2709
2710
0
      static std::string output;
2711
0
      static std::vector<std::string> utilities;
2712
0
      utilities.resize(this->impl->Utilities.size());
2713
0
      std::transform(
2714
0
        this->impl->Utilities.cbegin(), this->impl->Utilities.cend(),
2715
0
        utilities.begin(),
2716
0
        [](const BT<std::pair<std::string, bool>>& item) -> std::string {
2717
0
          return item.Value.first;
2718
0
        });
2719
0
      output = cmList::to_string(utilities);
2720
0
      return cmValue(output);
2721
0
    }
2722
0
    if (prop == propIMPORTED) {
2723
0
      return this->IsImported() ? cmValue(propTRUE) : cmValue(propFALSE);
2724
0
    }
2725
0
    if (prop == propIMPORTED_GLOBAL) {
2726
0
      return this->IsImportedGloballyVisible() ? cmValue(propTRUE)
2727
0
                                               : cmValue(propFALSE);
2728
0
    }
2729
0
    if (prop == propNAME) {
2730
0
      return cmValue(this->GetName());
2731
0
    }
2732
0
    if (prop == propBINARY_DIR) {
2733
0
      return cmValue(this->impl->Makefile->GetStateSnapshot()
2734
0
                       .GetDirectory()
2735
0
                       .GetCurrentBinary());
2736
0
    }
2737
0
    if (prop == propSOURCE_DIR) {
2738
0
      return cmValue(this->impl->Makefile->GetStateSnapshot()
2739
0
                       .GetDirectory()
2740
0
                       .GetCurrentSource());
2741
0
    }
2742
0
  }
2743
2744
  // Check fileset properties.
2745
0
  {
2746
0
    for (auto const& fileSetType : this->impl->FileSetTypes) {
2747
0
      auto value =
2748
0
        fileSetType.second.ReadProperties(this, this->impl.get(), prop);
2749
0
      if (value.first) {
2750
0
        return value.second;
2751
0
      }
2752
0
    }
2753
0
  }
2754
2755
0
  cmValue retVal = this->impl->Properties.GetPropertyValue(prop);
2756
0
  if (!retVal) {
2757
0
    bool const chain = this->impl->Makefile->GetState()->IsPropertyChained(
2758
0
      prop, cmProperty::TARGET);
2759
0
    if (chain) {
2760
0
      return this->impl->Makefile->GetStateSnapshot()
2761
0
        .GetDirectory()
2762
0
        .GetProperty(prop, chain);
2763
0
    }
2764
0
    return nullptr;
2765
0
  }
2766
0
  return retVal;
2767
0
}
2768
2769
std::string const& cmTarget::GetSafeProperty(std::string const& prop) const
2770
0
{
2771
0
  cmValue ret = this->GetProperty(prop);
2772
0
  if (ret) {
2773
0
    return *ret;
2774
0
  }
2775
2776
0
  static std::string const s_empty;
2777
0
  return s_empty;
2778
0
}
2779
2780
bool cmTarget::GetPropertyAsBool(std::string const& prop) const
2781
0
{
2782
0
  return this->GetProperty(prop).IsOn();
2783
0
}
2784
2785
cmPropertyMap const& cmTarget::GetProperties() const
2786
0
{
2787
0
  return this->impl->Properties;
2788
0
}
2789
2790
bool cmTarget::IsDLLPlatform() const
2791
0
{
2792
0
  return this->impl->IsDLLPlatform;
2793
0
}
2794
2795
bool cmTarget::IsAIX() const
2796
0
{
2797
0
  return this->impl->IsAIX;
2798
0
}
2799
bool cmTarget::IsApple() const
2800
0
{
2801
0
  return this->impl->IsApple;
2802
0
}
2803
2804
bool cmTarget::IsSymbolic() const
2805
0
{
2806
0
  return this->impl->IsSymbolic;
2807
0
}
2808
2809
bool cmTarget::IsNormal() const
2810
0
{
2811
0
  switch (this->impl->TargetVisibility) {
2812
0
    case Visibility::Normal:
2813
0
      return true;
2814
0
    case Visibility::Generated:
2815
0
    case Visibility::Imported:
2816
0
    case Visibility::ImportedGlobally:
2817
0
    case Visibility::Foreign:
2818
0
      return false;
2819
0
  }
2820
0
  assert(false && "unknown visibility (IsNormal)");
2821
0
  return false;
2822
0
}
2823
2824
bool cmTarget::IsSynthetic() const
2825
0
{
2826
0
  switch (this->impl->TargetVisibility) {
2827
0
    case Visibility::Generated:
2828
0
      return true;
2829
0
    case Visibility::Normal:
2830
0
    case Visibility::Imported:
2831
0
    case Visibility::ImportedGlobally:
2832
0
    case Visibility::Foreign:
2833
0
      return false;
2834
0
  }
2835
0
  assert(false && "unknown visibility (IsSynthetic)");
2836
0
  return false;
2837
0
}
2838
2839
bool cmTargetInternals::IsImported() const
2840
0
{
2841
0
  switch (this->TargetVisibility) {
2842
0
    case cmTarget::Visibility::Imported:
2843
0
    case cmTarget::Visibility::ImportedGlobally:
2844
0
    case cmTarget::Visibility::Foreign:
2845
0
      return true;
2846
0
    case cmTarget::Visibility::Normal:
2847
0
    case cmTarget::Visibility::Generated:
2848
0
      return false;
2849
0
  }
2850
0
  assert(false && "unknown visibility (IsImported)");
2851
0
  return false;
2852
0
}
2853
2854
bool cmTarget::IsImported() const
2855
0
{
2856
0
  return this->impl->IsImported();
2857
0
}
2858
2859
bool cmTarget::IsImportedGloballyVisible() const
2860
0
{
2861
0
  switch (this->impl->TargetVisibility) {
2862
0
    case Visibility::ImportedGlobally:
2863
0
      return true;
2864
0
    case Visibility::Normal:
2865
0
    case Visibility::Generated:
2866
0
    case Visibility::Imported:
2867
0
    case Visibility::Foreign:
2868
0
      return false;
2869
0
  }
2870
0
  assert(false && "unknown visibility (IsImportedGloballyVisible)");
2871
0
  return false;
2872
0
}
2873
2874
bool cmTarget::IsForeign() const
2875
0
{
2876
0
  switch (this->impl->TargetVisibility) {
2877
0
    case Visibility::Foreign:
2878
0
      return true;
2879
0
    case Visibility::Normal:
2880
0
    case Visibility::Generated:
2881
0
    case Visibility::Imported:
2882
0
    case Visibility::ImportedGlobally:
2883
0
      return false;
2884
0
  }
2885
0
  assert(false && "unknown visibility (isForeign)");
2886
0
  return false;
2887
0
}
2888
2889
bool cmTarget::IsPerConfig() const
2890
0
{
2891
0
  return this->impl->PerConfig;
2892
0
}
2893
2894
bool cmTarget::IsRuntimeBinary() const
2895
0
{
2896
0
  switch (this->GetType()) {
2897
0
    case cmStateEnums::EXECUTABLE:
2898
0
    case cmStateEnums::SHARED_LIBRARY:
2899
0
    case cmStateEnums::MODULE_LIBRARY:
2900
0
      return true;
2901
0
    case cmStateEnums::OBJECT_LIBRARY:
2902
0
    case cmStateEnums::STATIC_LIBRARY:
2903
0
    case cmStateEnums::UTILITY:
2904
0
    case cmStateEnums::INTERFACE_LIBRARY:
2905
0
    case cmStateEnums::GLOBAL_TARGET:
2906
0
    case cmStateEnums::UNKNOWN_LIBRARY:
2907
0
      break;
2908
0
  }
2909
0
  return false;
2910
0
}
2911
2912
bool cmTarget::CanCompileSources() const
2913
0
{
2914
0
  if (this->IsImported()) {
2915
0
    return false;
2916
0
  }
2917
0
  if (this->IsSynthetic()) {
2918
0
    return true;
2919
0
  }
2920
0
  switch (this->GetType()) {
2921
0
    case cmStateEnums::EXECUTABLE:
2922
0
    case cmStateEnums::STATIC_LIBRARY:
2923
0
    case cmStateEnums::SHARED_LIBRARY:
2924
0
    case cmStateEnums::MODULE_LIBRARY:
2925
0
    case cmStateEnums::OBJECT_LIBRARY:
2926
0
      return true;
2927
0
    case cmStateEnums::UTILITY:
2928
0
    case cmStateEnums::INTERFACE_LIBRARY:
2929
0
    case cmStateEnums::GLOBAL_TARGET:
2930
0
    case cmStateEnums::UNKNOWN_LIBRARY:
2931
0
      break;
2932
0
  }
2933
0
  return false;
2934
0
}
2935
2936
void cmTarget::SetIsForTryCompile()
2937
0
{
2938
0
  this->impl->IsForTryCompile = true;
2939
0
}
2940
2941
bool cmTarget::IsForTryCompile() const
2942
0
{
2943
0
  return this->impl->IsForTryCompile;
2944
0
}
2945
2946
char const* cmTarget::GetSuffixVariableInternal(
2947
  cmStateEnums::ArtifactType artifact) const
2948
0
{
2949
0
  switch (this->GetType()) {
2950
0
    case cmStateEnums::STATIC_LIBRARY:
2951
0
      return "CMAKE_STATIC_LIBRARY_SUFFIX";
2952
0
    case cmStateEnums::SHARED_LIBRARY:
2953
0
      switch (artifact) {
2954
0
        case cmStateEnums::RuntimeBinaryArtifact:
2955
0
          return this->IsArchivedAIXSharedLibrary()
2956
0
            ? "CMAKE_SHARED_LIBRARY_ARCHIVE_SUFFIX"
2957
0
            : "CMAKE_SHARED_LIBRARY_SUFFIX";
2958
0
        case cmStateEnums::ImportLibraryArtifact:
2959
0
          return this->IsApple() ? "CMAKE_APPLE_IMPORT_FILE_SUFFIX"
2960
0
                                 : "CMAKE_IMPORT_LIBRARY_SUFFIX";
2961
0
      }
2962
0
      break;
2963
0
    case cmStateEnums::MODULE_LIBRARY:
2964
0
      switch (artifact) {
2965
0
        case cmStateEnums::RuntimeBinaryArtifact:
2966
0
          return "CMAKE_SHARED_MODULE_SUFFIX";
2967
0
        case cmStateEnums::ImportLibraryArtifact:
2968
0
          return "CMAKE_IMPORT_LIBRARY_SUFFIX";
2969
0
      }
2970
0
      break;
2971
0
    case cmStateEnums::EXECUTABLE:
2972
0
      switch (artifact) {
2973
0
        case cmStateEnums::RuntimeBinaryArtifact:
2974
          // Android GUI application packages store the native
2975
          // binary as a shared library.
2976
0
          return (this->IsAndroidGuiExecutable()
2977
0
                    ? "CMAKE_SHARED_LIBRARY_SUFFIX"
2978
0
                    : "CMAKE_EXECUTABLE_SUFFIX");
2979
0
        case cmStateEnums::ImportLibraryArtifact:
2980
0
          return (this->impl->IsAIX ? "CMAKE_AIX_IMPORT_FILE_SUFFIX"
2981
0
                                    : "CMAKE_IMPORT_LIBRARY_SUFFIX");
2982
0
      }
2983
0
      break;
2984
0
    default:
2985
0
      break;
2986
0
  }
2987
0
  return "";
2988
0
}
2989
2990
char const* cmTarget::GetPrefixVariableInternal(
2991
  cmStateEnums::ArtifactType artifact) const
2992
0
{
2993
0
  switch (this->GetType()) {
2994
0
    case cmStateEnums::STATIC_LIBRARY:
2995
0
      return "CMAKE_STATIC_LIBRARY_PREFIX";
2996
0
    case cmStateEnums::SHARED_LIBRARY:
2997
0
      switch (artifact) {
2998
0
        case cmStateEnums::RuntimeBinaryArtifact:
2999
0
          return "CMAKE_SHARED_LIBRARY_PREFIX";
3000
0
        case cmStateEnums::ImportLibraryArtifact:
3001
0
          return this->IsApple() ? "CMAKE_APPLE_IMPORT_FILE_PREFIX"
3002
0
                                 : "CMAKE_IMPORT_LIBRARY_PREFIX";
3003
0
      }
3004
0
      break;
3005
0
    case cmStateEnums::MODULE_LIBRARY:
3006
0
      switch (artifact) {
3007
0
        case cmStateEnums::RuntimeBinaryArtifact:
3008
0
          return "CMAKE_SHARED_MODULE_PREFIX";
3009
0
        case cmStateEnums::ImportLibraryArtifact:
3010
0
          return "CMAKE_IMPORT_LIBRARY_PREFIX";
3011
0
      }
3012
0
      break;
3013
0
    case cmStateEnums::EXECUTABLE:
3014
0
      switch (artifact) {
3015
0
        case cmStateEnums::RuntimeBinaryArtifact:
3016
          // Android GUI application packages store the native
3017
          // binary as a shared library.
3018
0
          return (this->IsAndroidGuiExecutable()
3019
0
                    ? "CMAKE_SHARED_LIBRARY_PREFIX"
3020
0
                    : "");
3021
0
        case cmStateEnums::ImportLibraryArtifact:
3022
0
          return (this->impl->IsAIX ? "CMAKE_AIX_IMPORT_FILE_PREFIX"
3023
0
                                    : "CMAKE_IMPORT_LIBRARY_PREFIX");
3024
0
      }
3025
0
      break;
3026
0
    default:
3027
0
      break;
3028
0
  }
3029
0
  return "";
3030
0
}
3031
3032
std::string cmTarget::ImportedGetFullPath(
3033
  std::string const& config, cmStateEnums::ArtifactType artifact,
3034
  ImportArtifactMissingOk missingOk) const
3035
0
{
3036
0
  assert(this->IsImported());
3037
3038
  // Lookup/compute/cache the import information for this
3039
  // configuration.
3040
0
  std::string desired_config = config;
3041
0
  if (config.empty()) {
3042
0
    desired_config = "NOCONFIG";
3043
0
  }
3044
3045
0
  std::string result;
3046
3047
0
  cmValue loc = nullptr;
3048
0
  cmValue imp = nullptr;
3049
0
  std::string suffix;
3050
3051
0
  if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
3052
0
      this->GetMappedConfig(desired_config, loc, imp, suffix)) {
3053
0
    switch (artifact) {
3054
0
      case cmStateEnums::RuntimeBinaryArtifact:
3055
0
        if (loc) {
3056
0
          result = *loc;
3057
0
        } else if (imp) {
3058
0
          result = *imp;
3059
0
        } else {
3060
0
          std::string impProp = cmStrCat("IMPORTED_LOCATION", suffix);
3061
0
          if (cmValue config_location = this->GetProperty(impProp)) {
3062
0
            result = *config_location;
3063
0
          } else if (cmValue location =
3064
0
                       this->GetProperty("IMPORTED_LOCATION")) {
3065
0
            result = *location;
3066
0
          }
3067
0
          if (result.empty() &&
3068
0
              (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
3069
0
               this->IsExecutableWithExports())) {
3070
0
            impProp = cmStrCat("IMPORTED_IMPLIB", suffix);
3071
0
            if (cmValue config_implib = this->GetProperty(impProp)) {
3072
0
              result = *config_implib;
3073
0
            } else if (cmValue implib = this->GetProperty("IMPORTED_IMPLIB")) {
3074
0
              result = *implib;
3075
0
            }
3076
0
          }
3077
0
        }
3078
0
        if (this->IsApple() &&
3079
0
            (this->impl->TargetType == cmStateEnums::SHARED_LIBRARY ||
3080
0
             this->impl->TargetType == cmStateEnums::STATIC_LIBRARY ||
3081
0
             this->impl->TargetType == cmStateEnums::UNKNOWN_LIBRARY) &&
3082
0
            cmSystemTools::IsPathToXcFramework(result)) {
3083
0
          auto plist = cmParseXcFrameworkPlist(result, *this->impl->Makefile,
3084
0
                                               this->impl->Backtrace);
3085
0
          if (!plist) {
3086
0
            return "";
3087
0
          }
3088
0
          auto const* library = plist->SelectSuitableLibrary(
3089
0
            *this->impl->Makefile, this->impl->Backtrace);
3090
0
          if (library) {
3091
0
            result = cmStrCat(result, '/', library->LibraryIdentifier, '/',
3092
0
                              library->LibraryPath);
3093
0
          } else {
3094
0
            return "";
3095
0
          }
3096
0
        }
3097
0
        break;
3098
3099
0
      case cmStateEnums::ImportLibraryArtifact:
3100
0
        if (imp) {
3101
0
          result = *imp;
3102
0
        } else if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
3103
0
                   this->IsExecutableWithExports()) {
3104
0
          std::string impProp = cmStrCat("IMPORTED_IMPLIB", suffix);
3105
0
          if (cmValue config_implib = this->GetProperty(impProp)) {
3106
0
            result = *config_implib;
3107
0
          } else if (cmValue implib = this->GetProperty("IMPORTED_IMPLIB")) {
3108
0
            result = *implib;
3109
0
          }
3110
0
        }
3111
0
        break;
3112
0
    }
3113
0
  }
3114
3115
0
  if (result.empty() && missingOk != ImportArtifactMissingOk::Yes) {
3116
0
    if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
3117
0
      auto message = [&]() -> std::string {
3118
0
        std::string unset;
3119
0
        std::string configuration;
3120
3121
0
        if (this->GetType() == cmStateEnums::SHARED_LIBRARY &&
3122
0
            artifact == cmStateEnums::RuntimeBinaryArtifact) {
3123
0
          unset = "IMPORTED_LOCATION or IMPORTED_IMPLIB";
3124
0
        } else if (artifact == cmStateEnums::RuntimeBinaryArtifact) {
3125
0
          unset = "IMPORTED_LOCATION";
3126
0
        } else if (artifact == cmStateEnums::ImportLibraryArtifact) {
3127
0
          unset = "IMPORTED_IMPLIB";
3128
0
        }
3129
3130
0
        if (!config.empty()) {
3131
0
          configuration = cmStrCat(" configuration \"", config, '"');
3132
0
        }
3133
3134
0
        return cmStrCat(unset, " not set for imported target \"",
3135
0
                        this->GetName(), '"', configuration, '.');
3136
0
      };
3137
3138
0
      switch (this->GetPolicyStatus(cmPolicies::CMP0111)) {
3139
0
        case cmPolicies::WARN:
3140
0
          this->impl->Makefile->IssueDiagnostic(
3141
0
            cmDiagnostics::CMD_AUTHOR,
3142
0
            cmPolicies::GetPolicyWarning(cmPolicies::CMP0111) + "\n" +
3143
0
              message());
3144
0
          CM_FALLTHROUGH;
3145
0
        case cmPolicies::OLD:
3146
0
          break;
3147
0
        default:
3148
0
          this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR,
3149
0
                                             message());
3150
0
      }
3151
0
    }
3152
3153
0
    result = cmStrCat(this->GetName(), "-NOTFOUND");
3154
0
  }
3155
0
  return result;
3156
0
}
3157
3158
cmFileSet const* cmTarget::GetFileSet(std::string const& name) const
3159
0
{
3160
0
  auto it = this->impl->FileSets.find(name);
3161
0
  return it == this->impl->FileSets.end() ? nullptr : &it->second;
3162
0
}
3163
3164
cmFileSet* cmTarget::GetFileSet(std::string const& name)
3165
0
{
3166
0
  auto it = this->impl->FileSets.find(name);
3167
0
  return it == this->impl->FileSets.end() ? nullptr : &it->second;
3168
0
}
3169
3170
std::pair<cmFileSet*, bool> cmTarget::GetOrCreateFileSet(
3171
  std::string const& name, std::string const& type,
3172
  cm::FileSetMetadata::Visibility vis)
3173
0
{
3174
0
  auto result = this->impl->FileSets.emplace(
3175
0
    name, cmFileSet(this->GetMakefile(), this, name, type, vis));
3176
0
  if (result.second) {
3177
0
    auto bt = this->impl->Makefile->GetBacktrace();
3178
0
    if (cm::contains(this->impl->FileSetTypes, type)) {
3179
0
      this->impl->FileSetTypes.at(type).AddFileSet(name, vis, std::move(bt));
3180
0
    }
3181
0
  }
3182
0
  return std::make_pair(&result.first->second, result.second);
3183
0
}
3184
3185
std::string cmTarget::GetFileSetsPropertyName(std::string const& type) const
3186
0
{
3187
0
  if (cm::contains(this->impl->FileSetTypes, type)) {
3188
0
    return std::string{
3189
0
      this->impl->FileSetTypes.at(type).SelfEntries.PropertyName
3190
0
    };
3191
0
  }
3192
0
  return "";
3193
0
}
3194
3195
std::string cmTarget::GetInterfaceFileSetsPropertyName(
3196
  std::string const& type) const
3197
0
{
3198
0
  if (cm::contains(this->impl->FileSetTypes, type)) {
3199
0
    return std::string{
3200
0
      this->impl->FileSetTypes.at(type).InterfaceEntries.PropertyName
3201
0
    };
3202
0
  }
3203
0
  return "";
3204
0
}
3205
3206
std::vector<std::string> cmTarget::GetAllFileSetNames() const
3207
0
{
3208
0
  std::vector<std::string> result;
3209
3210
0
  for (auto const& it : this->impl->FileSets) {
3211
0
    result.push_back(it.first);
3212
0
  }
3213
3214
0
  return result;
3215
0
}
3216
3217
namespace {
3218
std::vector<std::string> RetrieveFileSetNames(
3219
  std::unordered_map<cm::string_view, FileSetType> const& fileSetTypes,
3220
  std::function<
3221
    std::vector<BT<std::string>> const&(FileSetType const& fileSetType)>
3222
    GetFileSets)
3223
0
{
3224
0
  std::vector<std::string> result;
3225
0
  auto inserter = std::back_inserter(result);
3226
3227
0
  auto appendEntries = [=](std::vector<BT<std::string>> const& entries) {
3228
0
    for (auto const& entry : entries) {
3229
0
      cmList expanded{ entry.Value };
3230
0
      std::copy(expanded.begin(), expanded.end(), inserter);
3231
0
    }
3232
0
  };
3233
3234
0
  for (auto const& fileSetType : fileSetTypes) {
3235
0
    appendEntries(GetFileSets(fileSetType.second));
3236
0
  }
3237
3238
0
  return result;
3239
0
}
3240
}
3241
3242
std::vector<std::string> cmTarget::GetAllPrivateFileSets() const
3243
0
{
3244
0
  return RetrieveFileSetNames(
3245
0
    this->impl->FileSetTypes,
3246
0
    [](FileSetType const& fileSetType) -> std::vector<BT<std::string>> const& {
3247
0
      return fileSetType.SelfEntries.Entries;
3248
0
    });
3249
0
}
3250
3251
std::vector<std::string> cmTarget::GetAllInterfaceFileSets() const
3252
0
{
3253
0
  return RetrieveFileSetNames(
3254
0
    this->impl->FileSetTypes,
3255
0
    [](FileSetType const& fileSetType) -> std::vector<BT<std::string>> const& {
3256
0
      return fileSetType.InterfaceEntries.Entries;
3257
0
    });
3258
0
}
3259
3260
bool cmTarget::HasFileSets() const
3261
0
{
3262
0
  return !this->impl->FileSets.empty();
3263
0
}
3264
3265
bool cmTargetInternals::CheckImportedLibName(std::string const& prop,
3266
                                             std::string const& value) const
3267
0
{
3268
0
  if (this->TargetType != cmStateEnums::INTERFACE_LIBRARY ||
3269
0
      !this->IsImported()) {
3270
0
    this->Makefile->IssueMessage(
3271
0
      MessageType::FATAL_ERROR,
3272
0
      prop +
3273
0
        " property may be set only on imported INTERFACE library targets.");
3274
0
    return false;
3275
0
  }
3276
0
  if (!value.empty()) {
3277
0
    if (value[0] == '-') {
3278
0
      this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
3279
0
                                   prop + " property value\n  " + value +
3280
0
                                     "\nmay not start with '-'.");
3281
0
      return false;
3282
0
    }
3283
0
    std::string::size_type bad = value.find_first_of(":/\\;");
3284
0
    if (bad != std::string::npos) {
3285
0
      this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
3286
0
                                   prop + " property value\n  " + value +
3287
0
                                     "\nmay not contain '" +
3288
0
                                     value.substr(bad, 1) + "'.");
3289
0
      return false;
3290
0
    }
3291
0
  }
3292
0
  return true;
3293
0
}
3294
3295
bool cmTarget::GetMappedConfig(std::string const& desiredConfig, cmValue& loc,
3296
                               cmValue& imp, std::string& suffix) const
3297
0
{
3298
0
  switch (this->GetPolicyStatusCMP0200()) {
3299
0
    case cmPolicies::WARN:
3300
0
      if (this->GetMakefile()->PolicyOptionalWarningEnabled(
3301
0
            "CMAKE_POLICY_WARNING_CMP0200")) {
3302
0
        break;
3303
0
      }
3304
0
      CM_FALLTHROUGH;
3305
0
    case cmPolicies::OLD:
3306
0
      return this->GetMappedConfigOld(desiredConfig, loc, imp, suffix);
3307
0
    case cmPolicies::NEW:
3308
0
      return this->GetMappedConfigNew(desiredConfig, loc, imp, suffix);
3309
0
  }
3310
3311
0
  cmValue newLoc;
3312
0
  cmValue newImp;
3313
0
  std::string newSuffix;
3314
3315
0
  bool const newResult =
3316
0
    this->GetMappedConfigNew(desiredConfig, newLoc, newImp, newSuffix);
3317
3318
0
  auto configFromSuffix = [](cm::string_view s) -> cm::string_view {
3319
0
    return s.empty() ? "(none)"_s : s.substr(1);
3320
0
  };
3321
3322
0
  if (!this->GetMappedConfigOld(desiredConfig, loc, imp, suffix)) {
3323
0
    if (newResult) {
3324
      // NEW policy found a configuration, OLD did not.
3325
0
      cm::string_view newConfig = configFromSuffix(newSuffix);
3326
0
      std::string const err = cmStrCat(
3327
0
        cmPolicies::GetPolicyWarning(cmPolicies::CMP0200),
3328
0
        "\nConfiguration selection for imported target \"", this->GetName(),
3329
0
        "\" failed, but would select configuration \"", newConfig,
3330
0
        "\" under the NEW policy.\n");
3331
0
      this->GetMakefile()->IssueDiagnostic(cmDiagnostics::CMD_AUTHOR, err);
3332
0
    }
3333
3334
0
    return false;
3335
0
  }
3336
3337
0
  cm::string_view oldConfig = configFromSuffix(suffix);
3338
0
  if (!newResult) {
3339
    // NEW policy did not find a configuration, OLD did.
3340
0
    std::string const err =
3341
0
      cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0200),
3342
0
               "\nConfiguration selection for imported target \"",
3343
0
               this->GetName(), "\" selected configuration \"", oldConfig,
3344
0
               "\", but would fail under the NEW policy.\n");
3345
0
    this->GetMakefile()->IssueDiagnostic(cmDiagnostics::CMD_AUTHOR, err);
3346
0
  } else if (suffix != newSuffix) {
3347
    // OLD and NEW policies found different configurations.
3348
0
    cm::string_view newConfig = configFromSuffix(newSuffix);
3349
0
    std::string const err =
3350
0
      cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0200),
3351
0
               "\nConfiguration selection for imported target \"",
3352
0
               this->GetName(), "\" selected configuration \"", oldConfig,
3353
0
               "\", but would select configuration \"", newConfig,
3354
0
               "\" under the NEW policy.\n");
3355
0
    this->GetMakefile()->IssueDiagnostic(cmDiagnostics::CMD_AUTHOR, err);
3356
0
  }
3357
3358
0
  return true;
3359
0
}
3360
3361
bool cmTarget::GetMappedConfigOld(std::string const& desired_config,
3362
                                  cmValue& loc, cmValue& imp,
3363
                                  std::string& suffix) const
3364
0
{
3365
0
  std::string config_upper;
3366
0
  if (!desired_config.empty()) {
3367
0
    config_upper = cmSystemTools::UpperCase(desired_config);
3368
0
  }
3369
3370
0
  std::string locPropBase;
3371
0
  if (this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
3372
0
    locPropBase = "IMPORTED_LIBNAME";
3373
0
  } else if (this->GetType() == cmStateEnums::OBJECT_LIBRARY) {
3374
0
    locPropBase = "IMPORTED_OBJECTS";
3375
0
  } else {
3376
0
    locPropBase = "IMPORTED_LOCATION";
3377
0
  }
3378
3379
  // Track the configuration-specific property suffix.
3380
0
  suffix = cmStrCat('_', config_upper);
3381
3382
0
  cmList mappedConfigs;
3383
0
  {
3384
0
    std::string mapProp = cmStrCat("MAP_IMPORTED_CONFIG_", config_upper);
3385
0
    if (cmValue mapValue = this->GetProperty(mapProp)) {
3386
0
      mappedConfigs.assign(*mapValue, cmList::EmptyElements::Yes);
3387
0
    }
3388
0
  }
3389
3390
  // If we needed to find one of the mapped configurations but did not
3391
  // There may be only IMPORTED_IMPLIB for a shared library or an executable
3392
  // with exports.
3393
0
  bool allowImp = (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
3394
0
                   this->IsExecutableWithExports()) ||
3395
0
    (this->IsAIX() && this->IsExecutableWithExports()) ||
3396
0
    (this->GetMakefile()->PlatformSupportsAppleTextStubs() &&
3397
0
     this->IsSharedLibraryWithExports());
3398
3399
  // If a mapping was found, check its configurations.
3400
0
  for (auto mci = mappedConfigs.begin();
3401
0
       !loc && !imp && mci != mappedConfigs.end(); ++mci) {
3402
    // Look for this configuration.
3403
0
    if (mci->empty()) {
3404
      // An empty string in the mapping has a special meaning:
3405
      // look up the config-less properties.
3406
0
      loc = this->GetProperty(locPropBase);
3407
0
      if (allowImp) {
3408
0
        imp = this->GetProperty("IMPORTED_IMPLIB");
3409
0
      }
3410
      // If it was found, set the suffix.
3411
0
      if (loc || imp) {
3412
0
        suffix.clear();
3413
0
      }
3414
0
    } else {
3415
0
      std::string mcUpper = cmSystemTools::UpperCase(*mci);
3416
0
      std::string locProp = cmStrCat(locPropBase, '_', mcUpper);
3417
0
      loc = this->GetProperty(locProp);
3418
0
      if (allowImp) {
3419
0
        std::string impProp = cmStrCat("IMPORTED_IMPLIB_", mcUpper);
3420
0
        imp = this->GetProperty(impProp);
3421
0
      }
3422
3423
      // If it was found, use it for all properties below.
3424
0
      if (loc || imp) {
3425
0
        suffix = cmStrCat('_', mcUpper);
3426
0
      }
3427
0
    }
3428
0
  }
3429
3430
  // If we needed to find one of the mapped configurations but did not
3431
  // then the target location is not found.  The project does not want
3432
  // any other configuration.
3433
0
  if (!mappedConfigs.empty() && !loc && !imp) {
3434
    // Interface libraries are always available because their
3435
    // library name is optional so it is okay to leave loc empty.
3436
0
    return this->GetType() == cmStateEnums::INTERFACE_LIBRARY;
3437
0
  }
3438
3439
  // If we have not yet found it then there are no mapped
3440
  // configurations.  Look for an exact-match.
3441
0
  if (!loc && !imp) {
3442
0
    std::string locProp = cmStrCat(locPropBase, suffix);
3443
0
    loc = this->GetProperty(locProp);
3444
0
    if (allowImp) {
3445
0
      std::string impProp = cmStrCat("IMPORTED_IMPLIB", suffix);
3446
0
      imp = this->GetProperty(impProp);
3447
0
    }
3448
0
  }
3449
3450
  // If we have not yet found it then there are no mapped
3451
  // configurations and no exact match.
3452
0
  if (!loc && !imp) {
3453
    // The suffix computed above is not useful.
3454
0
    suffix.clear();
3455
3456
    // Look for a configuration-less location.  This may be set by
3457
    // manually-written code.
3458
0
    loc = this->GetProperty(locPropBase);
3459
0
    if (allowImp) {
3460
0
      imp = this->GetProperty("IMPORTED_IMPLIB");
3461
0
    }
3462
0
  }
3463
3464
  // If we have not yet found it then the project is willing to try
3465
  // any available configuration.
3466
0
  if (!loc && !imp) {
3467
0
    cmList availableConfigs;
3468
0
    if (cmValue iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS")) {
3469
0
      availableConfigs.assign(*iconfigs);
3470
0
    }
3471
0
    for (auto it = availableConfigs.begin();
3472
0
         !loc && !imp && it != availableConfigs.end(); ++it) {
3473
0
      suffix = cmStrCat('_', cmSystemTools::UpperCase(*it));
3474
0
      std::string locProp = cmStrCat(locPropBase, suffix);
3475
0
      loc = this->GetProperty(locProp);
3476
0
      if (allowImp) {
3477
0
        std::string impProp = cmStrCat("IMPORTED_IMPLIB", suffix);
3478
0
        imp = this->GetProperty(impProp);
3479
0
      }
3480
0
    }
3481
0
  }
3482
  // If we have not yet found it then the target location is not available.
3483
0
  if (!loc && !imp) {
3484
    // Interface libraries are always available because their
3485
    // library name is optional so it is okay to leave loc empty.
3486
0
    return this->GetType() == cmStateEnums::INTERFACE_LIBRARY;
3487
0
  }
3488
3489
0
  return true;
3490
0
}
3491
3492
cmValue cmTarget::GetLocation(std::string const& base,
3493
                              std::string const& suffix) const
3494
0
{
3495
0
  cmValue value = this->GetProperty(cmStrCat(base, suffix));
3496
0
  if (value || suffix.empty()) {
3497
0
    return value;
3498
0
  }
3499
0
  return this->GetProperty(base);
3500
0
}
3501
3502
bool cmTarget::GetLocation(std::string const& config, cmValue& loc,
3503
                           cmValue& imp, std::string& suffix) const
3504
0
{
3505
0
  suffix = (config.empty() ? std::string{} : cmStrCat('_', config));
3506
3507
  // There may be only IMPORTED_IMPLIB for a shared library or an executable
3508
  // with exports.
3509
0
  bool const allowImp = (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
3510
0
                         this->IsExecutableWithExports()) ||
3511
0
    (this->IsAIX() && this->IsExecutableWithExports()) ||
3512
0
    (this->GetMakefile()->PlatformSupportsAppleTextStubs() &&
3513
0
     this->IsSharedLibraryWithExports());
3514
3515
0
  if (allowImp) {
3516
0
    imp = this->GetLocation("IMPORTED_IMPLIB", suffix);
3517
0
  }
3518
3519
0
  switch (this->GetType()) {
3520
0
    case cmStateEnums::INTERFACE_LIBRARY:
3521
0
      loc = this->GetLocation("IMPORTED_LIBNAME", suffix);
3522
0
      break;
3523
0
    case cmStateEnums::OBJECT_LIBRARY:
3524
0
      loc = this->GetLocation("IMPORTED_OBJECTS", suffix);
3525
0
      break;
3526
0
    default:
3527
0
      loc = this->GetLocation("IMPORTED_LOCATION", suffix);
3528
0
      break;
3529
0
  }
3530
3531
0
  return loc || imp || (this->GetType() == cmStateEnums::INTERFACE_LIBRARY);
3532
0
}
3533
3534
bool cmTarget::GetMappedConfigNew(std::string desiredConfig, cmValue& loc,
3535
                                  cmValue& imp, std::string& suffix) const
3536
0
{
3537
0
  desiredConfig = cmSystemTools::UpperCase(desiredConfig);
3538
3539
  // Get configuration mapping, if present.
3540
0
  cmList mappedConfigs;
3541
0
  if (!desiredConfig.empty()) {
3542
0
    std::string mapProp = cmStrCat("MAP_IMPORTED_CONFIG_", desiredConfig);
3543
0
    if (cmValue mapValue = this->GetProperty(mapProp)) {
3544
0
      mappedConfigs.assign(cmSystemTools::UpperCase(*mapValue),
3545
0
                           cmList::EmptyElements::Yes);
3546
0
    }
3547
0
  }
3548
3549
  // Get imported configurations, if specified.
3550
0
  if (cmValue iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS")) {
3551
0
    cmList const availableConfigs{ cmSystemTools::UpperCase(*iconfigs) };
3552
3553
0
    if (!mappedConfigs.empty()) {
3554
0
      for (auto const& c : mappedConfigs) {
3555
0
        if (cm::contains(availableConfigs, c)) {
3556
0
          this->GetLocation(c, loc, imp, suffix);
3557
0
          return true;
3558
0
        }
3559
0
      }
3560
3561
      // If a configuration mapping was specified, but no matching
3562
      // configuration was found, we don't want to try anything else.
3563
0
      return false;
3564
0
    }
3565
3566
    // There is no mapping; try the requested configuration first.
3567
0
    if (cm::contains(availableConfigs, desiredConfig)) {
3568
0
      this->GetLocation(desiredConfig, loc, imp, suffix);
3569
0
      return true;
3570
0
    }
3571
3572
    // If there is no mapping and the requested configuration is not one of
3573
    // the available configurations, just take the first available
3574
    // configuration.
3575
0
    this->GetLocation(availableConfigs[0], loc, imp, suffix);
3576
0
    return true;
3577
0
  }
3578
3579
0
  if (!mappedConfigs.empty()) {
3580
0
    for (auto const& c : mappedConfigs) {
3581
0
      if (this->GetLocation(c, loc, imp, suffix)) {
3582
0
        return true;
3583
0
      }
3584
0
    }
3585
3586
    // If a configuration mapping was specified, but no matching
3587
    // configuration was found, we don't want to try anything else.
3588
0
    return false;
3589
0
  }
3590
3591
  // There is no mapping and no explicit list of configurations; the only
3592
  // configuration left to try is the requested configuration.
3593
0
  if (this->GetLocation(desiredConfig, loc, imp, suffix)) {
3594
0
    return true;
3595
0
  }
3596
3597
0
  return false;
3598
0
}