cmTarget.cxx 58 KB

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