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 "cmInstallCommand.h"
14 #include "cmInstallDirectoryGenerator.h"
15 #include "cmInstallFilesGenerator.h"
16 #include "cmInstallScriptGenerator.h"
17 #include "cmInstallTargetGenerator.h"
18 #include "cmInstallExportGenerator.h"
19 #include "cmInstallCommandArguments.h"
21 #include <cmsys/Glob.hxx>
23 static cmInstallTargetGenerator* CreateInstallTargetGenerator(cmTarget& target,
24 const cmInstallCommandArguments& args, bool impLib, bool forceOpt = false)
26 return new cmInstallTargetGenerator(target, args.GetDestination().c_str(),
27 impLib, args.GetPermissions().c_str(),
28 args.GetConfigurations(), args.GetComponent().c_str(),
29 args.GetOptional() || forceOpt);
32 static cmInstallFilesGenerator* CreateInstallFilesGenerator(
33 const std::vector<std::string>& absFiles,
34 const cmInstallCommandArguments& args, bool programs)
36 return new cmInstallFilesGenerator(absFiles, args.GetDestination().c_str(),
37 programs, args.GetPermissions().c_str(),
38 args.GetConfigurations(), args.GetComponent().c_str(),
39 args.GetRename().c_str(), args.GetOptional());
44 bool cmInstallCommand::InitialPass(std::vector<std::string> const& args,
47 // Allow calling with no arguments so that arguments may be built up
48 // using a variable that may be left empty.
54 // Enable the install target.
55 this->Makefile->GetLocalGenerator()
56 ->GetGlobalGenerator()->EnableInstallTarget();
58 this->DefaultComponentName = this->Makefile->GetSafeDefinition(
59 "CMAKE_INSTALL_DEFAULT_COMPONENT_NAME");
60 if (this->DefaultComponentName.empty())
62 this->DefaultComponentName = "Unspecified";
65 // Switch among the command modes.
66 if(args[0] == "SCRIPT")
68 return this->HandleScriptMode(args);
70 else if(args[0] == "CODE")
72 return this->HandleScriptMode(args);
74 else if(args[0] == "TARGETS")
76 return this->HandleTargetsMode(args);
78 else if(args[0] == "FILES")
80 return this->HandleFilesMode(args);
82 else if(args[0] == "PROGRAMS")
84 return this->HandleFilesMode(args);
86 else if(args[0] == "DIRECTORY")
88 return this->HandleDirectoryMode(args);
90 else if(args[0] == "EXPORT")
92 return this->HandleExportMode(args);
96 cmStdString e = "called with unknown mode ";
98 this->SetError(e.c_str());
102 //----------------------------------------------------------------------------
103 bool cmInstallCommand::HandleScriptMode(std::vector<std::string> const& args)
105 std::string component = this->DefaultComponentName;
106 int componentCount = 0;
107 bool doing_script = false;
108 bool doing_code = false;
110 // Scan the args once for COMPONENT. Only allow one.
112 for(size_t i=0; i < args.size(); ++i)
114 if(args[i] == "COMPONENT" && i+1 < args.size())
124 this->SetError("given more than one COMPONENT for the SCRIPT or CODE "
125 "signature of the INSTALL command. "
126 "Use multiple INSTALL commands with one COMPONENT each.");
130 // Scan the args again, this time adding install generators each time we
131 // encounter a SCRIPT or CODE arg:
133 for(size_t i=0; i < args.size(); ++i)
135 if(args[i] == "SCRIPT")
140 else if(args[i] == "CODE")
142 doing_script = false;
145 else if(args[i] == "COMPONENT")
147 doing_script = false;
150 else if(doing_script)
152 doing_script = false;
153 std::string script = args[i];
154 if(!cmSystemTools::FileIsFullPath(script.c_str()))
156 script = this->Makefile->GetCurrentDirectory();
160 if(cmSystemTools::FileIsDirectory(script.c_str()))
162 this->SetError("given a directory as value of SCRIPT argument.");
165 this->Makefile->AddInstallGenerator(
166 new cmInstallScriptGenerator(script.c_str(), false,
172 std::string code = args[i];
173 this->Makefile->AddInstallGenerator(
174 new cmInstallScriptGenerator(code.c_str(), true,
181 this->SetError("given no value for SCRIPT argument.");
186 this->SetError("given no value for CODE argument.");
190 //Tell the global generator about any installation component names specified.
191 this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
192 ->AddInstallComponent(component.c_str());
200 InstallPart(cmCommandArgumentsHelper* helper, const char* key,
201 cmCommandArgumentGroup* group);
202 cmCAStringVector argVector;
203 cmInstallCommandArguments args;
206 //----------------------------------------------------------------------------
207 bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args)
209 // This is the TARGETS mode.
210 std::vector<cmTarget*> targets;
212 cmCommandArgumentsHelper argHelper;
213 cmCommandArgumentGroup group;
214 cmCAStringVector genericArgVector (&argHelper,0);
215 cmCAStringVector archiveArgVector (&argHelper,"ARCHIVE",&group);
216 cmCAStringVector libraryArgVector (&argHelper,"LIBRARY",&group);
217 cmCAStringVector runtimeArgVector (&argHelper,"RUNTIME",&group);
218 cmCAStringVector frameworkArgVector (&argHelper,"FRAMEWORK",&group);
219 cmCAStringVector bundleArgVector (&argHelper,"BUNDLE",&group);
220 cmCAStringVector privateHeaderArgVector(&argHelper,"PRIVATE_HEADER",&group);
221 cmCAStringVector publicHeaderArgVector (&argHelper,"PUBLIC_HEADER",&group);
222 cmCAStringVector resourceArgVector (&argHelper,"RESOURCE",&group);
223 genericArgVector.Follows(0);
224 group.Follows(&genericArgVector);
226 argHelper.Parse(&args, 0);
228 // now parse the generic args (i.e. the ones not specialized on LIBRARY/
229 // ARCHIVE, RUNTIME etc. (see above)
230 // These generic args also contain the targets and the export stuff
231 std::vector<std::string> unknownArgs;
232 cmInstallCommandArguments genericArgs(this->DefaultComponentName);
233 cmCAStringVector targetList(&genericArgs.Parser, "TARGETS");
234 cmCAString exports(&genericArgs.Parser,"EXPORT", &genericArgs.ArgumentGroup);
235 targetList.Follows(0);
236 genericArgs.ArgumentGroup.Follows(&targetList);
237 genericArgs.Parse(&genericArgVector.GetVector(), &unknownArgs);
238 bool success = genericArgs.Finalize();
240 cmInstallCommandArguments archiveArgs(this->DefaultComponentName);
241 cmInstallCommandArguments libraryArgs(this->DefaultComponentName);
242 cmInstallCommandArguments runtimeArgs(this->DefaultComponentName);
243 cmInstallCommandArguments frameworkArgs(this->DefaultComponentName);
244 cmInstallCommandArguments bundleArgs(this->DefaultComponentName);
245 cmInstallCommandArguments privateHeaderArgs(this->DefaultComponentName);
246 cmInstallCommandArguments publicHeaderArgs(this->DefaultComponentName);
247 cmInstallCommandArguments resourceArgs(this->DefaultComponentName);
249 // now parse the args for specific parts of the target (e.g. LIBRARY,
250 // RUNTIME, ARCHIVE etc.
251 archiveArgs.Parse (&archiveArgVector.GetVector(), &unknownArgs);
252 libraryArgs.Parse (&libraryArgVector.GetVector(), &unknownArgs);
253 runtimeArgs.Parse (&runtimeArgVector.GetVector(), &unknownArgs);
254 frameworkArgs.Parse (&frameworkArgVector.GetVector(), &unknownArgs);
255 bundleArgs.Parse (&bundleArgVector.GetVector(), &unknownArgs);
256 privateHeaderArgs.Parse(&privateHeaderArgVector.GetVector(), &unknownArgs);
257 publicHeaderArgs.Parse (&publicHeaderArgVector.GetVector(), &unknownArgs);
258 resourceArgs.Parse (&resourceArgVector.GetVector(), &unknownArgs);
260 if(!unknownArgs.empty())
264 e << "TARGETS given unknown argument \"" << unknownArgs[0] << "\".";
265 this->SetError(e.str().c_str());
269 // apply generic args
270 archiveArgs.SetGenericArguments(&genericArgs);
271 libraryArgs.SetGenericArguments(&genericArgs);
272 runtimeArgs.SetGenericArguments(&genericArgs);
273 frameworkArgs.SetGenericArguments(&genericArgs);
274 bundleArgs.SetGenericArguments(&genericArgs);
275 privateHeaderArgs.SetGenericArguments(&genericArgs);
276 publicHeaderArgs.SetGenericArguments(&genericArgs);
277 resourceArgs.SetGenericArguments(&genericArgs);
279 success = success && archiveArgs.Finalize();
280 success = success && libraryArgs.Finalize();
281 success = success && runtimeArgs.Finalize();
282 success = success && frameworkArgs.Finalize();
283 success = success && bundleArgs.Finalize();
284 success = success && privateHeaderArgs.Finalize();
285 success = success && publicHeaderArgs.Finalize();
286 success = success && resourceArgs.Finalize();
293 // Enforce argument rules too complex to specify for the
294 // general-purpose parser.
295 if(archiveArgs.GetNamelinkOnly() ||
296 runtimeArgs.GetNamelinkOnly() ||
297 frameworkArgs.GetNamelinkOnly() ||
298 bundleArgs.GetNamelinkOnly() ||
299 privateHeaderArgs.GetNamelinkOnly() ||
300 publicHeaderArgs.GetNamelinkOnly() ||
301 resourceArgs.GetNamelinkOnly())
304 "TARGETS given NAMELINK_ONLY option not in LIBRARY group. "
305 "The NAMELINK_ONLY option may be specified only following LIBRARY."
309 if(archiveArgs.GetNamelinkSkip() ||
310 runtimeArgs.GetNamelinkSkip() ||
311 frameworkArgs.GetNamelinkSkip() ||
312 bundleArgs.GetNamelinkSkip() ||
313 privateHeaderArgs.GetNamelinkSkip() ||
314 publicHeaderArgs.GetNamelinkSkip() ||
315 resourceArgs.GetNamelinkSkip())
318 "TARGETS given NAMELINK_SKIP option not in LIBRARY group. "
319 "The NAMELINK_SKIP option may be specified only following LIBRARY."
323 if(libraryArgs.GetNamelinkOnly() && libraryArgs.GetNamelinkSkip())
326 "TARGETS given NAMELINK_ONLY and NAMELINK_SKIP. "
327 "At most one of these two options may be specified."
332 // Select the mode for installing symlinks to versioned shared libraries.
333 cmInstallTargetGenerator::NamelinkModeType
334 namelinkMode = cmInstallTargetGenerator::NamelinkModeNone;
335 if(libraryArgs.GetNamelinkOnly())
337 namelinkMode = cmInstallTargetGenerator::NamelinkModeOnly;
339 else if(libraryArgs.GetNamelinkSkip())
341 namelinkMode = cmInstallTargetGenerator::NamelinkModeSkip;
344 // Check if there is something to do.
345 if(targetList.GetVector().empty())
350 // Check whether this is a DLL platform.
351 bool dll_platform = (this->Makefile->IsOn("WIN32") ||
352 this->Makefile->IsOn("CYGWIN") ||
353 this->Makefile->IsOn("MINGW"));
355 for(std::vector<std::string>::const_iterator
356 targetIt=targetList.GetVector().begin();
357 targetIt!=targetList.GetVector().end();
360 // Lookup this target in the current directory.
361 if(cmTarget* target=this->Makefile->FindTarget(targetIt->c_str()))
363 // Found the target. Check its type.
364 if(target->GetType() != cmTarget::EXECUTABLE &&
365 target->GetType() != cmTarget::STATIC_LIBRARY &&
366 target->GetType() != cmTarget::SHARED_LIBRARY &&
367 target->GetType() != cmTarget::MODULE_LIBRARY &&
368 target->GetType() != cmTarget::OBJECT_LIBRARY)
371 e << "TARGETS given target \"" << (*targetIt)
372 << "\" which is not an executable, library, or module.";
373 this->SetError(e.str().c_str());
376 else if(target->GetType() == cmTarget::OBJECT_LIBRARY)
379 e << "TARGETS given OBJECT library \"" << (*targetIt)
380 << "\" which may not be installed.";
381 this->SetError(e.str().c_str());
384 // Store the target in the list to be installed.
385 targets.push_back(target);
389 // Did not find the target.
391 e << "TARGETS given target \"" << (*targetIt)
392 << "\" which does not exist in this directory.";
393 this->SetError(e.str().c_str());
398 // Keep track of whether we will be performing an installation of
399 // any files of the given type.
400 bool installsArchive = false;
401 bool installsLibrary = false;
402 bool installsRuntime = false;
403 bool installsFramework = false;
404 bool installsBundle = false;
405 bool installsPrivateHeader = false;
406 bool installsPublicHeader = false;
407 bool installsResource = false;
409 // Generate install script code to install the given targets.
410 for(std::vector<cmTarget*>::iterator ti = targets.begin();
411 ti != targets.end(); ++ti)
413 // Handle each target type.
414 cmTarget& target = *(*ti);
415 cmInstallTargetGenerator* archiveGenerator = 0;
416 cmInstallTargetGenerator* libraryGenerator = 0;
417 cmInstallTargetGenerator* runtimeGenerator = 0;
418 cmInstallTargetGenerator* frameworkGenerator = 0;
419 cmInstallTargetGenerator* bundleGenerator = 0;
420 cmInstallFilesGenerator* privateHeaderGenerator = 0;
421 cmInstallFilesGenerator* publicHeaderGenerator = 0;
422 cmInstallFilesGenerator* resourceGenerator = 0;
424 // Track whether this is a namelink-only rule.
425 bool namelinkOnly = false;
427 switch(target.GetType())
429 case cmTarget::SHARED_LIBRARY:
431 // Shared libraries are handled differently on DLL and non-DLL
432 // platforms. All windows platforms are DLL platforms including
433 // cygwin. Currently no other platform is a DLL platform.
436 // When in namelink only mode skip all libraries on Windows.
437 if(namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly)
442 // This is a DLL platform.
443 if(!archiveArgs.GetDestination().empty())
445 // The import library uses the ARCHIVE properties.
446 archiveGenerator = CreateInstallTargetGenerator(target,
449 if(!runtimeArgs.GetDestination().empty())
451 // The DLL uses the RUNTIME properties.
452 runtimeGenerator = CreateInstallTargetGenerator(target,
455 if ((archiveGenerator==0) && (runtimeGenerator==0))
457 this->SetError("Library TARGETS given no DESTINATION!");
463 // This is a non-DLL platform.
464 // If it is marked with FRAMEWORK property use the FRAMEWORK set of
465 // INSTALL properties. Otherwise, use the LIBRARY properties.
466 if(target.IsFrameworkOnApple())
468 // When in namelink only mode skip frameworks.
469 if(namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly)
474 // Use the FRAMEWORK properties.
475 if (!frameworkArgs.GetDestination().empty())
477 frameworkGenerator = CreateInstallTargetGenerator(target,
478 frameworkArgs, false);
483 e << "TARGETS given no FRAMEWORK DESTINATION for shared library "
484 "FRAMEWORK target \"" << target.GetName() << "\".";
485 this->SetError(e.str().c_str());
491 // The shared library uses the LIBRARY properties.
492 if (!libraryArgs.GetDestination().empty())
494 libraryGenerator = CreateInstallTargetGenerator(target,
496 libraryGenerator->SetNamelinkMode(namelinkMode);
498 (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly);
503 e << "TARGETS given no LIBRARY DESTINATION for shared library "
504 "target \"" << target.GetName() << "\".";
505 this->SetError(e.str().c_str());
512 case cmTarget::STATIC_LIBRARY:
514 // Static libraries use ARCHIVE properties.
515 if (!archiveArgs.GetDestination().empty())
517 archiveGenerator = CreateInstallTargetGenerator(target, archiveArgs,
523 e << "TARGETS given no ARCHIVE DESTINATION for static library "
524 "target \"" << target.GetName() << "\".";
525 this->SetError(e.str().c_str());
530 case cmTarget::MODULE_LIBRARY:
532 // Modules use LIBRARY properties.
533 if (!libraryArgs.GetDestination().empty())
535 libraryGenerator = CreateInstallTargetGenerator(target, libraryArgs,
537 libraryGenerator->SetNamelinkMode(namelinkMode);
539 (namelinkMode == cmInstallTargetGenerator::NamelinkModeOnly);
544 e << "TARGETS given no LIBRARY DESTINATION for module target \""
545 << target.GetName() << "\".";
546 this->SetError(e.str().c_str());
551 case cmTarget::EXECUTABLE:
553 if(target.IsAppBundleOnApple())
555 // Application bundles use the BUNDLE properties.
556 if (!bundleArgs.GetDestination().empty())
558 bundleGenerator = CreateInstallTargetGenerator(target, bundleArgs,
561 else if(!runtimeArgs.GetDestination().empty())
563 bool failure = false;
564 if(this->CheckCMP0006(failure))
566 // For CMake 2.4 compatibility fallback to the RUNTIME
569 CreateInstallTargetGenerator(target, runtimeArgs, false);
579 e << "TARGETS given no BUNDLE DESTINATION for MACOSX_BUNDLE "
580 "executable target \"" << target.GetName() << "\".";
581 this->SetError(e.str().c_str());
587 // Executables use the RUNTIME properties.
588 if (!runtimeArgs.GetDestination().empty())
590 runtimeGenerator = CreateInstallTargetGenerator(target,
596 e << "TARGETS given no RUNTIME DESTINATION for executable "
597 "target \"" << target.GetName() << "\".";
598 this->SetError(e.str().c_str());
603 // On DLL platforms an executable may also have an import
604 // library. Install it to the archive destination if it
606 if(dll_platform && !archiveArgs.GetDestination().empty() &&
607 target.IsExecutableWithExports())
609 // The import library uses the ARCHIVE properties.
610 archiveGenerator = CreateInstallTargetGenerator(target,
611 archiveArgs, true, true);
616 // This should never happen due to the above type check.
621 // These well-known sets of files are installed *automatically* for
622 // FRAMEWORK SHARED library targets on the Mac as part of installing the
623 // FRAMEWORK. For other target types or on other platforms, they are not
624 // installed automatically and so we need to create install files
625 // generators for them.
626 bool createInstallGeneratorsForTargetFileSets = true;
628 if(target.IsFrameworkOnApple())
630 createInstallGeneratorsForTargetFileSets = false;
633 if(createInstallGeneratorsForTargetFileSets && !namelinkOnly)
635 const char* files = target.GetProperty("PRIVATE_HEADER");
636 if ((files) && (*files))
638 std::vector<std::string> relFiles;
639 cmSystemTools::ExpandListArgument(files, relFiles);
640 std::vector<std::string> absFiles;
641 if (!this->MakeFilesFullPath("PRIVATE_HEADER", relFiles, absFiles))
646 // Create the files install generator.
647 if (!privateHeaderArgs.GetDestination().empty())
649 privateHeaderGenerator =
650 CreateInstallFilesGenerator(absFiles, privateHeaderArgs, false);
655 e << "INSTALL TARGETS - target " << target.GetName() << " has "
656 << "PRIVATE_HEADER files but no PRIVATE_HEADER DESTINATION.";
657 cmSystemTools::Message(e.str().c_str(), "Warning");
661 files = target.GetProperty("PUBLIC_HEADER");
662 if ((files) && (*files))
664 std::vector<std::string> relFiles;
665 cmSystemTools::ExpandListArgument(files, relFiles);
666 std::vector<std::string> absFiles;
667 if (!this->MakeFilesFullPath("PUBLIC_HEADER", relFiles, absFiles))
672 // Create the files install generator.
673 if (!publicHeaderArgs.GetDestination().empty())
675 publicHeaderGenerator =
676 CreateInstallFilesGenerator(absFiles, publicHeaderArgs, false);
681 e << "INSTALL TARGETS - target " << target.GetName() << " has "
682 << "PUBLIC_HEADER files but no PUBLIC_HEADER DESTINATION.";
683 cmSystemTools::Message(e.str().c_str(), "Warning");
687 files = target.GetProperty("RESOURCE");
688 if ((files) && (*files))
690 std::vector<std::string> relFiles;
691 cmSystemTools::ExpandListArgument(files, relFiles);
692 std::vector<std::string> absFiles;
693 if (!this->MakeFilesFullPath("RESOURCE", relFiles, absFiles))
698 // Create the files install generator.
699 if (!resourceArgs.GetDestination().empty())
701 resourceGenerator = CreateInstallFilesGenerator(absFiles,
702 resourceArgs, false);
707 e << "INSTALL TARGETS - target " << target.GetName() << " has "
708 << "RESOURCE files but no RESOURCE DESTINATION.";
709 cmSystemTools::Message(e.str().c_str(), "Warning");
714 // Keep track of whether we're installing anything in each category
715 installsArchive = installsArchive || archiveGenerator != 0;
716 installsLibrary = installsLibrary || libraryGenerator != 0;
717 installsRuntime = installsRuntime || runtimeGenerator != 0;
718 installsFramework = installsFramework || frameworkGenerator != 0;
719 installsBundle = installsBundle || bundleGenerator != 0;
720 installsPrivateHeader = installsPrivateHeader
721 || privateHeaderGenerator != 0;
722 installsPublicHeader = installsPublicHeader || publicHeaderGenerator != 0;
723 installsResource = installsResource || resourceGenerator;
725 this->Makefile->AddInstallGenerator(archiveGenerator);
726 this->Makefile->AddInstallGenerator(libraryGenerator);
727 this->Makefile->AddInstallGenerator(runtimeGenerator);
728 this->Makefile->AddInstallGenerator(frameworkGenerator);
729 this->Makefile->AddInstallGenerator(bundleGenerator);
730 this->Makefile->AddInstallGenerator(privateHeaderGenerator);
731 this->Makefile->AddInstallGenerator(publicHeaderGenerator);
732 this->Makefile->AddInstallGenerator(resourceGenerator);
734 // Add this install rule to an export if one was specified and
735 // this is not a namelink-only rule.
736 if(!exports.GetString().empty() && !namelinkOnly)
738 this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
739 ->AddTargetToExports(exports.GetCString(), &target,
740 archiveGenerator, runtimeGenerator,
741 libraryGenerator, frameworkGenerator,
742 bundleGenerator, publicHeaderGenerator);
746 // Tell the global generator about any installation component names
750 this->Makefile->GetLocalGenerator()->
752 ->AddInstallComponent(archiveArgs.GetComponent().c_str());
756 this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
757 ->AddInstallComponent(libraryArgs.GetComponent().c_str());
761 this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
762 ->AddInstallComponent(runtimeArgs.GetComponent().c_str());
764 if (installsFramework)
766 this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
767 ->AddInstallComponent(frameworkArgs.GetComponent().c_str());
771 this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
772 ->AddInstallComponent(bundleArgs.GetComponent().c_str());
774 if (installsPrivateHeader)
776 this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
777 ->AddInstallComponent(privateHeaderArgs.GetComponent().c_str());
779 if (installsPublicHeader)
781 this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
782 ->AddInstallComponent(publicHeaderArgs.GetComponent().c_str());
784 if (installsResource)
786 this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
787 ->AddInstallComponent(resourceArgs.GetComponent().c_str());
793 //----------------------------------------------------------------------------
794 bool cmInstallCommand::HandleFilesMode(std::vector<std::string> const& args)
796 // This is the FILES mode.
797 bool programs = (args[0] == "PROGRAMS");
798 cmInstallCommandArguments ica(this->DefaultComponentName);
799 cmCAStringVector files(&ica.Parser, programs ? "PROGRAMS" : "FILES");
801 ica.ArgumentGroup.Follows(&files);
802 std::vector<std::string> unknownArgs;
803 ica.Parse(&args, &unknownArgs);
805 if(!unknownArgs.empty())
809 e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\".";
810 this->SetError(e.str().c_str());
814 // Check if there is something to do.
815 if(files.GetVector().empty())
820 if(!ica.GetRename().empty() && files.GetVector().size() > 1)
822 // The rename option works only with one file.
824 e << args[0] << " given RENAME option with more than one file.";
825 this->SetError(e.str().c_str());
829 std::vector<std::string> absFiles;
830 if (!this->MakeFilesFullPath(args[0].c_str(), files.GetVector(), absFiles))
840 if(ica.GetDestination().empty())
842 // A destination is required.
844 e << args[0] << " given no DESTINATION!";
845 this->SetError(e.str().c_str());
849 // Create the files install generator.
850 this->Makefile->AddInstallGenerator(
851 CreateInstallFilesGenerator(absFiles, ica, programs));
853 //Tell the global generator about any installation component names specified.
854 this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
855 ->AddInstallComponent(ica.GetComponent().c_str());
860 //----------------------------------------------------------------------------
862 cmInstallCommand::HandleDirectoryMode(std::vector<std::string> const& args)
864 enum Doing { DoingNone, DoingDirs, DoingDestination, DoingPattern,
865 DoingRegex, DoingPermsFile, DoingPermsDir, DoingPermsMatch,
866 DoingConfigurations, DoingComponent };
867 Doing doing = DoingDirs;
868 bool in_match_mode = false;
869 bool optional = false;
870 std::vector<std::string> dirs;
871 const char* destination = 0;
872 std::string permissions_file;
873 std::string permissions_dir;
874 std::vector<std::string> configurations;
875 std::string component = this->DefaultComponentName;
876 std::string literal_args;
877 for(unsigned int i=1; i < args.size(); ++i)
879 if(args[i] == "DESTINATION")
884 e << args[0] << " does not allow \""
885 << args[i] << "\" after PATTERN or REGEX.";
886 this->SetError(e.str().c_str());
890 // Switch to setting the destination property.
891 doing = DoingDestination;
893 else if(args[i] == "OPTIONAL")
898 e << args[0] << " does not allow \""
899 << args[i] << "\" after PATTERN or REGEX.";
900 this->SetError(e.str().c_str());
904 // Mark the rule as optional.
908 else if(args[i] == "PATTERN")
910 // Switch to a new pattern match rule.
911 doing = DoingPattern;
912 in_match_mode = true;
914 else if(args[i] == "REGEX")
916 // Switch to a new regex match rule.
918 in_match_mode = true;
920 else if(args[i] == "EXCLUDE")
922 // Add this property to the current match rule.
923 if(!in_match_mode || doing == DoingPattern || doing == DoingRegex)
926 e << args[0] << " does not allow \""
927 << args[i] << "\" before a PATTERN or REGEX is given.";
928 this->SetError(e.str().c_str());
931 literal_args += " EXCLUDE";
934 else if(args[i] == "PERMISSIONS")
939 e << args[0] << " does not allow \""
940 << args[i] << "\" before a PATTERN or REGEX is given.";
941 this->SetError(e.str().c_str());
945 // Switch to setting the current match permissions property.
946 literal_args += " PERMISSIONS";
947 doing = DoingPermsMatch;
949 else if(args[i] == "FILE_PERMISSIONS")
954 e << args[0] << " does not allow \""
955 << args[i] << "\" after PATTERN or REGEX.";
956 this->SetError(e.str().c_str());
960 // Switch to setting the file permissions property.
961 doing = DoingPermsFile;
963 else if(args[i] == "DIRECTORY_PERMISSIONS")
968 e << args[0] << " does not allow \""
969 << args[i] << "\" after PATTERN or REGEX.";
970 this->SetError(e.str().c_str());
974 // Switch to setting the directory permissions property.
975 doing = DoingPermsDir;
977 else if(args[i] == "USE_SOURCE_PERMISSIONS")
982 e << args[0] << " does not allow \""
983 << args[i] << "\" after PATTERN or REGEX.";
984 this->SetError(e.str().c_str());
988 // Add this option literally.
989 literal_args += " USE_SOURCE_PERMISSIONS";
992 else if(args[i] == "FILES_MATCHING")
997 e << args[0] << " does not allow \""
998 << args[i] << "\" after PATTERN or REGEX.";
999 this->SetError(e.str().c_str());
1003 // Add this option literally.
1004 literal_args += " FILES_MATCHING";
1007 else if(args[i] == "CONFIGURATIONS")
1012 e << args[0] << " does not allow \""
1013 << args[i] << "\" after PATTERN or REGEX.";
1014 this->SetError(e.str().c_str());
1018 // Switch to setting the configurations property.
1019 doing = DoingConfigurations;
1021 else if(args[i] == "COMPONENT")
1026 e << args[0] << " does not allow \""
1027 << args[i] << "\" after PATTERN or REGEX.";
1028 this->SetError(e.str().c_str());
1032 // Switch to setting the component property.
1033 doing = DoingComponent;
1035 else if(doing == DoingDirs)
1037 // Convert this directory to a full path.
1038 std::string dir = args[i];
1039 if(!cmSystemTools::FileIsFullPath(dir.c_str()))
1041 dir = this->Makefile->GetCurrentDirectory();
1046 // Make sure the name is a directory.
1047 if(cmSystemTools::FileExists(dir.c_str()) &&
1048 !cmSystemTools::FileIsDirectory(dir.c_str()))
1051 e << args[0] << " given non-directory \""
1052 << args[i] << "\" to install.";
1053 this->SetError(e.str().c_str());
1057 // Store the directory for installation.
1058 dirs.push_back(dir);
1060 else if(doing == DoingConfigurations)
1062 configurations.push_back(args[i]);
1064 else if(doing == DoingDestination)
1066 destination = args[i].c_str();
1069 else if(doing == DoingPattern)
1071 // Convert the pattern to a regular expression. Require a
1072 // leading slash and trailing end-of-string in the matched
1073 // string to make sure the pattern matches only whole file
1075 literal_args += " REGEX \"/";
1076 std::string regex = cmsys::Glob::PatternToRegex(args[i], false);
1077 cmSystemTools::ReplaceString(regex, "\\", "\\\\");
1078 literal_args += regex;
1079 literal_args += "$\"";
1082 else if(doing == DoingRegex)
1084 literal_args += " REGEX \"";
1085 // Match rules are case-insensitive on some platforms.
1086 #if defined(_WIN32) || defined(__APPLE__) || defined(__CYGWIN__)
1087 std::string regex = cmSystemTools::LowerCase(args[i]);
1089 std::string regex = args[i];
1091 cmSystemTools::ReplaceString(regex, "\\", "\\\\");
1092 literal_args += regex;
1093 literal_args += "\"";
1096 else if(doing == DoingComponent)
1098 component = args[i];
1101 else if(doing == DoingPermsFile)
1103 // Check the requested permission.
1104 if(!cmInstallCommandArguments::CheckPermissions(args[i],permissions_file))
1107 e << args[0] << " given invalid file permission \""
1108 << args[i] << "\".";
1109 this->SetError(e.str().c_str());
1113 else if(doing == DoingPermsDir)
1115 // Check the requested permission.
1116 if(!cmInstallCommandArguments::CheckPermissions(args[i],permissions_dir))
1119 e << args[0] << " given invalid directory permission \""
1120 << args[i] << "\".";
1121 this->SetError(e.str().c_str());
1125 else if(doing == DoingPermsMatch)
1127 // Check the requested permission.
1128 if(!cmInstallCommandArguments::CheckPermissions(args[i], literal_args))
1131 e << args[0] << " given invalid permission \""
1132 << args[i] << "\".";
1133 this->SetError(e.str().c_str());
1139 // Unknown argument.
1141 e << args[0] << " given unknown argument \"" << args[i] << "\".";
1142 this->SetError(e.str().c_str());
1147 // Support installing an empty directory.
1148 if(dirs.empty() && destination)
1153 // Check if there is something to do.
1160 // A destination is required.
1162 e << args[0] << " given no DESTINATION!";
1163 this->SetError(e.str().c_str());
1167 // Create the directory install generator.
1168 this->Makefile->AddInstallGenerator(
1169 new cmInstallDirectoryGenerator(dirs, destination,
1170 permissions_file.c_str(),
1171 permissions_dir.c_str(),
1174 literal_args.c_str(),
1177 // Tell the global generator about any installation component names
1179 this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
1180 ->AddInstallComponent(component.c_str());
1185 //----------------------------------------------------------------------------
1186 bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args)
1188 // This is the EXPORT mode.
1189 cmInstallCommandArguments ica(this->DefaultComponentName);
1190 cmCAString exp(&ica.Parser, "EXPORT");
1191 cmCAString name_space(&ica.Parser, "NAMESPACE", &ica.ArgumentGroup);
1192 cmCAString filename(&ica.Parser, "FILE", &ica.ArgumentGroup);
1195 ica.ArgumentGroup.Follows(&exp);
1196 std::vector<std::string> unknownArgs;
1197 ica.Parse(&args, &unknownArgs);
1199 if (!unknownArgs.empty())
1201 // Unknown argument.
1203 e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\".";
1204 this->SetError(e.str().c_str());
1208 if (!ica.Finalize())
1213 // Make sure there is a destination.
1214 if(ica.GetDestination().empty())
1216 // A destination is required.
1218 e << args[0] << " given no DESTINATION!";
1219 this->SetError(e.str().c_str());
1223 // Check the file name.
1224 std::string fname = filename.GetString();
1225 if(fname.find_first_of(":/\\") != fname.npos)
1228 e << args[0] << " given invalid export file name \"" << fname << "\". "
1229 << "The FILE argument may not contain a path. "
1230 << "Specify the path in the DESTINATION argument.";
1231 this->SetError(e.str().c_str());
1235 // Check the file extension.
1236 if(!fname.empty() &&
1237 cmSystemTools::GetFilenameLastExtension(fname) != ".cmake")
1240 e << args[0] << " given invalid export file name \"" << fname << "\". "
1241 << "The FILE argument must specify a name ending in \".cmake\".";
1242 this->SetError(e.str().c_str());
1246 // Construct the file name.
1249 fname = exp.GetString();
1252 if(fname.find_first_of(":/\\") != fname.npos)
1255 e << args[0] << " given export name \"" << exp.GetString() << "\". "
1256 << "This name cannot be safely converted to a file name. "
1257 << "Specify a different export name or use the FILE option to set "
1258 << "a file name explicitly.";
1259 this->SetError(e.str().c_str());
1264 // Create the export install generator.
1265 cmInstallExportGenerator* exportGenerator =
1266 new cmInstallExportGenerator(
1267 exp.GetCString(), ica.GetDestination().c_str(),
1268 ica.GetPermissions().c_str(), ica.GetConfigurations(),
1269 ica.GetComponent().c_str(), fname.c_str(),
1270 name_space.GetCString(), this->Makefile);
1271 this->Makefile->AddInstallGenerator(exportGenerator);
1276 bool cmInstallCommand::MakeFilesFullPath(const char* modeName,
1277 const std::vector<std::string>& relFiles,
1278 std::vector<std::string>& absFiles)
1280 for(std::vector<std::string>::const_iterator fileIt = relFiles.begin();
1281 fileIt != relFiles.end();
1284 std::string file = (*fileIt);
1285 if(!cmSystemTools::FileIsFullPath(file.c_str()))
1287 file = this->Makefile->GetCurrentDirectory();
1292 // Make sure the file is not a directory.
1293 if(cmSystemTools::FileIsDirectory(file.c_str()))
1296 e << modeName << " given directory \"" << (*fileIt) << "\" to install.";
1297 this->SetError(e.str().c_str());
1300 // Store the file for installation.
1301 absFiles.push_back(file);
1306 //----------------------------------------------------------------------------
1307 bool cmInstallCommand::CheckCMP0006(bool& failure)
1309 switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0006))
1311 case cmPolicies::WARN:
1313 this->Makefile->IssueMessage(
1314 cmake::AUTHOR_WARNING,
1315 this->Makefile->GetPolicies()->GetPolicyWarning(cmPolicies::CMP0006)
1318 case cmPolicies::OLD:
1319 // OLD behavior is to allow compatibility
1321 case cmPolicies::NEW:
1322 // NEW behavior is to disallow compatibility
1324 case cmPolicies::REQUIRED_IF_USED:
1325 case cmPolicies::REQUIRED_ALWAYS:
1327 this->Makefile->IssueMessage(
1329 this->Makefile->GetPolicies()
1330 ->GetRequiredPolicyError(cmPolicies::CMP0006)