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 "cmInstallTargetsCommand.h" 4 5 #include <unordered_map> 6 #include <utility> 7 8 #include "cmExecutionStatus.h" 9 #include "cmGlobalGenerator.h" 10 #include "cmMakefile.h" 11 #include "cmTarget.h" 12 cmInstallTargetsCommand(std::vector<std::string> const & args,cmExecutionStatus & status)13bool cmInstallTargetsCommand(std::vector<std::string> const& args, 14 cmExecutionStatus& status) 15 { 16 if (args.size() < 2) { 17 status.SetError("called with incorrect number of arguments"); 18 return false; 19 } 20 21 cmMakefile& mf = status.GetMakefile(); 22 23 // Enable the install target. 24 mf.GetGlobalGenerator()->EnableInstallTarget(); 25 26 cmMakefile::cmTargetMap& tgts = mf.GetTargets(); 27 auto s = args.begin(); 28 ++s; 29 std::string runtime_dir = "/bin"; 30 for (; s != args.end(); ++s) { 31 if (*s == "RUNTIME_DIRECTORY") { 32 ++s; 33 if (s == args.end()) { 34 status.SetError("called with RUNTIME_DIRECTORY but no actual " 35 "directory"); 36 return false; 37 } 38 39 runtime_dir = *s; 40 } else { 41 auto ti = tgts.find(*s); 42 if (ti != tgts.end()) { 43 ti->second.SetInstallPath(args[0]); 44 ti->second.SetRuntimeInstallPath(runtime_dir); 45 ti->second.SetHaveInstallRule(true); 46 } else { 47 std::string str = "Cannot find target: \"" + *s + "\" to install."; 48 status.SetError(str); 49 return false; 50 } 51 } 52 } 53 54 mf.GetGlobalGenerator()->AddInstallComponent( 55 mf.GetSafeDefinition("CMAKE_INSTALL_DEFAULT_COMPONENT_NAME")); 56 57 return true; 58 } 59