1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #include "cmExportFileGenerator.h"
14 #include "cmExportSet.h"
15 #include "cmGeneratedFileStream.h"
16 #include "cmGlobalGenerator.h"
17 #include "cmInstallExportGenerator.h"
18 #include "cmLocalGenerator.h"
19 #include "cmMakefile.h"
20 #include "cmSystemTools.h"
22 #include "cmTargetExport.h"
23 #include "cmVersion.h"
24 #include "cmComputeLinkInformation.h"
26 #include <cmsys/auto_ptr.hxx>
29 //----------------------------------------------------------------------------
30 cmExportFileGenerator::cmExportFileGenerator()
32 this->AppendMode = false;
33 this->ExportOld = false;
36 //----------------------------------------------------------------------------
37 void cmExportFileGenerator::AddConfiguration(const char* config)
39 this->Configurations.push_back(config);
42 //----------------------------------------------------------------------------
43 void cmExportFileGenerator::SetExportFile(const char* mainFile)
45 this->MainImportFile = mainFile;
47 cmSystemTools::GetFilenamePath(this->MainImportFile);
49 cmSystemTools::GetFilenameWithoutLastExtension(this->MainImportFile);
51 cmSystemTools::GetFilenameLastExtension(this->MainImportFile);
54 //----------------------------------------------------------------------------
55 bool cmExportFileGenerator::GenerateImportFile()
57 // Open the output file to generate it.
58 cmsys::auto_ptr<std::ofstream> foutPtr;
62 cmsys::auto_ptr<std::ofstream>
63 ap(new std::ofstream(this->MainImportFile.c_str(), std::ios::app));
68 // Generate atomically and with copy-if-different.
69 cmsys::auto_ptr<cmGeneratedFileStream>
70 ap(new cmGeneratedFileStream(this->MainImportFile.c_str(), true));
71 ap->SetCopyIfDifferent(true);
74 if(!foutPtr.get() || !*foutPtr)
76 std::string se = cmSystemTools::GetLastSystemError();
78 e << "cannot write to file \"" << this->MainImportFile
80 cmSystemTools::Error(e.str().c_str());
83 std::ostream& os = *foutPtr;
85 // Protect that file against use with older CMake versions.
86 os << "# Generated by CMake " << cmVersion::GetCMakeVersion() << "\n\n";
87 os << "if(\"${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}\" LESS 2.5)\n"
88 << " message(FATAL_ERROR \"CMake >= 2.6.0 required\")\n"
91 // Isolate the file policy level.
92 // We use 2.6 here instead of the current version because newer
93 // versions of CMake should be able to export files imported by 2.6
94 // until the import format changes.
95 os << "cmake_policy(PUSH)\n"
96 << "cmake_policy(VERSION 2.6)\n";
98 // Start with the import file header.
99 this->GenerateImportHeaderCode(os);
101 // Create all the imported targets.
102 bool result = this->GenerateMainFile(os);
104 // End with the import file footer.
105 this->GenerateImportFooterCode(os);
106 os << "cmake_policy(POP)\n";
111 //----------------------------------------------------------------------------
112 void cmExportFileGenerator::GenerateImportConfig(std::ostream& os,
114 std::vector<std::string> &missingTargets)
116 // Construct the property configuration suffix.
117 std::string suffix = "_";
118 if(config && *config)
120 suffix += cmSystemTools::UpperCase(config);
124 suffix += "NOCONFIG";
127 // Generate the per-config target information.
128 this->GenerateImportTargetsConfig(os, config, suffix, missingTargets);
131 //----------------------------------------------------------------------------
132 void cmExportFileGenerator::PopulateInterfaceProperty(const char *propName,
134 ImportPropertyMap &properties)
136 const char *input = target->GetProperty(propName);
139 properties[propName] = input;
143 //----------------------------------------------------------------------------
144 void cmExportFileGenerator::PopulateInterfaceProperty(const char *propName,
145 const char *outputName,
147 cmGeneratorExpression::PreprocessContext preprocessRule,
148 ImportPropertyMap &properties,
149 std::vector<std::string> &missingTargets)
151 const char *input = target->GetProperty(propName);
157 properties[outputName] = "";
161 std::string prepro = cmGeneratorExpression::Preprocess(input,
165 this->ResolveTargetsInGeneratorExpressions(prepro, target,
167 properties[outputName] = prepro;
172 void cmExportFileGenerator::GenerateRequiredCMakeVersion(std::ostream& os,
173 const char *versionString)
175 os << "if(CMAKE_VERSION VERSION_LESS " << versionString << ")\n"
176 " message(FATAL_ERROR \"This file relies on consumers using "
177 "CMake " << versionString << " or greater.\")\n"
181 //----------------------------------------------------------------------------
182 bool cmExportFileGenerator::PopulateInterfaceLinkLibrariesProperty(
184 cmGeneratorExpression::PreprocessContext preprocessRule,
185 ImportPropertyMap &properties,
186 std::vector<std::string> &missingTargets)
188 if(!target->IsLinkable())
192 const char *input = target->GetProperty("INTERFACE_LINK_LIBRARIES");
195 std::string prepro = cmGeneratorExpression::Preprocess(input,
199 this->ResolveTargetsInGeneratorExpressions(prepro, target,
202 properties["INTERFACE_LINK_LIBRARIES"] = prepro;
209 //----------------------------------------------------------------------------
210 static bool isSubDirectory(const char* a, const char* b)
212 return (cmSystemTools::ComparePath(a, b) ||
213 cmSystemTools::IsSubDirectory(a, b));
216 //----------------------------------------------------------------------------
217 static bool checkInterfaceDirs(const std::string &prepro,
220 const char* installDir =
221 target->GetMakefile()->GetSafeDefinition("CMAKE_INSTALL_PREFIX");
222 const char* topSourceDir = target->GetMakefile()->GetHomeDirectory();
223 const char* topBinaryDir = target->GetMakefile()->GetHomeOutputDirectory();
225 std::vector<std::string> parts;
226 cmGeneratorExpression::Split(prepro, parts);
228 const bool inSourceBuild = strcmp(topSourceDir, topBinaryDir) == 0;
230 for(std::vector<std::string>::iterator li = parts.begin();
231 li != parts.end(); ++li)
233 if (cmGeneratorExpression::Find(*li) != std::string::npos)
237 if (strncmp(li->c_str(), "${_IMPORT_PREFIX}", 17) == 0)
241 if (!cmSystemTools::FileIsFullPath(li->c_str()))
244 e << "Target \"" << target->GetName() << "\" "
245 "INTERFACE_INCLUDE_DIRECTORIES property contains relative path:\n"
246 " \"" << *li << "\"";
247 target->GetMakefile()->IssueMessage(cmake::FATAL_ERROR,
251 if (isSubDirectory(li->c_str(), installDir))
255 if (isSubDirectory(li->c_str(), topBinaryDir))
258 e << "Target \"" << target->GetName() << "\" "
259 "INTERFACE_INCLUDE_DIRECTORIES property contains path:\n"
260 " \"" << *li << "\"\nwhich is prefixed in the build directory.";
261 target->GetMakefile()->IssueMessage(cmake::FATAL_ERROR,
267 if (isSubDirectory(li->c_str(), topSourceDir))
270 e << "Target \"" << target->GetName() << "\" "
271 "INTERFACE_INCLUDE_DIRECTORIES property contains path:\n"
272 " \"" << *li << "\"\nwhich is prefixed in the source directory.";
273 target->GetMakefile()->IssueMessage(cmake::FATAL_ERROR,
282 //----------------------------------------------------------------------------
283 void cmExportFileGenerator::PopulateIncludeDirectoriesInterface(
285 cmGeneratorExpression::PreprocessContext preprocessRule,
286 ImportPropertyMap &properties,
287 std::vector<std::string> &missingTargets)
289 cmTarget *target = tei->Target;
290 assert(preprocessRule == cmGeneratorExpression::InstallInterface);
292 const char *propName = "INTERFACE_INCLUDE_DIRECTORIES";
293 const char *input = target->GetProperty(propName);
295 cmListFileBacktrace lfbt;
296 cmGeneratorExpression ge(lfbt);
298 std::string dirs = tei->InterfaceIncludeDirectories;
299 this->ReplaceInstallPrefix(dirs);
300 cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(dirs);
301 std::string exportDirs = cge->Evaluate(target->GetMakefile(), 0,
304 if (cge->GetHadContextSensitiveCondition())
306 cmMakefile* mf = target->GetMakefile();
308 e << "Target \"" << target->GetName() << "\" is installed with "
309 "INCLUDES DESTINATION set to a context sensitive path. Paths which "
310 "depend on the configuration, policy values or the link interface are "
311 "not supported. Consider using target_include_directories instead.";
312 mf->IssueMessage(cmake::FATAL_ERROR, e.str());
316 if (!input && exportDirs.empty())
320 if ((input && !*input) && exportDirs.empty())
323 properties[propName] = "";
327 std::string includes = (input?input:"");
328 const char* sep = input ? ";" : "";
329 includes += sep + exportDirs;
330 std::string prepro = cmGeneratorExpression::Preprocess(includes,
335 this->ResolveTargetsInGeneratorExpressions(prepro, target,
338 if (!checkInterfaceDirs(prepro, target))
342 properties[propName] = prepro;
346 //----------------------------------------------------------------------------
347 void cmExportFileGenerator::PopulateInterfaceProperty(const char *propName,
349 cmGeneratorExpression::PreprocessContext preprocessRule,
350 ImportPropertyMap &properties,
351 std::vector<std::string> &missingTargets)
353 this->PopulateInterfaceProperty(propName, propName, target, preprocessRule,
354 properties, missingTargets);
358 //----------------------------------------------------------------------------
359 void getPropertyContents(cmTarget *tgt, const char *prop,
360 std::set<std::string> &ifaceProperties)
362 const char *p = tgt->GetProperty(prop);
367 std::vector<std::string> content;
368 cmSystemTools::ExpandListArgument(p, content);
369 for (std::vector<std::string>::const_iterator ci = content.begin();
370 ci != content.end(); ++ci)
372 ifaceProperties.insert(*ci);
376 //----------------------------------------------------------------------------
377 void getCompatibleInterfaceProperties(cmTarget *target,
378 std::set<std::string> &ifaceProperties,
381 cmComputeLinkInformation *info = target->GetLinkInformation(config);
385 cmMakefile* mf = target->GetMakefile();
387 e << "Exporting the target \"" << target->GetName() << "\" is not "
388 "allowed since its linker language cannot be determined";
389 mf->IssueMessage(cmake::FATAL_ERROR, e.str());
393 const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
395 for(cmComputeLinkInformation::ItemVector::const_iterator li =
397 li != deps.end(); ++li)
403 getPropertyContents(li->Target,
404 "COMPATIBLE_INTERFACE_BOOL",
406 getPropertyContents(li->Target,
407 "COMPATIBLE_INTERFACE_STRING",
412 //----------------------------------------------------------------------------
413 void cmExportFileGenerator::PopulateCompatibleInterfaceProperties(
415 ImportPropertyMap &properties)
417 this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_BOOL",
419 this->PopulateInterfaceProperty("COMPATIBLE_INTERFACE_STRING",
422 std::set<std::string> ifaceProperties;
424 getPropertyContents(target, "COMPATIBLE_INTERFACE_BOOL", ifaceProperties);
425 getPropertyContents(target, "COMPATIBLE_INTERFACE_STRING", ifaceProperties);
427 getCompatibleInterfaceProperties(target, ifaceProperties, 0);
429 std::vector<std::string> configNames;
430 target->GetMakefile()->GetConfigurations(configNames);
432 for (std::vector<std::string>::const_iterator ci = configNames.begin();
433 ci != configNames.end(); ++ci)
435 getCompatibleInterfaceProperties(target, ifaceProperties, ci->c_str());
438 for (std::set<std::string>::const_iterator it = ifaceProperties.begin();
439 it != ifaceProperties.end(); ++it)
441 this->PopulateInterfaceProperty(("INTERFACE_" + *it).c_str(),
446 //----------------------------------------------------------------------------
447 void cmExportFileGenerator::GenerateInterfaceProperties(cmTarget *target,
449 const ImportPropertyMap &properties)
451 if (!properties.empty())
453 std::string targetName = this->Namespace;
454 targetName += target->GetExportName();
455 os << "set_target_properties(" << targetName << " PROPERTIES\n";
456 for(ImportPropertyMap::const_iterator pi = properties.begin();
457 pi != properties.end(); ++pi)
459 os << " " << pi->first << " \"" << pi->second << "\"\n";
465 //----------------------------------------------------------------------------
467 cmExportFileGenerator::AddTargetNamespace(std::string &input,
469 std::vector<std::string> &missingTargets)
471 cmMakefile *mf = target->GetMakefile();
473 cmTarget *tgt = mf->FindTargetToUse(input.c_str());
479 if(tgt->IsImported())
483 if(this->ExportedTargets.find(tgt) != this->ExportedTargets.end())
485 input = this->Namespace + tgt->GetExportName();
489 std::string namespacedTarget;
490 this->HandleMissingTarget(namespacedTarget, missingTargets,
492 if (!namespacedTarget.empty())
494 input = namespacedTarget;
500 //----------------------------------------------------------------------------
502 cmExportFileGenerator::ResolveTargetsInGeneratorExpressions(
505 std::vector<std::string> &missingTargets,
506 FreeTargetsReplace replace)
508 if (replace == NoReplaceFreeTargets)
510 this->ResolveTargetsInGeneratorExpression(input, target, missingTargets);
513 std::vector<std::string> parts;
514 cmGeneratorExpression::Split(input, parts);
518 for(std::vector<std::string>::iterator li = parts.begin();
519 li != parts.end(); ++li)
521 if (cmGeneratorExpression::Find(*li) == std::string::npos)
523 this->AddTargetNamespace(*li, target, missingTargets);
527 this->ResolveTargetsInGeneratorExpression(
537 //----------------------------------------------------------------------------
539 cmExportFileGenerator::ResolveTargetsInGeneratorExpression(
542 std::vector<std::string> &missingTargets)
544 std::string::size_type pos = 0;
545 std::string::size_type lastPos = pos;
547 cmMakefile *mf = target->GetMakefile();
549 while((pos = input.find("$<TARGET_PROPERTY:", lastPos)) != input.npos)
551 std::string::size_type nameStartPos = pos +
552 sizeof("$<TARGET_PROPERTY:") - 1;
553 std::string::size_type closePos = input.find(">", nameStartPos);
554 std::string::size_type commaPos = input.find(",", nameStartPos);
555 std::string::size_type nextOpenPos = input.find("$<", nameStartPos);
556 if (commaPos == input.npos // Implied 'this' target
557 || closePos == input.npos // Imcomplete expression.
558 || closePos < commaPos // Implied 'this' target
559 || nextOpenPos < commaPos) // Non-literal
561 lastPos = nameStartPos;
565 std::string targetName = input.substr(nameStartPos,
566 commaPos - nameStartPos);
568 if (this->AddTargetNamespace(targetName, target, missingTargets))
570 input.replace(nameStartPos, commaPos - nameStartPos, targetName);
572 lastPos = nameStartPos + targetName.size() + 1;
575 std::string errorString;
578 while((pos = input.find("$<TARGET_NAME:", lastPos)) != input.npos)
580 std::string::size_type nameStartPos = pos + sizeof("$<TARGET_NAME:") - 1;
581 std::string::size_type endPos = input.find(">", nameStartPos);
582 if (endPos == input.npos)
584 errorString = "$<TARGET_NAME:...> expression incomplete";
587 std::string targetName = input.substr(nameStartPos,
588 endPos - nameStartPos);
589 if(targetName.find("$<") != input.npos)
591 errorString = "$<TARGET_NAME:...> requires its parameter to be a "
595 if (!this->AddTargetNamespace(targetName, target, missingTargets))
597 errorString = "$<TARGET_NAME:...> requires its parameter to be a "
601 input.replace(pos, endPos - pos + 1, targetName);
605 this->ReplaceInstallPrefix(input);
607 if (!errorString.empty())
609 mf->IssueMessage(cmake::FATAL_ERROR, errorString);
613 //----------------------------------------------------------------------------
615 cmExportFileGenerator::ReplaceInstallPrefix(std::string &)
620 //----------------------------------------------------------------------------
622 cmExportFileGenerator
623 ::SetImportLinkInterface(const char* config, std::string const& suffix,
624 cmGeneratorExpression::PreprocessContext preprocessRule,
625 cmTarget* target, ImportPropertyMap& properties,
626 std::vector<std::string>& missingTargets)
628 // Add the transitive link dependencies for this configuration.
629 cmTarget::LinkInterface const* iface = target->GetLinkInterface(config,
636 if (iface->ImplementationIsInterface)
638 // Policy CMP0022 must not be NEW.
639 this->SetImportLinkProperty(suffix, target,
640 "IMPORTED_LINK_INTERFACE_LIBRARIES",
641 iface->Libraries, properties, missingTargets);
645 const char *propContent;
647 if (const char *prop_suffixed = target->GetProperty(
648 ("LINK_INTERFACE_LIBRARIES" + suffix).c_str()))
650 propContent = prop_suffixed;
652 else if (const char *prop = target->GetProperty(
653 "LINK_INTERFACE_LIBRARIES"))
662 const bool newCMP0022Behavior =
663 target->GetPolicyStatusCMP0022() != cmPolicies::WARN
664 && target->GetPolicyStatusCMP0022() != cmPolicies::OLD;
666 if(newCMP0022Behavior && !this->ExportOld)
668 cmMakefile *mf = target->GetMakefile();
670 e << "Target \"" << target->GetName() << "\" has policy CMP0022 enabled, "
671 "but also has old-style LINK_INTERFACE_LIBRARIES properties "
672 "populated, but it was exported without the "
673 "EXPORT_LINK_INTERFACE_LIBRARIES to export the old-style properties";
674 mf->IssueMessage(cmake::FATAL_ERROR, e.str());
680 properties["IMPORTED_LINK_INTERFACE_LIBRARIES" + suffix] = "";
684 std::string prepro = cmGeneratorExpression::Preprocess(propContent,
688 this->ResolveTargetsInGeneratorExpressions(prepro, target,
691 properties["IMPORTED_LINK_INTERFACE_LIBRARIES" + suffix] = prepro;
695 //----------------------------------------------------------------------------
697 cmExportFileGenerator
698 ::SetImportDetailProperties(const char* config, std::string const& suffix,
699 cmTarget* target, ImportPropertyMap& properties,
700 std::vector<std::string>& missingTargets
703 // Get the makefile in which to lookup target information.
704 cmMakefile* mf = target->GetMakefile();
706 // Add the soname for unix shared libraries.
707 if(target->GetType() == cmTarget::SHARED_LIBRARY ||
708 target->GetType() == cmTarget::MODULE_LIBRARY)
710 // Check whether this is a DLL platform.
712 (mf->IsOn("WIN32") || mf->IsOn("CYGWIN") || mf->IsOn("MINGW"));
717 if(target->HasSOName(config))
719 if(mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
721 value = this->InstallNameDir(target, config);
723 prop = "IMPORTED_SONAME";
724 value += target->GetSOName(config);
728 prop = "IMPORTED_NO_SONAME";
732 properties[prop] = value;
736 // Add the transitive link dependencies for this configuration.
737 if(cmTarget::LinkInterface const* iface = target->GetLinkInterface(config,
740 this->SetImportLinkProperty(suffix, target,
741 "IMPORTED_LINK_INTERFACE_LANGUAGES",
742 iface->Languages, properties, missingTargets);
744 this->SetImportLinkProperty(suffix, target,
745 "IMPORTED_LINK_DEPENDENT_LIBRARIES",
746 iface->SharedDeps, properties, missingTargets);
747 if(iface->Multiplicity > 0)
749 std::string prop = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
752 m << iface->Multiplicity;
753 properties[prop] = m.str();
758 //----------------------------------------------------------------------------
760 cmExportFileGenerator
761 ::SetImportLinkProperty(std::string const& suffix,
763 const char* propName,
764 std::vector<std::string> const& libs,
765 ImportPropertyMap& properties,
766 std::vector<std::string>& missingTargets
769 // Skip the property if there are no libraries.
775 // Construct the property value.
776 std::string link_libs;
777 const char* sep = "";
778 for(std::vector<std::string>::const_iterator li = libs.begin();
779 li != libs.end(); ++li)
781 // Separate this from the previous entry.
785 std::string temp = *li;
786 this->AddTargetNamespace(temp, target, missingTargets);
790 // Store the property.
791 std::string prop = propName;
793 properties[prop] = link_libs;
797 //----------------------------------------------------------------------------
798 void cmExportFileGenerator::GenerateImportHeaderCode(std::ostream& os,
801 os << "#----------------------------------------------------------------\n"
802 << "# Generated CMake target import file";
805 os << " for configuration \"" << config << "\".\n";
811 os << "#----------------------------------------------------------------\n"
813 this->GenerateImportVersionCode(os);
816 //----------------------------------------------------------------------------
817 void cmExportFileGenerator::GenerateImportFooterCode(std::ostream& os)
819 os << "# Commands beyond this point should not need to know the version.\n"
820 << "set(CMAKE_IMPORT_FILE_VERSION)\n";
823 //----------------------------------------------------------------------------
824 void cmExportFileGenerator::GenerateImportVersionCode(std::ostream& os)
826 // Store an import file format version. This will let us change the
827 // format later while still allowing old import files to work.
828 os << "# Commands may need to know the format version.\n"
829 << "set(CMAKE_IMPORT_FILE_VERSION 1)\n"
833 //----------------------------------------------------------------------------
834 void cmExportFileGenerator::GenerateExpectedTargetsCode(std::ostream& os,
835 const std::string &expectedTargets)
837 os << "# Protect against multiple inclusion, which would fail when already "
838 "imported targets are added once more.\n"
839 "set(_targetsDefined)\n"
840 "set(_targetsNotDefined)\n"
841 "set(_expectedTargets)\n"
842 "foreach(_expectedTarget " << expectedTargets << ")\n"
843 " list(APPEND _expectedTargets ${_expectedTarget})\n"
844 " if(NOT TARGET ${_expectedTarget})\n"
845 " list(APPEND _targetsNotDefined ${_expectedTarget})\n"
847 " if(TARGET ${_expectedTarget})\n"
848 " list(APPEND _targetsDefined ${_expectedTarget})\n"
851 "if(\"${_targetsDefined}\" STREQUAL \"${_expectedTargets}\")\n"
852 " set(CMAKE_IMPORT_FILE_VERSION)\n"
853 " cmake_policy(POP)\n"
856 "if(NOT \"${_targetsDefined}\" STREQUAL \"\")\n"
857 " message(FATAL_ERROR \"Some (but not all) targets in this export "
858 "set were already defined.\\nTargets Defined: ${_targetsDefined}\\n"
859 "Targets not yet defined: ${_targetsNotDefined}\\n\")\n"
861 "unset(_targetsDefined)\n"
862 "unset(_targetsNotDefined)\n"
863 "unset(_expectedTargets)\n"
866 //----------------------------------------------------------------------------
868 cmExportFileGenerator
869 ::GenerateImportTargetCode(std::ostream& os, cmTarget* target)
871 // Construct the imported target name.
872 std::string targetName = this->Namespace;
874 targetName += target->GetExportName();
876 // Create the imported target.
877 os << "# Create imported target " << targetName << "\n";
878 switch(target->GetType())
880 case cmTarget::EXECUTABLE:
881 os << "add_executable(" << targetName << " IMPORTED)\n";
883 case cmTarget::STATIC_LIBRARY:
884 os << "add_library(" << targetName << " STATIC IMPORTED)\n";
886 case cmTarget::SHARED_LIBRARY:
887 os << "add_library(" << targetName << " SHARED IMPORTED)\n";
889 case cmTarget::MODULE_LIBRARY:
890 os << "add_library(" << targetName << " MODULE IMPORTED)\n";
892 case cmTarget::UNKNOWN_LIBRARY:
893 os << "add_library(" << targetName << " UNKNOWN IMPORTED)\n";
895 default: // should never happen
899 // Mark the imported executable if it has exports.
900 if(target->IsExecutableWithExports())
902 os << "set_property(TARGET " << targetName
903 << " PROPERTY ENABLE_EXPORTS 1)\n";
906 // Mark the imported library if it is a framework.
907 if(target->IsFrameworkOnApple())
909 os << "set_property(TARGET " << targetName
910 << " PROPERTY FRAMEWORK 1)\n";
913 // Mark the imported executable if it is an application bundle.
914 if(target->IsAppBundleOnApple())
916 os << "set_property(TARGET " << targetName
917 << " PROPERTY MACOSX_BUNDLE 1)\n";
920 if (target->IsCFBundleOnApple())
922 os << "set_property(TARGET " << targetName
923 << " PROPERTY BUNDLE 1)\n";
928 //----------------------------------------------------------------------------
930 cmExportFileGenerator
931 ::GenerateImportPropertyCode(std::ostream& os, const char* config,
933 ImportPropertyMap const& properties)
935 // Construct the imported target name.
936 std::string targetName = this->Namespace;
938 targetName += target->GetExportName();
940 // Set the import properties.
941 os << "# Import target \"" << targetName << "\" for configuration \""
943 os << "set_property(TARGET " << targetName
944 << " APPEND PROPERTY IMPORTED_CONFIGURATIONS ";
945 if(config && *config)
947 os << cmSystemTools::UpperCase(config);
954 os << "set_target_properties(" << targetName << " PROPERTIES\n";
955 for(ImportPropertyMap::const_iterator pi = properties.begin();
956 pi != properties.end(); ++pi)
958 os << " " << pi->first << " \"" << pi->second << "\"\n";
965 //----------------------------------------------------------------------------
966 void cmExportFileGenerator::GenerateMissingTargetsCheckCode(std::ostream& os,
967 const std::vector<std::string>& missingTargets)
969 if (missingTargets.empty())
971 os << "# This file does not depend on other imported targets which have\n"
972 "# been exported from the same project but in a separate "
976 os << "# Make sure the targets which have been exported in some other \n"
977 "# export set exist.\n"
978 "unset(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
980 std::set<std::string> emitted;
981 for(unsigned int i=0; i<missingTargets.size(); ++i)
983 if (emitted.insert(missingTargets[i]).second)
985 os << "\"" << missingTargets[i] << "\" ";
989 " if(NOT TARGET \"${_target}\" )\n"
990 " set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets \""
991 "${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets} ${_target}\")"
996 "if(DEFINED ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
997 " if(CMAKE_FIND_PACKAGE_NAME)\n"
998 " set( ${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE)\n"
999 " set( ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "
1000 "\"The following imported targets are "
1001 "referenced, but are missing: "
1002 "${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets}\")\n"
1004 " message(FATAL_ERROR \"The following imported targets are "
1005 "referenced, but are missing: "
1006 "${${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets}\")\n"
1009 "unset(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE_targets)\n"
1014 //----------------------------------------------------------------------------
1016 cmExportFileGenerator::GenerateImportedFileCheckLoop(std::ostream& os)
1018 // Add code which verifies at cmake time that the file which is being
1019 // imported actually exists on disk. This should in theory always be theory
1020 // case, but still when packages are split into normal and development
1021 // packages this might get broken (e.g. the Config.cmake could be part of
1022 // the non-development package, something similar happened to me without
1023 // on SUSE with a mysql pkg-config file, which claimed everything is fine,
1024 // but the development package was not installed.).
1025 os << "# Loop over all imported files and verify that they actually exist\n"
1026 "foreach(target ${_IMPORT_CHECK_TARGETS} )\n"
1027 " foreach(file ${_IMPORT_CHECK_FILES_FOR_${target}} )\n"
1028 " if(NOT EXISTS \"${file}\" )\n"
1029 " message(FATAL_ERROR \"The imported target \\\"${target}\\\""
1030 " references the file\n"
1031 " \\\"${file}\\\"\n"
1032 "but this file does not exist. Possible reasons include:\n"
1033 "* The file was deleted, renamed, or moved to another location.\n"
1034 "* An install or uninstall procedure did not complete successfully.\n"
1035 "* The installation package was faulty and contained\n"
1036 " \\\"${CMAKE_CURRENT_LIST_FILE}\\\"\n"
1037 "but not all the files it references.\n"
1041 " unset(_IMPORT_CHECK_FILES_FOR_${target})\n"
1043 "unset(_IMPORT_CHECK_TARGETS)\n"
1048 //----------------------------------------------------------------------------
1050 cmExportFileGenerator
1051 ::GenerateImportedFileChecksCode(std::ostream& os, cmTarget* target,
1052 ImportPropertyMap const& properties,
1053 const std::set<std::string>& importedLocations)
1055 // Construct the imported target name.
1056 std::string targetName = this->Namespace;
1057 targetName += target->GetExportName();
1059 os << "list(APPEND _IMPORT_CHECK_TARGETS " << targetName << " )\n"
1060 "list(APPEND _IMPORT_CHECK_FILES_FOR_" << targetName << " ";
1062 for(std::set<std::string>::const_iterator li = importedLocations.begin();
1063 li != importedLocations.end();
1066 ImportPropertyMap::const_iterator pi = properties.find(*li);
1067 if (pi != properties.end())
1069 os << "\"" << pi->second << "\" ";