cmTarget.cxx 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmTarget.h"
  4. #include "cmsys/RegularExpression.hxx"
  5. #include <algorithm>
  6. #include <assert.h>
  7. #include <map>
  8. #include <set>
  9. #include <sstream>
  10. #include <string.h>
  11. #include "cmAlgorithms.h"
  12. #include "cmGeneratorExpression.h"
  13. #include "cmGeneratorTarget.h"
  14. #include "cmGlobalGenerator.h"
  15. #include "cmListFileCache.h"
  16. #include "cmMakefile.h"
  17. #include "cmMessenger.h"
  18. #include "cmOutputConverter.h"
  19. #include "cmProperty.h"
  20. #include "cmSourceFile.h"
  21. #include "cmSourceFileLocation.h"
  22. #include "cmState.h"
  23. #include "cmStateDirectory.h"
  24. #include "cmStateSnapshot.h"
  25. #include "cmSystemTools.h"
  26. #include "cmTargetPropertyComputer.h"
  27. #include "cm_unordered_set.hxx"
  28. #include "cmake.h"
  29. template <>
  30. const char* cmTargetPropertyComputer::ComputeLocationForBuild<cmTarget>(
  31. cmTarget const* tgt)
  32. {
  33. static std::string loc;
  34. if (tgt->IsImported()) {
  35. loc = tgt->ImportedGetFullPath("", cmStateEnums::RuntimeBinaryArtifact);
  36. return loc.c_str();
  37. }
  38. cmGlobalGenerator* gg = tgt->GetGlobalGenerator();
  39. if (!gg->GetConfigureDoneCMP0026()) {
  40. gg->CreateGenerationObjects();
  41. }
  42. cmGeneratorTarget* gt = gg->FindGeneratorTarget(tgt->GetName());
  43. loc = gt->GetLocationForBuild();
  44. return loc.c_str();
  45. }
  46. template <>
  47. const char* cmTargetPropertyComputer::ComputeLocation<cmTarget>(
  48. cmTarget const* tgt, const std::string& config)
  49. {
  50. static std::string loc;
  51. if (tgt->IsImported()) {
  52. loc =
  53. tgt->ImportedGetFullPath(config, cmStateEnums::RuntimeBinaryArtifact);
  54. return loc.c_str();
  55. }
  56. cmGlobalGenerator* gg = tgt->GetGlobalGenerator();
  57. if (!gg->GetConfigureDoneCMP0026()) {
  58. gg->CreateGenerationObjects();
  59. }
  60. cmGeneratorTarget* gt = gg->FindGeneratorTarget(tgt->GetName());
  61. loc = gt->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact);
  62. return loc.c_str();
  63. }
  64. template <>
  65. const char* cmTargetPropertyComputer::GetSources<cmTarget>(
  66. cmTarget const* tgt, cmMessenger* messenger,
  67. cmListFileBacktrace const& context)
  68. {
  69. cmStringRange entries = tgt->GetSourceEntries();
  70. if (entries.empty()) {
  71. return CM_NULLPTR;
  72. }
  73. std::ostringstream ss;
  74. const char* sep = "";
  75. for (std::vector<std::string>::const_iterator i = entries.begin();
  76. i != entries.end(); ++i) {
  77. std::string const& entry = *i;
  78. std::vector<std::string> files;
  79. cmSystemTools::ExpandListArgument(entry, files);
  80. for (std::vector<std::string>::const_iterator li = files.begin();
  81. li != files.end(); ++li) {
  82. if (cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
  83. (*li)[li->size() - 1] == '>') {
  84. std::string objLibName = li->substr(17, li->size() - 18);
  85. if (cmGeneratorExpression::Find(objLibName) != std::string::npos) {
  86. ss << sep;
  87. sep = ";";
  88. ss << *li;
  89. continue;
  90. }
  91. bool addContent = false;
  92. bool noMessage = true;
  93. std::ostringstream e;
  94. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  95. switch (context.GetBottom().GetPolicy(cmPolicies::CMP0051)) {
  96. case cmPolicies::WARN:
  97. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0051) << "\n";
  98. noMessage = false;
  99. case cmPolicies::OLD:
  100. break;
  101. case cmPolicies::REQUIRED_ALWAYS:
  102. case cmPolicies::REQUIRED_IF_USED:
  103. case cmPolicies::NEW:
  104. addContent = true;
  105. }
  106. if (!noMessage) {
  107. e << "Target \"" << tgt->GetName()
  108. << "\" contains "
  109. "$<TARGET_OBJECTS> generator expression in its sources "
  110. "list. "
  111. "This content was not previously part of the SOURCES "
  112. "property "
  113. "when that property was read at configure time. Code "
  114. "reading "
  115. "that property needs to be adapted to ignore the generator "
  116. "expression using the string(GENEX_STRIP) command.";
  117. messenger->IssueMessage(messageType, e.str(), context);
  118. }
  119. if (addContent) {
  120. ss << sep;
  121. sep = ";";
  122. ss << *li;
  123. }
  124. } else if (cmGeneratorExpression::Find(*li) == std::string::npos) {
  125. ss << sep;
  126. sep = ";";
  127. ss << *li;
  128. } else {
  129. cmSourceFile* sf = tgt->GetMakefile()->GetOrCreateSource(*li);
  130. // Construct what is known about this source file location.
  131. cmSourceFileLocation const& location = sf->GetLocation();
  132. std::string sname = location.GetDirectory();
  133. if (!sname.empty()) {
  134. sname += "/";
  135. }
  136. sname += location.GetName();
  137. ss << sep;
  138. sep = ";";
  139. // Append this list entry.
  140. ss << sname;
  141. }
  142. }
  143. }
  144. static std::string srcs;
  145. srcs = ss.str();
  146. return srcs.c_str();
  147. }
  148. class cmTargetInternals
  149. {
  150. public:
  151. std::vector<std::string> IncludeDirectoriesEntries;
  152. std::vector<cmListFileBacktrace> IncludeDirectoriesBacktraces;
  153. std::vector<std::string> CompileOptionsEntries;
  154. std::vector<cmListFileBacktrace> CompileOptionsBacktraces;
  155. std::vector<std::string> CompileFeaturesEntries;
  156. std::vector<cmListFileBacktrace> CompileFeaturesBacktraces;
  157. std::vector<std::string> CompileDefinitionsEntries;
  158. std::vector<cmListFileBacktrace> CompileDefinitionsBacktraces;
  159. std::vector<std::string> SourceEntries;
  160. std::vector<cmListFileBacktrace> SourceBacktraces;
  161. std::vector<std::string> LinkImplementationPropertyEntries;
  162. std::vector<cmListFileBacktrace> LinkImplementationPropertyBacktraces;
  163. };
  164. cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
  165. Visibility vis, cmMakefile* mf)
  166. {
  167. assert(mf);
  168. this->Name = name;
  169. this->TargetTypeValue = type;
  170. this->Makefile = mf;
  171. this->HaveInstallRule = false;
  172. this->DLLPlatform = false;
  173. this->IsAndroid = false;
  174. this->IsImportedTarget =
  175. (vis == VisibilityImported || vis == VisibilityImportedGlobally);
  176. this->ImportedGloballyVisible = vis == VisibilityImportedGlobally;
  177. this->BuildInterfaceIncludesAppended = false;
  178. // only add dependency information for library targets
  179. if (this->TargetTypeValue >= cmStateEnums::STATIC_LIBRARY &&
  180. this->TargetTypeValue <= cmStateEnums::MODULE_LIBRARY) {
  181. this->RecordDependencies = true;
  182. } else {
  183. this->RecordDependencies = false;
  184. }
  185. // Check whether this is a DLL platform.
  186. this->DLLPlatform =
  187. (this->Makefile->IsOn("WIN32") || this->Makefile->IsOn("CYGWIN") ||
  188. this->Makefile->IsOn("MINGW"));
  189. // Check whether we are targeting an Android platform.
  190. this->IsAndroid =
  191. strcmp(this->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME"),
  192. "Android") == 0;
  193. // Setup default property values.
  194. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
  195. this->GetType() != cmStateEnums::UTILITY) {
  196. this->SetPropertyDefault("ANDROID_API", CM_NULLPTR);
  197. this->SetPropertyDefault("ANDROID_API_MIN", CM_NULLPTR);
  198. this->SetPropertyDefault("ANDROID_ARCH", CM_NULLPTR);
  199. this->SetPropertyDefault("ANDROID_STL_TYPE", CM_NULLPTR);
  200. this->SetPropertyDefault("ANDROID_SKIP_ANT_STEP", CM_NULLPTR);
  201. this->SetPropertyDefault("ANDROID_PROCESS_MAX", CM_NULLPTR);
  202. this->SetPropertyDefault("ANDROID_PROGUARD", CM_NULLPTR);
  203. this->SetPropertyDefault("ANDROID_PROGUARD_CONFIG_PATH", CM_NULLPTR);
  204. this->SetPropertyDefault("ANDROID_SECURE_PROPS_PATH", CM_NULLPTR);
  205. this->SetPropertyDefault("ANDROID_NATIVE_LIB_DIRECTORIES", CM_NULLPTR);
  206. this->SetPropertyDefault("ANDROID_NATIVE_LIB_DEPENDENCIES", CM_NULLPTR);
  207. this->SetPropertyDefault("ANDROID_JAVA_SOURCE_DIR", CM_NULLPTR);
  208. this->SetPropertyDefault("ANDROID_JAR_DIRECTORIES", CM_NULLPTR);
  209. this->SetPropertyDefault("ANDROID_JAR_DEPENDENCIES", CM_NULLPTR);
  210. this->SetPropertyDefault("ANDROID_ASSETS_DIRECTORIES", CM_NULLPTR);
  211. this->SetPropertyDefault("ANDROID_ANT_ADDITIONAL_OPTIONS", CM_NULLPTR);
  212. this->SetPropertyDefault("BUILD_RPATH", CM_NULLPTR);
  213. this->SetPropertyDefault("INSTALL_NAME_DIR", CM_NULLPTR);
  214. this->SetPropertyDefault("INSTALL_RPATH", "");
  215. this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
  216. this->SetPropertyDefault("INTERPROCEDURAL_OPTIMIZATION", CM_NULLPTR);
  217. this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
  218. this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
  219. this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", CM_NULLPTR);
  220. this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", CM_NULLPTR);
  221. this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", CM_NULLPTR);
  222. this->SetPropertyDefault("PDB_OUTPUT_DIRECTORY", CM_NULLPTR);
  223. this->SetPropertyDefault("COMPILE_PDB_OUTPUT_DIRECTORY", CM_NULLPTR);
  224. this->SetPropertyDefault("Fortran_FORMAT", CM_NULLPTR);
  225. this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", CM_NULLPTR);
  226. this->SetPropertyDefault("GNUtoMS", CM_NULLPTR);
  227. this->SetPropertyDefault("OSX_ARCHITECTURES", CM_NULLPTR);
  228. this->SetPropertyDefault("IOS_INSTALL_COMBINED", CM_NULLPTR);
  229. this->SetPropertyDefault("AUTOMOC", CM_NULLPTR);
  230. this->SetPropertyDefault("AUTOUIC", CM_NULLPTR);
  231. this->SetPropertyDefault("AUTORCC", CM_NULLPTR);
  232. this->SetPropertyDefault("AUTOMOC_DEPEND_FILTERS", CM_NULLPTR);
  233. this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", CM_NULLPTR);
  234. this->SetPropertyDefault("AUTOUIC_OPTIONS", CM_NULLPTR);
  235. this->SetPropertyDefault("AUTOUIC_SEARCH_PATHS", CM_NULLPTR);
  236. this->SetPropertyDefault("AUTORCC_OPTIONS", CM_NULLPTR);
  237. this->SetPropertyDefault("LINK_DEPENDS_NO_SHARED", CM_NULLPTR);
  238. this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", CM_NULLPTR);
  239. this->SetPropertyDefault("WIN32_EXECUTABLE", CM_NULLPTR);
  240. this->SetPropertyDefault("MACOSX_BUNDLE", CM_NULLPTR);
  241. this->SetPropertyDefault("MACOSX_RPATH", CM_NULLPTR);
  242. this->SetPropertyDefault("BUILD_WITH_INSTALL_NAME_DIR", CM_NULLPTR);
  243. this->SetPropertyDefault("C_CLANG_TIDY", CM_NULLPTR);
  244. this->SetPropertyDefault("C_COMPILER_LAUNCHER", CM_NULLPTR);
  245. this->SetPropertyDefault("C_CPPLINT", CM_NULLPTR);
  246. this->SetPropertyDefault("C_INCLUDE_WHAT_YOU_USE", CM_NULLPTR);
  247. this->SetPropertyDefault("LINK_WHAT_YOU_USE", CM_NULLPTR);
  248. this->SetPropertyDefault("C_STANDARD", CM_NULLPTR);
  249. this->SetPropertyDefault("C_STANDARD_REQUIRED", CM_NULLPTR);
  250. this->SetPropertyDefault("C_EXTENSIONS", CM_NULLPTR);
  251. this->SetPropertyDefault("CXX_CLANG_TIDY", CM_NULLPTR);
  252. this->SetPropertyDefault("CXX_COMPILER_LAUNCHER", CM_NULLPTR);
  253. this->SetPropertyDefault("CXX_CPPLINT", CM_NULLPTR);
  254. this->SetPropertyDefault("CXX_INCLUDE_WHAT_YOU_USE", CM_NULLPTR);
  255. this->SetPropertyDefault("CXX_STANDARD", CM_NULLPTR);
  256. this->SetPropertyDefault("CXX_STANDARD_REQUIRED", CM_NULLPTR);
  257. this->SetPropertyDefault("CXX_EXTENSIONS", CM_NULLPTR);
  258. this->SetPropertyDefault("CUDA_STANDARD", CM_NULLPTR);
  259. this->SetPropertyDefault("CUDA_STANDARD_REQUIRED", CM_NULLPTR);
  260. this->SetPropertyDefault("CUDA_EXTENSIONS", CM_NULLPTR);
  261. this->SetPropertyDefault("LINK_SEARCH_START_STATIC", CM_NULLPTR);
  262. this->SetPropertyDefault("LINK_SEARCH_END_STATIC", CM_NULLPTR);
  263. }
  264. if (this->GetType() != cmStateEnums::UTILITY) {
  265. this->SetPropertyDefault("NO_SYSTEM_FROM_IMPORTED", CM_NULLPTR);
  266. }
  267. // Collect the set of configuration types.
  268. std::vector<std::string> configNames;
  269. mf->GetConfigurations(configNames);
  270. // Setup per-configuration property default values.
  271. if (this->GetType() != cmStateEnums::UTILITY) {
  272. const char* configProps[] = {
  273. /* clang-format needs this comment to break after the opening brace */
  274. "ARCHIVE_OUTPUT_DIRECTORY_", "LIBRARY_OUTPUT_DIRECTORY_",
  275. "RUNTIME_OUTPUT_DIRECTORY_", "PDB_OUTPUT_DIRECTORY_",
  276. "COMPILE_PDB_OUTPUT_DIRECTORY_", "MAP_IMPORTED_CONFIG_",
  277. "INTERPROCEDURAL_OPTIMIZATION_", CM_NULLPTR
  278. };
  279. for (std::vector<std::string>::iterator ci = configNames.begin();
  280. ci != configNames.end(); ++ci) {
  281. std::string configUpper = cmSystemTools::UpperCase(*ci);
  282. for (const char** p = configProps; *p; ++p) {
  283. // Interface libraries have no output locations, so honor only
  284. // the configuration map.
  285. if (this->TargetTypeValue == cmStateEnums::INTERFACE_LIBRARY &&
  286. strcmp(*p, "MAP_IMPORTED_CONFIG_") != 0) {
  287. continue;
  288. }
  289. std::string property = *p;
  290. property += configUpper;
  291. this->SetPropertyDefault(property, CM_NULLPTR);
  292. }
  293. // Initialize per-configuration name postfix property from the
  294. // variable only for non-executable targets. This preserves
  295. // compatibility with previous CMake versions in which executables
  296. // did not support this variable. Projects may still specify the
  297. // property directly.
  298. if (this->TargetTypeValue != cmStateEnums::EXECUTABLE &&
  299. this->TargetTypeValue != cmStateEnums::INTERFACE_LIBRARY) {
  300. std::string property = cmSystemTools::UpperCase(*ci);
  301. property += "_POSTFIX";
  302. this->SetPropertyDefault(property, CM_NULLPTR);
  303. }
  304. }
  305. }
  306. // Save the backtrace of target construction.
  307. this->Backtrace = this->Makefile->GetBacktrace();
  308. if (!this->IsImported()) {
  309. // Initialize the INCLUDE_DIRECTORIES property based on the current value
  310. // of the same directory property:
  311. const cmStringRange parentIncludes =
  312. this->Makefile->GetIncludeDirectoriesEntries();
  313. const cmBacktraceRange parentIncludesBts =
  314. this->Makefile->GetIncludeDirectoriesBacktraces();
  315. this->Internal->IncludeDirectoriesEntries.insert(
  316. this->Internal->IncludeDirectoriesEntries.end(), parentIncludes.begin(),
  317. parentIncludes.end());
  318. this->Internal->IncludeDirectoriesBacktraces.insert(
  319. this->Internal->IncludeDirectoriesBacktraces.end(),
  320. parentIncludesBts.begin(), parentIncludesBts.end());
  321. const std::set<std::string> parentSystemIncludes =
  322. this->Makefile->GetSystemIncludeDirectories();
  323. this->SystemIncludeDirectories.insert(parentSystemIncludes.begin(),
  324. parentSystemIncludes.end());
  325. const cmStringRange parentOptions =
  326. this->Makefile->GetCompileOptionsEntries();
  327. const cmBacktraceRange parentOptionsBts =
  328. this->Makefile->GetCompileOptionsBacktraces();
  329. this->Internal->CompileOptionsEntries.insert(
  330. this->Internal->CompileOptionsEntries.end(), parentOptions.begin(),
  331. parentOptions.end());
  332. this->Internal->CompileOptionsBacktraces.insert(
  333. this->Internal->CompileOptionsBacktraces.end(), parentOptionsBts.begin(),
  334. parentOptionsBts.end());
  335. }
  336. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
  337. this->GetType() != cmStateEnums::UTILITY) {
  338. this->SetPropertyDefault("C_VISIBILITY_PRESET", CM_NULLPTR);
  339. this->SetPropertyDefault("CXX_VISIBILITY_PRESET", CM_NULLPTR);
  340. this->SetPropertyDefault("CUDA_VISIBILITY_PRESET", CM_NULLPTR);
  341. this->SetPropertyDefault("VISIBILITY_INLINES_HIDDEN", CM_NULLPTR);
  342. }
  343. if (this->TargetTypeValue == cmStateEnums::EXECUTABLE) {
  344. this->SetPropertyDefault("ANDROID_GUI", CM_NULLPTR);
  345. this->SetPropertyDefault("CROSSCOMPILING_EMULATOR", CM_NULLPTR);
  346. this->SetPropertyDefault("ENABLE_EXPORTS", CM_NULLPTR);
  347. }
  348. if (this->TargetTypeValue == cmStateEnums::SHARED_LIBRARY ||
  349. this->TargetTypeValue == cmStateEnums::MODULE_LIBRARY) {
  350. this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
  351. }
  352. if (this->TargetTypeValue == cmStateEnums::SHARED_LIBRARY ||
  353. this->TargetTypeValue == cmStateEnums::EXECUTABLE) {
  354. this->SetPropertyDefault("WINDOWS_EXPORT_ALL_SYMBOLS", CM_NULLPTR);
  355. }
  356. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
  357. this->GetType() != cmStateEnums::UTILITY) {
  358. this->SetPropertyDefault("POSITION_INDEPENDENT_CODE", CM_NULLPTR);
  359. }
  360. // Record current policies for later use.
  361. this->Makefile->RecordPolicies(this->PolicyMap);
  362. if (this->TargetTypeValue == cmStateEnums::INTERFACE_LIBRARY) {
  363. // This policy is checked in a few conditions. The properties relevant
  364. // to the policy are always ignored for cmStateEnums::INTERFACE_LIBRARY
  365. // targets,
  366. // so ensure that the conditions don't lead to nonsense.
  367. this->PolicyMap.Set(cmPolicies::CMP0022, cmPolicies::NEW);
  368. }
  369. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
  370. this->GetType() != cmStateEnums::UTILITY) {
  371. this->SetPropertyDefault("JOB_POOL_COMPILE", CM_NULLPTR);
  372. this->SetPropertyDefault("JOB_POOL_LINK", CM_NULLPTR);
  373. }
  374. }
  375. cmGlobalGenerator* cmTarget::GetGlobalGenerator() const
  376. {
  377. return this->GetMakefile()->GetGlobalGenerator();
  378. }
  379. void cmTarget::AddUtility(const std::string& u, cmMakefile* makefile)
  380. {
  381. if (this->Utilities.insert(u).second && makefile) {
  382. this->UtilityBacktraces.insert(
  383. std::make_pair(u, makefile->GetBacktrace()));
  384. }
  385. }
  386. cmListFileBacktrace const* cmTarget::GetUtilityBacktrace(
  387. const std::string& u) const
  388. {
  389. std::map<std::string, cmListFileBacktrace>::const_iterator i =
  390. this->UtilityBacktraces.find(u);
  391. if (i == this->UtilityBacktraces.end()) {
  392. return CM_NULLPTR;
  393. }
  394. return &i->second;
  395. }
  396. cmListFileBacktrace const& cmTarget::GetBacktrace() const
  397. {
  398. return this->Backtrace;
  399. }
  400. bool cmTarget::IsExecutableWithExports() const
  401. {
  402. return (this->GetType() == cmStateEnums::EXECUTABLE &&
  403. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  404. }
  405. bool cmTarget::HasImportLibrary() const
  406. {
  407. return (this->DLLPlatform &&
  408. (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  409. this->IsExecutableWithExports()));
  410. }
  411. bool cmTarget::IsFrameworkOnApple() const
  412. {
  413. return ((this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  414. this->GetType() == cmStateEnums::STATIC_LIBRARY) &&
  415. this->Makefile->IsOn("APPLE") &&
  416. this->GetPropertyAsBool("FRAMEWORK"));
  417. }
  418. bool cmTarget::IsAppBundleOnApple() const
  419. {
  420. return (this->GetType() == cmStateEnums::EXECUTABLE &&
  421. this->Makefile->IsOn("APPLE") &&
  422. this->GetPropertyAsBool("MACOSX_BUNDLE"));
  423. }
  424. void cmTarget::AddTracedSources(std::vector<std::string> const& srcs)
  425. {
  426. if (!srcs.empty()) {
  427. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  428. this->Internal->SourceEntries.push_back(cmJoin(srcs, ";"));
  429. this->Internal->SourceBacktraces.push_back(lfbt);
  430. }
  431. }
  432. void cmTarget::AddSources(std::vector<std::string> const& srcs)
  433. {
  434. std::string srcFiles;
  435. const char* sep = "";
  436. for (std::vector<std::string>::const_iterator i = srcs.begin();
  437. i != srcs.end(); ++i) {
  438. std::string filename = *i;
  439. const char* src = filename.c_str();
  440. if (!(src[0] == '$' && src[1] == '<')) {
  441. if (!filename.empty()) {
  442. filename = this->ProcessSourceItemCMP0049(filename);
  443. if (filename.empty()) {
  444. return;
  445. }
  446. }
  447. this->Makefile->GetOrCreateSource(filename);
  448. }
  449. srcFiles += sep;
  450. srcFiles += filename;
  451. sep = ";";
  452. }
  453. if (!srcFiles.empty()) {
  454. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  455. this->Internal->SourceEntries.push_back(srcFiles);
  456. this->Internal->SourceBacktraces.push_back(lfbt);
  457. }
  458. }
  459. std::string cmTarget::ProcessSourceItemCMP0049(const std::string& s)
  460. {
  461. std::string src = s;
  462. // For backwards compatibility replace varibles in source names.
  463. // This should eventually be removed.
  464. this->Makefile->ExpandVariablesInString(src);
  465. if (src != s) {
  466. std::ostringstream e;
  467. bool noMessage = false;
  468. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  469. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0049)) {
  470. case cmPolicies::WARN:
  471. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0049) << "\n";
  472. break;
  473. case cmPolicies::OLD:
  474. noMessage = true;
  475. break;
  476. case cmPolicies::REQUIRED_ALWAYS:
  477. case cmPolicies::REQUIRED_IF_USED:
  478. case cmPolicies::NEW:
  479. messageType = cmake::FATAL_ERROR;
  480. }
  481. if (!noMessage) {
  482. e << "Legacy variable expansion in source file \"" << s
  483. << "\" expanded to \"" << src << "\" in target \"" << this->GetName()
  484. << "\". This behavior will be removed in a "
  485. "future version of CMake.";
  486. this->Makefile->IssueMessage(messageType, e.str());
  487. if (messageType == cmake::FATAL_ERROR) {
  488. return "";
  489. }
  490. }
  491. }
  492. return src;
  493. }
  494. cmSourceFile* cmTarget::AddSourceCMP0049(const std::string& s)
  495. {
  496. std::string src = this->ProcessSourceItemCMP0049(s);
  497. if (!s.empty() && src.empty()) {
  498. return CM_NULLPTR;
  499. }
  500. return this->AddSource(src);
  501. }
  502. struct CreateLocation
  503. {
  504. cmMakefile const* Makefile;
  505. CreateLocation(cmMakefile const* mf)
  506. : Makefile(mf)
  507. {
  508. }
  509. cmSourceFileLocation operator()(const std::string& filename)
  510. {
  511. return cmSourceFileLocation(this->Makefile, filename);
  512. }
  513. };
  514. struct LocationMatcher
  515. {
  516. const cmSourceFileLocation& Needle;
  517. LocationMatcher(const cmSourceFileLocation& needle)
  518. : Needle(needle)
  519. {
  520. }
  521. bool operator()(cmSourceFileLocation& loc)
  522. {
  523. return loc.Matches(this->Needle);
  524. }
  525. };
  526. struct TargetPropertyEntryFinder
  527. {
  528. private:
  529. const cmSourceFileLocation& Needle;
  530. public:
  531. TargetPropertyEntryFinder(const cmSourceFileLocation& needle)
  532. : Needle(needle)
  533. {
  534. }
  535. bool operator()(std::string const& entry)
  536. {
  537. std::vector<std::string> files;
  538. cmSystemTools::ExpandListArgument(entry, files);
  539. std::vector<cmSourceFileLocation> locations(files.size());
  540. std::transform(files.begin(), files.end(), locations.begin(),
  541. CreateLocation(this->Needle.GetMakefile()));
  542. return std::find_if(locations.begin(), locations.end(),
  543. LocationMatcher(this->Needle)) != locations.end();
  544. }
  545. };
  546. cmSourceFile* cmTarget::AddSource(const std::string& src)
  547. {
  548. cmSourceFileLocation sfl(this->Makefile, src);
  549. if (std::find_if(this->Internal->SourceEntries.begin(),
  550. this->Internal->SourceEntries.end(),
  551. TargetPropertyEntryFinder(sfl)) ==
  552. this->Internal->SourceEntries.end()) {
  553. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  554. this->Internal->SourceEntries.push_back(src);
  555. this->Internal->SourceBacktraces.push_back(lfbt);
  556. }
  557. if (cmGeneratorExpression::Find(src) != std::string::npos) {
  558. return CM_NULLPTR;
  559. }
  560. return this->Makefile->GetOrCreateSource(src);
  561. }
  562. void cmTarget::AddLinkDirectory(const std::string& d)
  563. {
  564. // Make sure we don't add unnecessary search directories.
  565. if (this->LinkDirectoriesEmmitted.insert(d).second) {
  566. this->LinkDirectories.push_back(d);
  567. }
  568. }
  569. const std::vector<std::string>& cmTarget::GetLinkDirectories() const
  570. {
  571. return this->LinkDirectories;
  572. }
  573. void cmTarget::ClearDependencyInformation(cmMakefile& mf,
  574. const std::string& target)
  575. {
  576. // Clear the dependencies. The cache variable must exist iff we are
  577. // recording dependency information for this target.
  578. std::string depname = target;
  579. depname += "_LIB_DEPENDS";
  580. if (this->RecordDependencies) {
  581. mf.AddCacheDefinition(depname, "", "Dependencies for target",
  582. cmStateEnums::STATIC);
  583. } else {
  584. if (mf.GetDefinition(depname)) {
  585. std::string message = "Target ";
  586. message += target;
  587. message += " has dependency information when it shouldn't.\n";
  588. message += "Your cache is probably stale. Please remove the entry\n ";
  589. message += depname;
  590. message += "\nfrom the cache.";
  591. cmSystemTools::Error(message.c_str());
  592. }
  593. }
  594. }
  595. std::string cmTarget::GetDebugGeneratorExpressions(
  596. const std::string& value, cmTargetLinkLibraryType llt) const
  597. {
  598. if (llt == GENERAL_LibraryType) {
  599. return value;
  600. }
  601. // Get the list of configurations considered to be DEBUG.
  602. std::vector<std::string> debugConfigs =
  603. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  604. std::string configString = "$<CONFIG:" + debugConfigs[0] + ">";
  605. if (debugConfigs.size() > 1) {
  606. for (std::vector<std::string>::const_iterator li =
  607. debugConfigs.begin() + 1;
  608. li != debugConfigs.end(); ++li) {
  609. configString += ",$<CONFIG:" + *li + ">";
  610. }
  611. configString = "$<OR:" + configString + ">";
  612. }
  613. if (llt == OPTIMIZED_LibraryType) {
  614. configString = "$<NOT:" + configString + ">";
  615. }
  616. return "$<" + configString + ":" + value + ">";
  617. }
  618. static std::string targetNameGenex(const std::string& lib)
  619. {
  620. return "$<TARGET_NAME:" + lib + ">";
  621. }
  622. bool cmTarget::PushTLLCommandTrace(TLLSignature signature,
  623. cmListFileContext const& lfc)
  624. {
  625. bool ret = true;
  626. if (!this->TLLCommands.empty()) {
  627. if (this->TLLCommands.back().first != signature) {
  628. ret = false;
  629. }
  630. }
  631. if (this->TLLCommands.empty() || this->TLLCommands.back().second != lfc) {
  632. this->TLLCommands.push_back(std::make_pair(signature, lfc));
  633. }
  634. return ret;
  635. }
  636. void cmTarget::GetTllSignatureTraces(std::ostream& s, TLLSignature sig) const
  637. {
  638. const char* sigString =
  639. (sig == cmTarget::KeywordTLLSignature ? "keyword" : "plain");
  640. s << "The uses of the " << sigString << " signature are here:\n";
  641. typedef std::vector<std::pair<TLLSignature, cmListFileContext> > Container;
  642. cmOutputConverter converter(this->GetMakefile()->GetStateSnapshot());
  643. for (Container::const_iterator it = this->TLLCommands.begin();
  644. it != this->TLLCommands.end(); ++it) {
  645. if (it->first == sig) {
  646. cmListFileContext lfc = it->second;
  647. lfc.FilePath = converter.ConvertToRelativePath(
  648. this->Makefile->GetState()->GetSourceDirectory(), lfc.FilePath);
  649. s << " * " << lfc << std::endl;
  650. }
  651. }
  652. }
  653. void cmTarget::AddLinkLibrary(cmMakefile& mf, const std::string& lib,
  654. cmTargetLinkLibraryType llt)
  655. {
  656. cmTarget* tgt = this->Makefile->FindTargetToUse(lib);
  657. {
  658. const bool isNonImportedTarget = tgt && !tgt->IsImported();
  659. const std::string libName =
  660. (isNonImportedTarget && llt != GENERAL_LibraryType)
  661. ? targetNameGenex(lib)
  662. : lib;
  663. this->AppendProperty(
  664. "LINK_LIBRARIES",
  665. this->GetDebugGeneratorExpressions(libName, llt).c_str());
  666. }
  667. if (cmGeneratorExpression::Find(lib) != std::string::npos ||
  668. (tgt && tgt->GetType() == cmStateEnums::INTERFACE_LIBRARY) ||
  669. (this->Name == lib)) {
  670. return;
  671. }
  672. cmTarget::LibraryID tmp;
  673. tmp.first = lib;
  674. tmp.second = llt;
  675. this->OriginalLinkLibraries.push_back(tmp);
  676. // Add the explicit dependency information for this target. This is
  677. // simply a set of libraries separated by ";". There should always
  678. // be a trailing ";". These library names are not canonical, in that
  679. // they may be "-framework x", "-ly", "/path/libz.a", etc.
  680. // We shouldn't remove duplicates here because external libraries
  681. // may be purposefully duplicated to handle recursive dependencies,
  682. // and we removing one instance will break the link line. Duplicates
  683. // will be appropriately eliminated at emit time.
  684. if (this->RecordDependencies) {
  685. std::string targetEntry = this->Name;
  686. targetEntry += "_LIB_DEPENDS";
  687. std::string dependencies;
  688. const char* old_val = mf.GetDefinition(targetEntry);
  689. if (old_val) {
  690. dependencies += old_val;
  691. }
  692. switch (llt) {
  693. case GENERAL_LibraryType:
  694. dependencies += "general";
  695. break;
  696. case DEBUG_LibraryType:
  697. dependencies += "debug";
  698. break;
  699. case OPTIMIZED_LibraryType:
  700. dependencies += "optimized";
  701. break;
  702. }
  703. dependencies += ";";
  704. dependencies += lib;
  705. dependencies += ";";
  706. mf.AddCacheDefinition(targetEntry, dependencies.c_str(),
  707. "Dependencies for the target", cmStateEnums::STATIC);
  708. }
  709. }
  710. void cmTarget::AddSystemIncludeDirectories(const std::set<std::string>& incs)
  711. {
  712. this->SystemIncludeDirectories.insert(incs.begin(), incs.end());
  713. }
  714. cmStringRange cmTarget::GetIncludeDirectoriesEntries() const
  715. {
  716. return cmMakeRange(this->Internal->IncludeDirectoriesEntries);
  717. }
  718. cmBacktraceRange cmTarget::GetIncludeDirectoriesBacktraces() const
  719. {
  720. return cmMakeRange(this->Internal->IncludeDirectoriesBacktraces);
  721. }
  722. cmStringRange cmTarget::GetCompileOptionsEntries() const
  723. {
  724. return cmMakeRange(this->Internal->CompileOptionsEntries);
  725. }
  726. cmBacktraceRange cmTarget::GetCompileOptionsBacktraces() const
  727. {
  728. return cmMakeRange(this->Internal->CompileOptionsBacktraces);
  729. }
  730. cmStringRange cmTarget::GetCompileFeaturesEntries() const
  731. {
  732. return cmMakeRange(this->Internal->CompileFeaturesEntries);
  733. }
  734. cmBacktraceRange cmTarget::GetCompileFeaturesBacktraces() const
  735. {
  736. return cmMakeRange(this->Internal->CompileFeaturesBacktraces);
  737. }
  738. cmStringRange cmTarget::GetCompileDefinitionsEntries() const
  739. {
  740. return cmMakeRange(this->Internal->CompileDefinitionsEntries);
  741. }
  742. cmBacktraceRange cmTarget::GetCompileDefinitionsBacktraces() const
  743. {
  744. return cmMakeRange(this->Internal->CompileDefinitionsBacktraces);
  745. }
  746. cmStringRange cmTarget::GetSourceEntries() const
  747. {
  748. return cmMakeRange(this->Internal->SourceEntries);
  749. }
  750. cmBacktraceRange cmTarget::GetSourceBacktraces() const
  751. {
  752. return cmMakeRange(this->Internal->SourceBacktraces);
  753. }
  754. cmStringRange cmTarget::GetLinkImplementationEntries() const
  755. {
  756. return cmMakeRange(this->Internal->LinkImplementationPropertyEntries);
  757. }
  758. cmBacktraceRange cmTarget::GetLinkImplementationBacktraces() const
  759. {
  760. return cmMakeRange(this->Internal->LinkImplementationPropertyBacktraces);
  761. }
  762. void cmTarget::SetProperty(const std::string& prop, const char* value)
  763. {
  764. if (!cmTargetPropertyComputer::PassesWhitelist(
  765. this->GetType(), prop, this->Makefile->GetMessenger(),
  766. this->Makefile->GetBacktrace())) {
  767. return;
  768. }
  769. if (prop == "MANUALLY_ADDED_DEPENDENCIES") {
  770. std::ostringstream e;
  771. e << "MANUALLY_ADDED_DEPENDENCIES property is read-only\n";
  772. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  773. return;
  774. }
  775. if (prop == "NAME") {
  776. std::ostringstream e;
  777. e << "NAME property is read-only\n";
  778. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  779. return;
  780. }
  781. if (prop == "TYPE") {
  782. std::ostringstream e;
  783. e << "TYPE property is read-only\n";
  784. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  785. return;
  786. }
  787. if (prop == "EXPORT_NAME" && this->IsImported()) {
  788. std::ostringstream e;
  789. e << "EXPORT_NAME property can't be set on imported targets (\""
  790. << this->Name << "\")\n";
  791. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  792. return;
  793. }
  794. if (prop == "SOURCES" && this->IsImported()) {
  795. std::ostringstream e;
  796. e << "SOURCES property can't be set on imported targets (\"" << this->Name
  797. << "\")\n";
  798. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  799. return;
  800. }
  801. if (prop == "INCLUDE_DIRECTORIES") {
  802. this->Internal->IncludeDirectoriesEntries.clear();
  803. this->Internal->IncludeDirectoriesBacktraces.clear();
  804. if (value) {
  805. this->Internal->IncludeDirectoriesEntries.push_back(value);
  806. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  807. this->Internal->IncludeDirectoriesBacktraces.push_back(lfbt);
  808. }
  809. } else if (prop == "COMPILE_OPTIONS") {
  810. this->Internal->CompileOptionsEntries.clear();
  811. this->Internal->CompileOptionsBacktraces.clear();
  812. if (value) {
  813. this->Internal->CompileOptionsEntries.push_back(value);
  814. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  815. this->Internal->CompileOptionsBacktraces.push_back(lfbt);
  816. }
  817. } else if (prop == "COMPILE_FEATURES") {
  818. this->Internal->CompileFeaturesEntries.clear();
  819. this->Internal->CompileFeaturesBacktraces.clear();
  820. if (value) {
  821. this->Internal->CompileFeaturesEntries.push_back(value);
  822. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  823. this->Internal->CompileFeaturesBacktraces.push_back(lfbt);
  824. }
  825. } else if (prop == "COMPILE_DEFINITIONS") {
  826. this->Internal->CompileDefinitionsEntries.clear();
  827. this->Internal->CompileDefinitionsBacktraces.clear();
  828. if (value) {
  829. this->Internal->CompileDefinitionsEntries.push_back(value);
  830. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  831. this->Internal->CompileDefinitionsBacktraces.push_back(lfbt);
  832. }
  833. } else if (prop == "LINK_LIBRARIES") {
  834. this->Internal->LinkImplementationPropertyEntries.clear();
  835. this->Internal->LinkImplementationPropertyBacktraces.clear();
  836. if (value) {
  837. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  838. this->Internal->LinkImplementationPropertyEntries.push_back(value);
  839. this->Internal->LinkImplementationPropertyBacktraces.push_back(lfbt);
  840. }
  841. } else if (prop == "SOURCES") {
  842. this->Internal->SourceEntries.clear();
  843. this->Internal->SourceBacktraces.clear();
  844. if (value) {
  845. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  846. this->Internal->SourceEntries.push_back(value);
  847. this->Internal->SourceBacktraces.push_back(lfbt);
  848. }
  849. } else if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME") &&
  850. !this->CheckImportedLibName(prop, value ? value : "")) {
  851. /* error was reported by check method */
  852. } else if (prop == "CUDA_PTX_COMPILATION" &&
  853. this->GetType() != cmStateEnums::OBJECT_LIBRARY) {
  854. std::ostringstream e;
  855. e << "CUDA_PTX_COMPILATION property can only be applied to OBJECT "
  856. "targets (\""
  857. << this->Name << "\")\n";
  858. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  859. return;
  860. } else {
  861. this->Properties.SetProperty(prop, value);
  862. }
  863. }
  864. void cmTarget::AppendProperty(const std::string& prop, const char* value,
  865. bool asString)
  866. {
  867. if (!cmTargetPropertyComputer::PassesWhitelist(
  868. this->GetType(), prop, this->Makefile->GetMessenger(),
  869. this->Makefile->GetBacktrace())) {
  870. return;
  871. }
  872. if (prop == "NAME") {
  873. std::ostringstream e;
  874. e << "NAME property is read-only\n";
  875. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  876. return;
  877. }
  878. if (prop == "EXPORT_NAME" && this->IsImported()) {
  879. std::ostringstream e;
  880. e << "EXPORT_NAME property can't be set on imported targets (\""
  881. << this->Name << "\")\n";
  882. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  883. return;
  884. }
  885. if (prop == "SOURCES" && this->IsImported()) {
  886. std::ostringstream e;
  887. e << "SOURCES property can't be set on imported targets (\"" << this->Name
  888. << "\")\n";
  889. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  890. return;
  891. }
  892. if (prop == "INCLUDE_DIRECTORIES") {
  893. if (value && *value) {
  894. this->Internal->IncludeDirectoriesEntries.push_back(value);
  895. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  896. this->Internal->IncludeDirectoriesBacktraces.push_back(lfbt);
  897. }
  898. } else if (prop == "COMPILE_OPTIONS") {
  899. if (value && *value) {
  900. this->Internal->CompileOptionsEntries.push_back(value);
  901. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  902. this->Internal->CompileOptionsBacktraces.push_back(lfbt);
  903. }
  904. } else if (prop == "COMPILE_FEATURES") {
  905. if (value && *value) {
  906. this->Internal->CompileFeaturesEntries.push_back(value);
  907. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  908. this->Internal->CompileFeaturesBacktraces.push_back(lfbt);
  909. }
  910. } else if (prop == "COMPILE_DEFINITIONS") {
  911. if (value && *value) {
  912. this->Internal->CompileDefinitionsEntries.push_back(value);
  913. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  914. this->Internal->CompileDefinitionsBacktraces.push_back(lfbt);
  915. }
  916. } else if (prop == "LINK_LIBRARIES") {
  917. if (value && *value) {
  918. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  919. this->Internal->LinkImplementationPropertyEntries.push_back(value);
  920. this->Internal->LinkImplementationPropertyBacktraces.push_back(lfbt);
  921. }
  922. } else if (prop == "SOURCES") {
  923. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  924. this->Internal->SourceEntries.push_back(value);
  925. this->Internal->SourceBacktraces.push_back(lfbt);
  926. } else if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME")) {
  927. this->Makefile->IssueMessage(cmake::FATAL_ERROR,
  928. prop + " property may not be APPENDed.");
  929. } else {
  930. this->Properties.AppendProperty(prop, value, asString);
  931. }
  932. }
  933. void cmTarget::AppendBuildInterfaceIncludes()
  934. {
  935. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  936. this->GetType() != cmStateEnums::STATIC_LIBRARY &&
  937. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  938. this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
  939. !this->IsExecutableWithExports()) {
  940. return;
  941. }
  942. if (this->BuildInterfaceIncludesAppended) {
  943. return;
  944. }
  945. this->BuildInterfaceIncludesAppended = true;
  946. if (this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE")) {
  947. const char* binDir = this->Makefile->GetCurrentBinaryDirectory();
  948. const char* srcDir = this->Makefile->GetCurrentSourceDirectory();
  949. const std::string dirs = std::string(binDir ? binDir : "") +
  950. std::string(binDir ? ";" : "") + std::string(srcDir ? srcDir : "");
  951. if (!dirs.empty()) {
  952. this->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
  953. ("$<BUILD_INTERFACE:" + dirs + ">").c_str());
  954. }
  955. }
  956. }
  957. void cmTarget::InsertInclude(std::string const& entry,
  958. cmListFileBacktrace const& bt, bool before)
  959. {
  960. std::vector<std::string>::iterator position = before
  961. ? this->Internal->IncludeDirectoriesEntries.begin()
  962. : this->Internal->IncludeDirectoriesEntries.end();
  963. std::vector<cmListFileBacktrace>::iterator btPosition = before
  964. ? this->Internal->IncludeDirectoriesBacktraces.begin()
  965. : this->Internal->IncludeDirectoriesBacktraces.end();
  966. this->Internal->IncludeDirectoriesEntries.insert(position, entry);
  967. this->Internal->IncludeDirectoriesBacktraces.insert(btPosition, bt);
  968. }
  969. void cmTarget::InsertCompileOption(std::string const& entry,
  970. cmListFileBacktrace const& bt, bool before)
  971. {
  972. std::vector<std::string>::iterator position = before
  973. ? this->Internal->CompileOptionsEntries.begin()
  974. : this->Internal->CompileOptionsEntries.end();
  975. std::vector<cmListFileBacktrace>::iterator btPosition = before
  976. ? this->Internal->CompileOptionsBacktraces.begin()
  977. : this->Internal->CompileOptionsBacktraces.end();
  978. this->Internal->CompileOptionsEntries.insert(position, entry);
  979. this->Internal->CompileOptionsBacktraces.insert(btPosition, bt);
  980. }
  981. void cmTarget::InsertCompileDefinition(std::string const& entry,
  982. cmListFileBacktrace const& bt)
  983. {
  984. this->Internal->CompileDefinitionsEntries.push_back(entry);
  985. this->Internal->CompileDefinitionsBacktraces.push_back(bt);
  986. }
  987. static void cmTargetCheckLINK_INTERFACE_LIBRARIES(const std::string& prop,
  988. const char* value,
  989. cmMakefile* context,
  990. bool imported)
  991. {
  992. // Look for link-type keywords in the value.
  993. static cmsys::RegularExpression keys("(^|;)(debug|optimized|general)(;|$)");
  994. if (!keys.find(value)) {
  995. return;
  996. }
  997. // Support imported and non-imported versions of the property.
  998. const char* base = (imported ? "IMPORTED_LINK_INTERFACE_LIBRARIES"
  999. : "LINK_INTERFACE_LIBRARIES");
  1000. // Report an error.
  1001. std::ostringstream e;
  1002. e << "Property " << prop << " may not contain link-type keyword \""
  1003. << keys.match(2) << "\". "
  1004. << "The " << base << " property has a per-configuration "
  1005. << "version called " << base << "_<CONFIG> which may be "
  1006. << "used to specify per-configuration rules.";
  1007. if (!imported) {
  1008. e << " "
  1009. << "Alternatively, an IMPORTED library may be created, configured "
  1010. << "with a per-configuration location, and then named in the "
  1011. << "property value. "
  1012. << "See the add_library command's IMPORTED mode for details."
  1013. << "\n"
  1014. << "If you have a list of libraries that already contains the "
  1015. << "keyword, use the target_link_libraries command with its "
  1016. << "LINK_INTERFACE_LIBRARIES mode to set the property. "
  1017. << "The command automatically recognizes link-type keywords and sets "
  1018. << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
  1019. << "properties accordingly.";
  1020. }
  1021. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  1022. }
  1023. static void cmTargetCheckINTERFACE_LINK_LIBRARIES(const char* value,
  1024. cmMakefile* context)
  1025. {
  1026. // Look for link-type keywords in the value.
  1027. static cmsys::RegularExpression keys("(^|;)(debug|optimized|general)(;|$)");
  1028. if (!keys.find(value)) {
  1029. return;
  1030. }
  1031. // Report an error.
  1032. std::ostringstream e;
  1033. e << "Property INTERFACE_LINK_LIBRARIES may not contain link-type "
  1034. "keyword \""
  1035. << keys.match(2)
  1036. << "\". The INTERFACE_LINK_LIBRARIES "
  1037. "property may contain configuration-sensitive generator-expressions "
  1038. "which may be used to specify per-configuration rules.";
  1039. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  1040. }
  1041. void cmTarget::CheckProperty(const std::string& prop,
  1042. cmMakefile* context) const
  1043. {
  1044. // Certain properties need checking.
  1045. if (cmHasLiteralPrefix(prop, "LINK_INTERFACE_LIBRARIES")) {
  1046. if (const char* value = this->GetProperty(prop)) {
  1047. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, false);
  1048. }
  1049. }
  1050. if (cmHasLiteralPrefix(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES")) {
  1051. if (const char* value = this->GetProperty(prop)) {
  1052. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, true);
  1053. }
  1054. }
  1055. if (cmHasLiteralPrefix(prop, "INTERFACE_LINK_LIBRARIES")) {
  1056. if (const char* value = this->GetProperty(prop)) {
  1057. cmTargetCheckINTERFACE_LINK_LIBRARIES(value, context);
  1058. }
  1059. }
  1060. }
  1061. const char* cmTarget::GetComputedProperty(
  1062. const std::string& prop, cmMessenger* messenger,
  1063. cmListFileBacktrace const& context) const
  1064. {
  1065. return cmTargetPropertyComputer::GetProperty(this, prop, messenger, context);
  1066. }
  1067. const char* cmTarget::GetProperty(const std::string& prop) const
  1068. {
  1069. static CM_UNORDERED_SET<std::string> specialProps;
  1070. #define MAKE_STATIC_PROP(PROP) static const std::string prop##PROP = #PROP
  1071. MAKE_STATIC_PROP(LINK_LIBRARIES);
  1072. MAKE_STATIC_PROP(TYPE);
  1073. MAKE_STATIC_PROP(INCLUDE_DIRECTORIES);
  1074. MAKE_STATIC_PROP(COMPILE_FEATURES);
  1075. MAKE_STATIC_PROP(COMPILE_OPTIONS);
  1076. MAKE_STATIC_PROP(COMPILE_DEFINITIONS);
  1077. MAKE_STATIC_PROP(IMPORTED);
  1078. MAKE_STATIC_PROP(MANUALLY_ADDED_DEPENDENCIES);
  1079. MAKE_STATIC_PROP(NAME);
  1080. MAKE_STATIC_PROP(BINARY_DIR);
  1081. MAKE_STATIC_PROP(SOURCE_DIR);
  1082. MAKE_STATIC_PROP(SOURCES);
  1083. #undef MAKE_STATIC_PROP
  1084. if (specialProps.empty()) {
  1085. specialProps.insert(propLINK_LIBRARIES);
  1086. specialProps.insert(propTYPE);
  1087. specialProps.insert(propINCLUDE_DIRECTORIES);
  1088. specialProps.insert(propCOMPILE_FEATURES);
  1089. specialProps.insert(propCOMPILE_OPTIONS);
  1090. specialProps.insert(propCOMPILE_DEFINITIONS);
  1091. specialProps.insert(propIMPORTED);
  1092. specialProps.insert(propMANUALLY_ADDED_DEPENDENCIES);
  1093. specialProps.insert(propNAME);
  1094. specialProps.insert(propBINARY_DIR);
  1095. specialProps.insert(propSOURCE_DIR);
  1096. specialProps.insert(propSOURCES);
  1097. }
  1098. if (specialProps.count(prop)) {
  1099. if (prop == propLINK_LIBRARIES) {
  1100. if (this->Internal->LinkImplementationPropertyEntries.empty()) {
  1101. return CM_NULLPTR;
  1102. }
  1103. static std::string output;
  1104. output = cmJoin(this->Internal->LinkImplementationPropertyEntries, ";");
  1105. return output.c_str();
  1106. }
  1107. // the type property returns what type the target is
  1108. if (prop == propTYPE) {
  1109. return cmState::GetTargetTypeName(this->GetType());
  1110. }
  1111. if (prop == propINCLUDE_DIRECTORIES) {
  1112. if (this->Internal->IncludeDirectoriesEntries.empty()) {
  1113. return CM_NULLPTR;
  1114. }
  1115. static std::string output;
  1116. output = cmJoin(this->Internal->IncludeDirectoriesEntries, ";");
  1117. return output.c_str();
  1118. }
  1119. if (prop == propCOMPILE_FEATURES) {
  1120. if (this->Internal->CompileFeaturesEntries.empty()) {
  1121. return CM_NULLPTR;
  1122. }
  1123. static std::string output;
  1124. output = cmJoin(this->Internal->CompileFeaturesEntries, ";");
  1125. return output.c_str();
  1126. }
  1127. if (prop == propCOMPILE_OPTIONS) {
  1128. if (this->Internal->CompileOptionsEntries.empty()) {
  1129. return CM_NULLPTR;
  1130. }
  1131. static std::string output;
  1132. output = cmJoin(this->Internal->CompileOptionsEntries, ";");
  1133. return output.c_str();
  1134. }
  1135. if (prop == propCOMPILE_DEFINITIONS) {
  1136. if (this->Internal->CompileDefinitionsEntries.empty()) {
  1137. return CM_NULLPTR;
  1138. }
  1139. static std::string output;
  1140. output = cmJoin(this->Internal->CompileDefinitionsEntries, ";");
  1141. return output.c_str();
  1142. }
  1143. if (prop == propMANUALLY_ADDED_DEPENDENCIES) {
  1144. if (this->Utilities.empty()) {
  1145. return CM_NULLPTR;
  1146. }
  1147. static std::string output;
  1148. output = cmJoin(this->Utilities, ";");
  1149. return output.c_str();
  1150. }
  1151. if (prop == propIMPORTED) {
  1152. return this->IsImported() ? "TRUE" : "FALSE";
  1153. }
  1154. if (prop == propNAME) {
  1155. return this->GetName().c_str();
  1156. }
  1157. if (prop == propBINARY_DIR) {
  1158. return this->GetMakefile()
  1159. ->GetStateSnapshot()
  1160. .GetDirectory()
  1161. .GetCurrentBinary();
  1162. }
  1163. if (prop == propSOURCE_DIR) {
  1164. return this->GetMakefile()
  1165. ->GetStateSnapshot()
  1166. .GetDirectory()
  1167. .GetCurrentSource();
  1168. }
  1169. }
  1170. const char* retVal = this->Properties.GetPropertyValue(prop);
  1171. if (!retVal) {
  1172. const bool chain = this->GetMakefile()->GetState()->IsPropertyChained(
  1173. prop, cmProperty::TARGET);
  1174. if (chain) {
  1175. return this->Makefile->GetStateSnapshot().GetDirectory().GetProperty(
  1176. prop, chain);
  1177. }
  1178. }
  1179. return retVal;
  1180. }
  1181. bool cmTarget::GetPropertyAsBool(const std::string& prop) const
  1182. {
  1183. return cmSystemTools::IsOn(this->GetProperty(prop));
  1184. }
  1185. const char* cmTarget::GetSuffixVariableInternal(
  1186. cmStateEnums::ArtifactType artifact) const
  1187. {
  1188. switch (this->GetType()) {
  1189. case cmStateEnums::STATIC_LIBRARY:
  1190. return "CMAKE_STATIC_LIBRARY_SUFFIX";
  1191. case cmStateEnums::SHARED_LIBRARY:
  1192. switch (artifact) {
  1193. case cmStateEnums::RuntimeBinaryArtifact:
  1194. return "CMAKE_SHARED_LIBRARY_SUFFIX";
  1195. case cmStateEnums::ImportLibraryArtifact:
  1196. return "CMAKE_IMPORT_LIBRARY_SUFFIX";
  1197. }
  1198. break;
  1199. case cmStateEnums::MODULE_LIBRARY:
  1200. switch (artifact) {
  1201. case cmStateEnums::RuntimeBinaryArtifact:
  1202. return "CMAKE_SHARED_MODULE_SUFFIX";
  1203. case cmStateEnums::ImportLibraryArtifact:
  1204. return "CMAKE_IMPORT_LIBRARY_SUFFIX";
  1205. }
  1206. break;
  1207. case cmStateEnums::EXECUTABLE:
  1208. switch (artifact) {
  1209. case cmStateEnums::RuntimeBinaryArtifact:
  1210. // Android GUI application packages store the native
  1211. // binary as a shared library.
  1212. return (this->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI")
  1213. ? "CMAKE_SHARED_LIBRARY_SUFFIX"
  1214. : "CMAKE_EXECUTABLE_SUFFIX");
  1215. case cmStateEnums::ImportLibraryArtifact:
  1216. return "CMAKE_IMPORT_LIBRARY_SUFFIX";
  1217. }
  1218. break;
  1219. default:
  1220. break;
  1221. }
  1222. return "";
  1223. }
  1224. const char* cmTarget::GetPrefixVariableInternal(
  1225. cmStateEnums::ArtifactType artifact) const
  1226. {
  1227. switch (this->GetType()) {
  1228. case cmStateEnums::STATIC_LIBRARY:
  1229. return "CMAKE_STATIC_LIBRARY_PREFIX";
  1230. case cmStateEnums::SHARED_LIBRARY:
  1231. switch (artifact) {
  1232. case cmStateEnums::RuntimeBinaryArtifact:
  1233. return "CMAKE_SHARED_LIBRARY_PREFIX";
  1234. case cmStateEnums::ImportLibraryArtifact:
  1235. return "CMAKE_IMPORT_LIBRARY_PREFIX";
  1236. }
  1237. break;
  1238. case cmStateEnums::MODULE_LIBRARY:
  1239. switch (artifact) {
  1240. case cmStateEnums::RuntimeBinaryArtifact:
  1241. return "CMAKE_SHARED_MODULE_PREFIX";
  1242. case cmStateEnums::ImportLibraryArtifact:
  1243. return "CMAKE_IMPORT_LIBRARY_PREFIX";
  1244. }
  1245. break;
  1246. case cmStateEnums::EXECUTABLE:
  1247. switch (artifact) {
  1248. case cmStateEnums::RuntimeBinaryArtifact:
  1249. // Android GUI application packages store the native
  1250. // binary as a shared library.
  1251. return (this->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI")
  1252. ? "CMAKE_SHARED_LIBRARY_PREFIX"
  1253. : "");
  1254. case cmStateEnums::ImportLibraryArtifact:
  1255. return "CMAKE_IMPORT_LIBRARY_PREFIX";
  1256. }
  1257. break;
  1258. default:
  1259. break;
  1260. }
  1261. return "";
  1262. }
  1263. std::string cmTarget::ImportedGetFullPath(
  1264. const std::string& config, cmStateEnums::ArtifactType artifact) const
  1265. {
  1266. assert(this->IsImported());
  1267. // Lookup/compute/cache the import information for this
  1268. // configuration.
  1269. std::string desired_config = config;
  1270. if (config.empty()) {
  1271. desired_config = "NOCONFIG";
  1272. }
  1273. std::string result;
  1274. const char* loc = CM_NULLPTR;
  1275. const char* imp = CM_NULLPTR;
  1276. std::string suffix;
  1277. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
  1278. this->GetMappedConfig(desired_config, &loc, &imp, suffix)) {
  1279. switch (artifact) {
  1280. case cmStateEnums::RuntimeBinaryArtifact:
  1281. if (loc) {
  1282. result = loc;
  1283. } else {
  1284. std::string impProp = "IMPORTED_LOCATION";
  1285. impProp += suffix;
  1286. if (const char* config_location = this->GetProperty(impProp)) {
  1287. result = config_location;
  1288. } else if (const char* location =
  1289. this->GetProperty("IMPORTED_LOCATION")) {
  1290. result = location;
  1291. }
  1292. }
  1293. break;
  1294. case cmStateEnums::ImportLibraryArtifact:
  1295. if (imp) {
  1296. result = imp;
  1297. } else if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  1298. this->IsExecutableWithExports()) {
  1299. std::string impProp = "IMPORTED_IMPLIB";
  1300. impProp += suffix;
  1301. if (const char* config_implib = this->GetProperty(impProp)) {
  1302. result = config_implib;
  1303. } else if (const char* implib =
  1304. this->GetProperty("IMPORTED_IMPLIB")) {
  1305. result = implib;
  1306. }
  1307. }
  1308. break;
  1309. }
  1310. }
  1311. if (result.empty()) {
  1312. result = this->GetName();
  1313. result += "-NOTFOUND";
  1314. }
  1315. return result;
  1316. }
  1317. void cmTarget::SetPropertyDefault(const std::string& property,
  1318. const char* default_value)
  1319. {
  1320. // Compute the name of the variable holding the default value.
  1321. std::string var = "CMAKE_";
  1322. var += property;
  1323. if (const char* value = this->Makefile->GetDefinition(var)) {
  1324. this->SetProperty(property, value);
  1325. } else if (default_value) {
  1326. this->SetProperty(property, default_value);
  1327. }
  1328. }
  1329. bool cmTarget::CheckImportedLibName(std::string const& prop,
  1330. std::string const& value) const
  1331. {
  1332. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY ||
  1333. !this->IsImported()) {
  1334. this->Makefile->IssueMessage(
  1335. cmake::FATAL_ERROR, prop +
  1336. " property may be set only on imported INTERFACE library targets.");
  1337. return false;
  1338. }
  1339. if (!value.empty()) {
  1340. if (value[0] == '-') {
  1341. this->Makefile->IssueMessage(cmake::FATAL_ERROR, prop +
  1342. " property value\n " + value +
  1343. "\nmay not start with '-'.");
  1344. return false;
  1345. }
  1346. std::string::size_type bad = value.find_first_of(":/\\;");
  1347. if (bad != std::string::npos) {
  1348. this->Makefile->IssueMessage(
  1349. cmake::FATAL_ERROR, prop + " property value\n " + value +
  1350. "\nmay not contain '" + value.substr(bad, 1) + "'.");
  1351. return false;
  1352. }
  1353. }
  1354. return true;
  1355. }
  1356. bool cmTarget::GetMappedConfig(std::string const& desired_config,
  1357. const char** loc, const char** imp,
  1358. std::string& suffix) const
  1359. {
  1360. std::string config_upper;
  1361. if (!desired_config.empty()) {
  1362. config_upper = cmSystemTools::UpperCase(desired_config);
  1363. }
  1364. std::string locPropBase;
  1365. if (this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  1366. locPropBase = "IMPORTED_LIBNAME";
  1367. } else if (this->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  1368. locPropBase = "IMPORTED_OBJECTS";
  1369. } else {
  1370. locPropBase = "IMPORTED_LOCATION";
  1371. }
  1372. // Track the configuration-specific property suffix.
  1373. suffix = "_";
  1374. suffix += config_upper;
  1375. std::vector<std::string> mappedConfigs;
  1376. {
  1377. std::string mapProp = "MAP_IMPORTED_CONFIG_";
  1378. mapProp += config_upper;
  1379. if (const char* mapValue = this->GetProperty(mapProp)) {
  1380. cmSystemTools::ExpandListArgument(mapValue, mappedConfigs, true);
  1381. }
  1382. }
  1383. // If we needed to find one of the mapped configurations but did not
  1384. // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
  1385. // library or an executable with exports.
  1386. bool allowImp = this->HasImportLibrary();
  1387. // If a mapping was found, check its configurations.
  1388. for (std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
  1389. !*loc && !*imp && mci != mappedConfigs.end(); ++mci) {
  1390. // Look for this configuration.
  1391. if (mci->empty()) {
  1392. // An empty string in the mapping has a special meaning:
  1393. // look up the config-less properties.
  1394. *loc = this->GetProperty(locPropBase);
  1395. if (allowImp) {
  1396. *imp = this->GetProperty("IMPORTED_IMPLIB");
  1397. }
  1398. // If it was found, set the suffix.
  1399. if (*loc || *imp) {
  1400. suffix = "";
  1401. }
  1402. } else {
  1403. std::string mcUpper = cmSystemTools::UpperCase(*mci);
  1404. std::string locProp = locPropBase + "_";
  1405. locProp += mcUpper;
  1406. *loc = this->GetProperty(locProp);
  1407. if (allowImp) {
  1408. std::string impProp = "IMPORTED_IMPLIB_";
  1409. impProp += mcUpper;
  1410. *imp = this->GetProperty(impProp);
  1411. }
  1412. // If it was found, use it for all properties below.
  1413. if (*loc || *imp) {
  1414. suffix = "_";
  1415. suffix += mcUpper;
  1416. }
  1417. }
  1418. }
  1419. // If we needed to find one of the mapped configurations but did not
  1420. // then the target location is not found. The project does not want
  1421. // any other configuration.
  1422. if (!mappedConfigs.empty() && !*loc && !*imp) {
  1423. // Interface libraries are always available because their
  1424. // library name is optional so it is okay to leave *loc empty.
  1425. return this->GetType() == cmStateEnums::INTERFACE_LIBRARY;
  1426. }
  1427. // If we have not yet found it then there are no mapped
  1428. // configurations. Look for an exact-match.
  1429. if (!*loc && !*imp) {
  1430. std::string locProp = locPropBase;
  1431. locProp += suffix;
  1432. *loc = this->GetProperty(locProp);
  1433. if (allowImp) {
  1434. std::string impProp = "IMPORTED_IMPLIB";
  1435. impProp += suffix;
  1436. *imp = this->GetProperty(impProp);
  1437. }
  1438. }
  1439. // If we have not yet found it then there are no mapped
  1440. // configurations and no exact match.
  1441. if (!*loc && !*imp) {
  1442. // The suffix computed above is not useful.
  1443. suffix = "";
  1444. // Look for a configuration-less location. This may be set by
  1445. // manually-written code.
  1446. *loc = this->GetProperty(locPropBase);
  1447. if (allowImp) {
  1448. *imp = this->GetProperty("IMPORTED_IMPLIB");
  1449. }
  1450. }
  1451. // If we have not yet found it then the project is willing to try
  1452. // any available configuration.
  1453. if (!*loc && !*imp) {
  1454. std::vector<std::string> availableConfigs;
  1455. if (const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS")) {
  1456. cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
  1457. }
  1458. for (std::vector<std::string>::const_iterator aci =
  1459. availableConfigs.begin();
  1460. !*loc && !*imp && aci != availableConfigs.end(); ++aci) {
  1461. suffix = "_";
  1462. suffix += cmSystemTools::UpperCase(*aci);
  1463. std::string locProp = locPropBase;
  1464. locProp += suffix;
  1465. *loc = this->GetProperty(locProp);
  1466. if (allowImp) {
  1467. std::string impProp = "IMPORTED_IMPLIB";
  1468. impProp += suffix;
  1469. *imp = this->GetProperty(impProp);
  1470. }
  1471. }
  1472. }
  1473. // If we have not yet found it then the target location is not available.
  1474. if (!*loc && !*imp) {
  1475. // Interface libraries are always available because their
  1476. // library name is optional so it is okay to leave *loc empty.
  1477. return this->GetType() == cmStateEnums::INTERFACE_LIBRARY;
  1478. }
  1479. return true;
  1480. }
  1481. cmTargetInternalPointer::cmTargetInternalPointer()
  1482. {
  1483. this->Pointer = new cmTargetInternals;
  1484. }
  1485. cmTargetInternalPointer::cmTargetInternalPointer(
  1486. cmTargetInternalPointer const& r)
  1487. {
  1488. // Ideally cmTarget instances should never be copied. However until
  1489. // we can make a sweep to remove that, this copy constructor avoids
  1490. // allowing the resources (Internals) to be copied.
  1491. this->Pointer = new cmTargetInternals(*r.Pointer);
  1492. }
  1493. cmTargetInternalPointer::~cmTargetInternalPointer()
  1494. {
  1495. delete this->Pointer;
  1496. }
  1497. cmTargetInternalPointer& cmTargetInternalPointer::operator=(
  1498. cmTargetInternalPointer const& r)
  1499. {
  1500. if (this == &r) {
  1501. return *this;
  1502. } // avoid warning on HP about self check
  1503. // Ideally cmTarget instances should never be copied. However until
  1504. // we can make a sweep to remove that, this copy constructor avoids
  1505. // allowing the resources (Internals) to be copied.
  1506. cmTargetInternals* oldPointer = this->Pointer;
  1507. this->Pointer = new cmTargetInternals(*r.Pointer);
  1508. delete oldPointer;
  1509. return *this;
  1510. }