cmTarget.cxx 57 KB

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