cmTarget.cxx 57 KB

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