cmTarget.cxx 57 KB

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