Coverage Report

Created: 2026-07-14 07:09

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