cmTarget.cxx 57 KB

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