Coverage Report

Created: 2026-03-12 06:35

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