cmTarget.cxx 57 KB

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