cmTarget.cxx 57 KB

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