2013-10-04 01:28:00 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
|
|
|
|
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
|
|
|
#include "cmcmd.h"
|
2016-04-29 16:40:20 +03:00
|
|
|
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmAlgorithms.h"
|
2013-10-04 01:28:00 +04:00
|
|
|
#include "cmGlobalGenerator.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmLocalGenerator.h"
|
|
|
|
#include "cmMakefile.h"
|
2013-09-24 22:07:45 +04:00
|
|
|
#include "cmQtAutoGenerators.h"
|
2013-10-04 01:28:00 +04:00
|
|
|
#include "cmVersion.h"
|
|
|
|
|
|
|
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
2016-05-16 17:34:04 +03:00
|
|
|
#include "cmDependsFortran.h" // For -E cmake_copy_f90_mod callback.
|
2013-10-04 01:28:00 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <cmsys/Directory.hxx>
|
2014-01-04 09:47:13 +04:00
|
|
|
#include <cmsys/FStream.hxx>
|
2016-04-29 17:53:13 +03:00
|
|
|
#include <cmsys/Process.h>
|
2015-02-06 00:29:59 +03:00
|
|
|
#include <cmsys/Terminal.h>
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
#if defined(CMAKE_HAVE_VS_GENERATORS)
|
|
|
|
#include "cmCallVisualStudioMacro.h"
|
|
|
|
#include "cmVisualStudioWCEPlatformParser.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include <stdlib.h> // required for atoi
|
2015-06-19 23:12:43 +03:00
|
|
|
#if defined(_WIN32) && defined(CMAKE_BUILD_WITH_CMAKE)
|
2015-11-16 23:31:10 +03:00
|
|
|
#include "bindexplib.h"
|
2015-06-19 23:12:43 +03:00
|
|
|
#endif
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
void CMakeCommandUsage(const char* program)
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream errorStream;
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2013-10-04 01:28:00 +04:00
|
|
|
errorStream
|
|
|
|
<< "cmake version " << cmVersion::GetCMakeVersion() << "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
/* clang-format on */
|
2013-10-04 01:28:00 +04:00
|
|
|
#else
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2013-10-04 01:28:00 +04:00
|
|
|
errorStream
|
|
|
|
<< "cmake bootstrap\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
/* clang-format on */
|
2013-10-04 01:28:00 +04:00
|
|
|
#endif
|
|
|
|
// If you add new commands, change here,
|
|
|
|
// and in cmakemain.cxx in the options table
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2013-10-04 01:28:00 +04:00
|
|
|
errorStream
|
2015-12-03 02:43:37 +03:00
|
|
|
<< "Usage: " << program << " -E <command> [arguments...]\n"
|
2013-10-04 01:28:00 +04:00
|
|
|
<< "Available commands: \n"
|
2015-12-06 22:30:44 +03:00
|
|
|
<< " chdir dir cmd [args...] - run command in a given directory\n"
|
2013-10-04 01:28:00 +04:00
|
|
|
<< " compare_files file1 file2 - check if file1 is same as file2\n"
|
2015-12-03 23:29:30 +03:00
|
|
|
<< " copy <file>... destination - copy files to destination "
|
|
|
|
"(either file or directory)\n"
|
2015-12-06 22:30:44 +03:00
|
|
|
<< " copy_directory <dir>... destination - copy content of <dir>... "
|
|
|
|
"directories to 'destination' directory\n"
|
2015-12-03 23:29:30 +03:00
|
|
|
<< " copy_if_different <file>... destination - copy files if it has "
|
2013-10-04 01:28:00 +04:00
|
|
|
"changed\n"
|
2015-12-03 02:43:37 +03:00
|
|
|
<< " echo [<string>...] - displays arguments as text\n"
|
|
|
|
<< " echo_append [<string>...] - displays arguments as text but no new "
|
2013-10-04 01:28:00 +04:00
|
|
|
"line\n"
|
2014-06-24 00:33:33 +04:00
|
|
|
<< " env [--unset=NAME]... [NAME=VALUE]... COMMAND [ARG]...\n"
|
|
|
|
<< " - run command in a modified environment\n"
|
2013-10-04 01:28:00 +04:00
|
|
|
<< " environment - display the current environment\n"
|
2015-12-09 17:59:43 +03:00
|
|
|
<< " make_directory <dir>... - create parent and <dir> directories\n"
|
2016-05-02 13:27:57 +03:00
|
|
|
<< " md5sum <file>... - create MD5 checksum of files\n"
|
2015-12-03 02:43:37 +03:00
|
|
|
<< " remove [-f] <file>... - remove the file(s), use -f to force "
|
2013-10-04 01:28:00 +04:00
|
|
|
"it\n"
|
|
|
|
<< " remove_directory dir - remove a directory and its contents\n"
|
|
|
|
<< " rename oldname newname - rename a file or directory "
|
|
|
|
"(on one volume)\n"
|
2015-01-09 00:56:33 +03:00
|
|
|
<< " tar [cxt][vf][zjJ] file.tar [file/dir1 file/dir2 ...]\n"
|
2013-10-04 01:28:00 +04:00
|
|
|
<< " - create or extract a tar or zip archive\n"
|
2014-01-21 22:48:30 +04:00
|
|
|
<< " sleep <number>... - sleep for given number of seconds\n"
|
2015-12-03 02:43:37 +03:00
|
|
|
<< " time command [args...] - run command and return elapsed time\n"
|
2013-10-04 01:28:00 +04:00
|
|
|
<< " touch file - touch a file.\n"
|
|
|
|
<< " touch_nocreate file - touch a file but do not create it.\n"
|
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
|
<< "Available on Windows only:\n"
|
|
|
|
<< " delete_regv key - delete registry value\n"
|
|
|
|
<< " env_vs8_wince sdkname - displays a batch file which sets the "
|
|
|
|
"environment for the provided Windows CE SDK installed in VS2005\n"
|
|
|
|
<< " env_vs9_wince sdkname - displays a batch file which sets the "
|
|
|
|
"environment for the provided Windows CE SDK installed in VS2008\n"
|
|
|
|
<< " write_regv key value - write registry value\n"
|
|
|
|
#else
|
|
|
|
<< "Available on UNIX only:\n"
|
|
|
|
<< " create_symlink old new - create a symbolic link new -> old\n"
|
|
|
|
#endif
|
|
|
|
;
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
cmSystemTools::Error(errorStream.str().c_str());
|
|
|
|
}
|
|
|
|
|
2015-01-26 21:28:31 +03:00
|
|
|
static bool cmTarFilesFrom(std::string const& file,
|
|
|
|
std::vector<std::string>& files)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileIsDirectory(file)) {
|
2015-01-26 21:28:31 +03:00
|
|
|
std::ostringstream e;
|
|
|
|
e << "-E tar --files-from= file '" << file << "' is a directory";
|
|
|
|
cmSystemTools::Error(e.str().c_str());
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-01-26 21:28:31 +03:00
|
|
|
cmsys::ifstream fin(file.c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!fin) {
|
2015-01-26 21:28:31 +03:00
|
|
|
std::ostringstream e;
|
|
|
|
e << "-E tar --files-from= file '" << file << "' not found";
|
|
|
|
cmSystemTools::Error(e.str().c_str());
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-01-26 21:28:31 +03:00
|
|
|
std::string line;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (cmSystemTools::GetLineFromStream(fin, line)) {
|
|
|
|
if (line.empty()) {
|
2015-01-26 21:28:31 +03:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (cmHasLiteralPrefix(line, "--add-file=")) {
|
2015-01-26 21:28:31 +03:00
|
|
|
files.push_back(line.substr(11));
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (cmHasLiteralPrefix(line, "-")) {
|
2015-01-26 21:28:31 +03:00
|
|
|
std::ostringstream e;
|
|
|
|
e << "-E tar --files-from='" << file << "' file invalid line:\n"
|
|
|
|
<< line << "\n";
|
|
|
|
cmSystemTools::Error(e.str().c_str());
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-01-26 21:28:31 +03:00
|
|
|
files.push_back(line);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-01-26 21:28:31 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-04 01:28:00 +04:00
|
|
|
int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
|
|
|
|
{
|
|
|
|
// IF YOU ADD A NEW COMMAND, DOCUMENT IT ABOVE and in cmakemain.cxx
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args.size() > 1) {
|
2013-10-04 01:28:00 +04:00
|
|
|
// Copy file
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args[1] == "copy" && args.size() > 3) {
|
2015-12-03 23:29:30 +03:00
|
|
|
// If multiple source files specified,
|
|
|
|
// then destination must be directory
|
|
|
|
if ((args.size() > 4) &&
|
2016-05-16 17:34:04 +03:00
|
|
|
(!cmSystemTools::FileIsDirectory(args[args.size() - 1]))) {
|
2015-12-03 23:29:30 +03:00
|
|
|
std::cerr << "Error: Target (for copy command) \""
|
2016-05-16 17:34:04 +03:00
|
|
|
<< args[args.size() - 1] << "\" is not a directory.\n";
|
2013-10-04 01:28:00 +04:00
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-12-03 23:29:30 +03:00
|
|
|
// If error occurs we want to continue copying next files.
|
|
|
|
bool return_value = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::string::size_type cc = 2; cc < args.size() - 1; cc++) {
|
|
|
|
if (!cmSystemTools::cmCopyFile(args[cc].c_str(),
|
|
|
|
args[args.size() - 1].c_str())) {
|
|
|
|
std::cerr << "Error copying file \"" << args[cc] << "\" to \""
|
|
|
|
<< args[args.size() - 1] << "\".\n";
|
2015-12-03 23:29:30 +03:00
|
|
|
return_value = 1;
|
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return return_value;
|
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
// Copy file if different.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args[1] == "copy_if_different" && args.size() > 3) {
|
2015-12-03 23:29:30 +03:00
|
|
|
// If multiple source files specified,
|
|
|
|
// then destination must be directory
|
|
|
|
if ((args.size() > 4) &&
|
2016-05-16 17:34:04 +03:00
|
|
|
(!cmSystemTools::FileIsDirectory(args[args.size() - 1]))) {
|
2015-12-03 23:29:30 +03:00
|
|
|
std::cerr << "Error: Target (for copy_if_different command) \""
|
2016-05-16 17:34:04 +03:00
|
|
|
<< args[args.size() - 1] << "\" is not a directory.\n";
|
2013-10-04 01:28:00 +04:00
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-12-03 23:29:30 +03:00
|
|
|
// If error occurs we want to continue copying next files.
|
|
|
|
bool return_value = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::string::size_type cc = 2; cc < args.size() - 1; cc++) {
|
|
|
|
if (!cmSystemTools::CopyFileIfDifferent(
|
|
|
|
args[cc].c_str(), args[args.size() - 1].c_str())) {
|
|
|
|
std::cerr << "Error copying file (if different) from \"" << args[cc]
|
|
|
|
<< "\" to \"" << args[args.size() - 1] << "\".\n";
|
2015-12-03 23:29:30 +03:00
|
|
|
return_value = 1;
|
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return return_value;
|
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
// Copy directory content
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args[1] == "copy_directory" && args.size() > 3) {
|
2015-12-06 22:30:44 +03:00
|
|
|
// If error occurs we want to continue copying next files.
|
|
|
|
bool return_value = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::string::size_type cc = 2; cc < args.size() - 1; cc++) {
|
|
|
|
if (!cmSystemTools::CopyADirectory(args[cc].c_str(),
|
|
|
|
args[args.size() - 1].c_str())) {
|
|
|
|
std::cerr << "Error copying directory from \"" << args[cc]
|
|
|
|
<< "\" to \"" << args[args.size() - 1] << "\".\n";
|
2015-12-06 22:30:44 +03:00
|
|
|
return_value = 1;
|
2013-10-04 01:28:00 +04:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return return_value;
|
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
// Rename a file or directory
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args[1] == "rename" && args.size() == 4) {
|
|
|
|
if (!cmSystemTools::RenameFile(args[2].c_str(), args[3].c_str())) {
|
2013-10-04 01:28:00 +04:00
|
|
|
std::string e = cmSystemTools::GetLastSystemError();
|
2016-05-16 17:34:04 +03:00
|
|
|
std::cerr << "Error renaming from \"" << args[2] << "\" to \""
|
|
|
|
<< args[3] << "\": " << e << "\n";
|
2013-10-04 01:28:00 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
// Compare files
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args[1] == "compare_files" && args.size() == 4) {
|
|
|
|
if (cmSystemTools::FilesDiffer(args[2], args[3])) {
|
|
|
|
std::cerr << "Files \"" << args[2] << "\" to \"" << args[3]
|
2013-10-04 01:28:00 +04:00
|
|
|
<< "\" are different.\n";
|
|
|
|
return 1;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
2015-06-19 23:12:43 +03:00
|
|
|
#if defined(_WIN32) && defined(CMAKE_BUILD_WITH_CMAKE)
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "__create_def") {
|
|
|
|
if (args.size() < 4) {
|
|
|
|
std::cerr
|
|
|
|
<< "__create_def Usage: -E __create_def outfile.def objlistfile\n";
|
2015-06-19 23:12:43 +03:00
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-06-19 23:12:43 +03:00
|
|
|
FILE* fout = cmsys::SystemTools::Fopen(args[2].c_str(), "w+");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!fout) {
|
2015-06-19 23:12:43 +03:00
|
|
|
std::cerr << "could not open output .def file: " << args[2].c_str()
|
|
|
|
<< "\n";
|
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
cmsys::ifstream fin(args[3].c_str(), std::ios::in | std::ios::binary);
|
|
|
|
if (!fin) {
|
2015-06-19 23:12:43 +03:00
|
|
|
std::cerr << "could not open object list file: " << args[3].c_str()
|
|
|
|
<< "\n";
|
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-06-19 23:12:43 +03:00
|
|
|
std::string objfile;
|
2015-11-16 23:31:10 +03:00
|
|
|
bindexplib deffile;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (cmSystemTools::GetLineFromStream(fin, objfile)) {
|
|
|
|
if (!deffile.AddObjectFile(objfile.c_str())) {
|
2015-06-19 23:12:43 +03:00
|
|
|
return 1;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-11-16 23:31:10 +03:00
|
|
|
deffile.WriteFile(fout);
|
|
|
|
fclose(fout);
|
2015-06-19 23:12:43 +03:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-06-19 23:12:43 +03:00
|
|
|
#endif
|
2015-05-14 20:31:32 +03:00
|
|
|
// run include what you use command and then run the compile
|
|
|
|
// command. This is an internal undocumented option and should
|
|
|
|
// only be used by CMake itself when running iwyu.
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "__run_iwyu") {
|
|
|
|
if (args.size() < 3) {
|
2015-05-14 20:31:32 +03:00
|
|
|
std::cerr << "__run_iwyu Usage: -E __run_iwyu [--iwyu=/path/iwyu]"
|
2016-05-16 17:34:04 +03:00
|
|
|
" [--tidy=/path/tidy] -- compile command\n";
|
2015-05-14 20:31:32 +03:00
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-05-14 20:31:32 +03:00
|
|
|
bool doing_options = true;
|
|
|
|
std::vector<std::string> orig_cmd;
|
|
|
|
std::string iwyu;
|
2016-04-08 23:09:27 +03:00
|
|
|
std::string tidy;
|
|
|
|
std::string sourceFile;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::string::size_type cc = 2; cc < args.size(); cc++) {
|
2015-05-14 20:31:32 +03:00
|
|
|
std::string const& arg = args[cc];
|
2016-05-16 17:34:04 +03:00
|
|
|
if (arg == "--") {
|
2015-05-14 20:31:32 +03:00
|
|
|
doing_options = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (doing_options && cmHasLiteralPrefix(arg, "--iwyu=")) {
|
2015-05-14 20:31:32 +03:00
|
|
|
iwyu = arg.substr(7);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (doing_options && cmHasLiteralPrefix(arg, "--tidy=")) {
|
2016-04-08 23:09:27 +03:00
|
|
|
tidy = arg.substr(7);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (doing_options && cmHasLiteralPrefix(arg, "--source=")) {
|
2016-04-08 23:09:27 +03:00
|
|
|
sourceFile = arg.substr(9);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (doing_options) {
|
2015-05-14 20:31:32 +03:00
|
|
|
std::cerr << "__run_iwyu given unknown argument: " << arg << "\n";
|
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-05-14 20:31:32 +03:00
|
|
|
orig_cmd.push_back(arg);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (tidy.empty() && iwyu.empty()) {
|
2016-04-08 23:09:27 +03:00
|
|
|
std::cerr << "__run_iwyu missing --tidy= or --iwyu=\n";
|
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!tidy.empty() && sourceFile.empty()) {
|
2016-04-08 23:09:27 +03:00
|
|
|
std::cerr << "__run_iwyu --tidy= requires --source=\n";
|
2015-05-14 20:31:32 +03:00
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (orig_cmd.empty()) {
|
2015-05-14 20:31:32 +03:00
|
|
|
std::cerr << "__run_iwyu missing compile command after --\n";
|
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-05-14 20:31:32 +03:00
|
|
|
|
|
|
|
int ret = 0;
|
2016-04-08 23:09:27 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!iwyu.empty()) {
|
2016-04-08 23:09:27 +03:00
|
|
|
// Construct the iwyu command line by taking what was given
|
|
|
|
// and adding all the arguments we give to the compiler.
|
|
|
|
std::vector<std::string> iwyu_cmd;
|
|
|
|
cmSystemTools::ExpandListArgument(iwyu, iwyu_cmd, true);
|
2016-05-16 17:34:04 +03:00
|
|
|
iwyu_cmd.insert(iwyu_cmd.end(), orig_cmd.begin() + 1, orig_cmd.end());
|
2016-04-08 23:09:27 +03:00
|
|
|
|
|
|
|
// Run the iwyu command line. Capture its stderr and hide its stdout.
|
|
|
|
std::string stdErr;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::RunSingleCommand(iwyu_cmd, 0, &stdErr, &ret, 0,
|
|
|
|
cmSystemTools::OUTPUT_NONE)) {
|
|
|
|
std::cerr << "Error running '" << iwyu_cmd[0] << "': " << stdErr
|
|
|
|
<< "\n";
|
2016-04-08 23:09:27 +03:00
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-04-08 23:09:27 +03:00
|
|
|
|
|
|
|
// Warn if iwyu reported anything.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (stdErr.find("should remove these lines:") != stdErr.npos ||
|
|
|
|
stdErr.find("should add these lines:") != stdErr.npos) {
|
2016-04-08 23:09:27 +03:00
|
|
|
std::cerr << "Warning: include-what-you-use reported diagnostics:\n"
|
|
|
|
<< stdErr << "\n";
|
2015-05-14 20:31:32 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-05-14 20:31:32 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!tidy.empty()) {
|
2016-04-08 23:09:27 +03:00
|
|
|
// Construct the clang-tidy command line by taking what was given
|
2016-04-28 01:48:15 +03:00
|
|
|
// and adding our compiler command line. The clang-tidy tool will
|
|
|
|
// automatically skip over the compiler itself and extract the
|
|
|
|
// options.
|
2016-04-08 23:09:27 +03:00
|
|
|
std::vector<std::string> tidy_cmd;
|
|
|
|
cmSystemTools::ExpandListArgument(tidy, tidy_cmd, true);
|
|
|
|
tidy_cmd.push_back(sourceFile);
|
|
|
|
tidy_cmd.push_back("--");
|
2016-04-28 01:48:15 +03:00
|
|
|
tidy_cmd.insert(tidy_cmd.end(), orig_cmd.begin(), orig_cmd.end());
|
2016-04-08 23:09:27 +03:00
|
|
|
|
2016-04-26 23:50:54 +03:00
|
|
|
// Run the tidy command line. Capture its stdout and hide its stderr.
|
|
|
|
std::string stdOut;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::RunSingleCommand(tidy_cmd, &stdOut, 0, &ret, 0,
|
|
|
|
cmSystemTools::OUTPUT_NONE)) {
|
2016-04-08 23:09:27 +03:00
|
|
|
std::cerr << "Error running '" << tidy_cmd[0] << "'\n";
|
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-04-26 23:50:54 +03:00
|
|
|
|
|
|
|
// Output the stdout from clang-tidy to stderr
|
|
|
|
std::cerr << stdOut;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-05-14 20:31:32 +03:00
|
|
|
|
|
|
|
// Now run the real compiler command and return its result value.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::RunSingleCommand(
|
|
|
|
orig_cmd, 0, 0, &ret, 0, cmSystemTools::OUTPUT_PASSTHROUGH)) {
|
2016-01-14 22:42:11 +03:00
|
|
|
std::cerr << "Error running '" << orig_cmd[0] << "'\n";
|
2015-05-14 20:31:32 +03:00
|
|
|
return 1;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return ret;
|
|
|
|
}
|
2015-05-14 20:31:32 +03:00
|
|
|
|
2013-10-04 01:28:00 +04:00
|
|
|
// Echo string
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "echo") {
|
2015-07-18 11:45:18 +03:00
|
|
|
std::cout << cmJoin(cmMakeRange(args).advance(2), " ") << std::endl;
|
2013-10-04 01:28:00 +04:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
// Echo string no new line
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "echo_append") {
|
2015-07-18 11:45:18 +03:00
|
|
|
std::cout << cmJoin(cmMakeRange(args).advance(2), " ");
|
2013-10-04 01:28:00 +04:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "env") {
|
2014-06-24 00:33:33 +04:00
|
|
|
std::vector<std::string>::const_iterator ai = args.begin() + 2;
|
|
|
|
std::vector<std::string>::const_iterator ae = args.end();
|
2016-05-16 17:34:04 +03:00
|
|
|
for (; ai != ae; ++ai) {
|
2014-06-24 00:33:33 +04:00
|
|
|
std::string const& a = *ai;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmHasLiteralPrefix(a, "--unset=")) {
|
2014-06-24 00:33:33 +04:00
|
|
|
// Unset environment variable.
|
|
|
|
cmSystemTools::UnPutEnv(a.c_str() + 8);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (!a.empty() && a[0] == '-') {
|
2014-06-24 00:33:33 +04:00
|
|
|
// Environment variable and command names cannot start in '-',
|
|
|
|
// so this must be an unknown option.
|
|
|
|
std::cerr << "cmake -E env: unknown option '" << a << "'"
|
|
|
|
<< std::endl;
|
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (a.find("=") != a.npos) {
|
2014-06-24 00:33:33 +04:00
|
|
|
// Set environment variable.
|
2014-11-23 13:05:50 +03:00
|
|
|
cmSystemTools::PutEnv(a);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2014-06-24 00:33:33 +04:00
|
|
|
// This is the beginning of the command.
|
|
|
|
break;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-06-24 00:33:33 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (ai == ae) {
|
2014-06-24 00:33:33 +04:00
|
|
|
std::cerr << "cmake -E env: no command given" << std::endl;
|
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-06-24 00:33:33 +04:00
|
|
|
|
|
|
|
// Execute command from remaining arguments.
|
|
|
|
std::vector<std::string> cmd(ai, ae);
|
|
|
|
int retval;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::RunSingleCommand(cmd, 0, 0, &retval, NULL,
|
|
|
|
cmSystemTools::OUTPUT_PASSTHROUGH)) {
|
2014-06-24 00:33:33 +04:00
|
|
|
return retval;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return 1;
|
|
|
|
}
|
2014-06-24 00:33:33 +04:00
|
|
|
|
2013-10-04 01:28:00 +04:00
|
|
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "environment") {
|
2013-10-04 01:28:00 +04:00
|
|
|
std::vector<std::string> env = cmSystemTools::GetEnvironmentVariables();
|
|
|
|
std::vector<std::string>::iterator it;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (it = env.begin(); it != env.end(); ++it) {
|
2014-03-11 16:35:32 +04:00
|
|
|
std::cout << *it << std::endl;
|
2013-10-04 01:28:00 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
#endif
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "make_directory" && args.size() > 2) {
|
2015-12-09 17:59:43 +03:00
|
|
|
// If error occurs we want to continue copying next files.
|
|
|
|
bool return_value = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::string::size_type cc = 2; cc < args.size(); cc++) {
|
|
|
|
if (!cmSystemTools::MakeDirectory(args[cc].c_str())) {
|
|
|
|
std::cerr << "Error creating directory \"" << args[cc] << "\".\n";
|
2015-12-09 17:59:43 +03:00
|
|
|
return_value = 1;
|
2013-10-04 01:28:00 +04:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return return_value;
|
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "remove_directory" && args.size() == 3) {
|
|
|
|
if (cmSystemTools::FileIsDirectory(args[2]) &&
|
|
|
|
!cmSystemTools::RemoveADirectory(args[2])) {
|
|
|
|
std::cerr << "Error removing directory \"" << args[2] << "\".\n";
|
2013-10-04 01:28:00 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
// Remove file
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "remove" && args.size() > 2) {
|
2013-10-04 01:28:00 +04:00
|
|
|
bool force = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::string::size_type cc = 2; cc < args.size(); cc++) {
|
|
|
|
if (args[cc] == "\\-f" || args[cc] == "-f") {
|
2013-10-04 01:28:00 +04:00
|
|
|
force = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2013-10-04 01:28:00 +04:00
|
|
|
// Complain if the file could not be removed, still exists,
|
|
|
|
// and the -f option was not given.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::RemoveFile(args[cc]) && !force &&
|
|
|
|
cmSystemTools::FileExists(args[cc].c_str())) {
|
2013-10-04 01:28:00 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
// Touch file
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "touch" && args.size() > 2) {
|
|
|
|
for (std::string::size_type cc = 2; cc < args.size(); cc++) {
|
|
|
|
if (!cmSystemTools::Touch(args[cc], true)) {
|
2013-10-04 01:28:00 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
// Touch file
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "touch_nocreate" && args.size() > 2) {
|
|
|
|
for (std::string::size_type cc = 2; cc < args.size(); cc++) {
|
2013-10-04 01:28:00 +04:00
|
|
|
// Complain if the file could not be removed, still exists,
|
|
|
|
// and the -f option was not given.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::Touch(args[cc], false)) {
|
2013-10-04 01:28:00 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
2014-01-21 22:48:30 +04:00
|
|
|
// Sleep command
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "sleep" && args.size() > 2) {
|
2014-01-21 22:48:30 +04:00
|
|
|
double total = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (size_t i = 2; i < args.size(); ++i) {
|
2014-01-21 22:48:30 +04:00
|
|
|
double num = 0.0;
|
|
|
|
char unit;
|
|
|
|
char extra;
|
|
|
|
int n = sscanf(args[i].c_str(), "%lg%c%c", &num, &unit, &extra);
|
2016-05-16 17:34:04 +03:00
|
|
|
if ((n == 1 || (n == 2 && unit == 's')) && num >= 0) {
|
2014-01-21 22:48:30 +04:00
|
|
|
total += num;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2014-01-21 22:48:30 +04:00
|
|
|
std::cerr << "Unknown sleep time format \"" << args[i] << "\".\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
if (total > 0) {
|
|
|
|
cmSystemTools::Delay(static_cast<unsigned int>(total * 1000));
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2014-01-21 22:48:30 +04:00
|
|
|
|
2013-10-04 01:28:00 +04:00
|
|
|
// Clock command
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "time" && args.size() > 2) {
|
|
|
|
std::vector<std::string> command(args.begin() + 2, args.end());
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
clock_t clock_start, clock_finish;
|
|
|
|
time_t time_start, time_finish;
|
|
|
|
|
|
|
|
time(&time_start);
|
|
|
|
clock_start = clock();
|
2016-05-16 17:34:04 +03:00
|
|
|
int ret = 0;
|
2016-01-20 16:45:55 +03:00
|
|
|
cmSystemTools::RunSingleCommand(command, 0, 0, &ret);
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
clock_finish = clock();
|
|
|
|
time(&time_finish);
|
|
|
|
|
|
|
|
double clocks_per_sec = static_cast<double>(CLOCKS_PER_SEC);
|
|
|
|
std::cout << "Elapsed time: "
|
2016-05-16 17:34:04 +03:00
|
|
|
<< static_cast<long>(time_finish - time_start) << " s. (time)"
|
|
|
|
<< ", "
|
|
|
|
<< static_cast<double>(clock_finish - clock_start) /
|
|
|
|
clocks_per_sec
|
|
|
|
<< " s. (clock)"
|
|
|
|
<< "\n";
|
2013-10-04 01:28:00 +04:00
|
|
|
return ret;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
// Command to calculate the md5sum of a file
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "md5sum" && args.size() >= 3) {
|
2013-10-04 01:28:00 +04:00
|
|
|
char md5out[32];
|
|
|
|
int retval = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::string::size_type cc = 2; cc < args.size(); cc++) {
|
|
|
|
const char* filename = args[cc].c_str();
|
2013-10-04 01:28:00 +04:00
|
|
|
// Cannot compute md5sum of a directory
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileIsDirectory(filename)) {
|
2013-10-04 01:28:00 +04:00
|
|
|
std::cerr << "Error: " << filename << " is a directory" << std::endl;
|
|
|
|
retval++;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (!cmSystemTools::ComputeFileMD5(filename, md5out)) {
|
2013-10-04 01:28:00 +04:00
|
|
|
// To mimic md5sum behavior in a shell:
|
|
|
|
std::cerr << filename << ": No such file or directory" << std::endl;
|
|
|
|
retval++;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
|
|
|
std::cout << std::string(md5out, 32) << " " << filename
|
|
|
|
<< std::endl;
|
2013-10-04 01:28:00 +04:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return retval;
|
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
// Command to change directory and run a program.
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "chdir" && args.size() >= 4) {
|
2013-10-04 01:28:00 +04:00
|
|
|
std::string directory = args[2];
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::FileExists(directory.c_str())) {
|
2013-10-04 01:28:00 +04:00
|
|
|
cmSystemTools::Error("Directory does not exist for chdir command: ",
|
|
|
|
args[2].c_str());
|
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
2015-07-18 11:45:18 +03:00
|
|
|
std::string command =
|
|
|
|
cmWrap('"', cmMakeRange(args).advance(3), '"', " ");
|
2013-10-04 01:28:00 +04:00
|
|
|
int retval = 0;
|
|
|
|
int timeout = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::RunSingleCommand(
|
|
|
|
command.c_str(), 0, 0, &retval, directory.c_str(),
|
|
|
|
cmSystemTools::OUTPUT_PASSTHROUGH, timeout)) {
|
2013-10-04 01:28:00 +04:00
|
|
|
return retval;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
// Command to start progress for a build
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "cmake_progress_start" && args.size() == 4) {
|
2013-10-04 01:28:00 +04:00
|
|
|
// basically remove the directory
|
|
|
|
std::string dirName = args[2];
|
|
|
|
dirName += "/Progress";
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::RemoveADirectory(dirName);
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
// is the last argument a filename that exists?
|
2016-05-16 17:34:04 +03:00
|
|
|
FILE* countFile = cmsys::SystemTools::Fopen(args[3], "r");
|
2013-10-04 01:28:00 +04:00
|
|
|
int count;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (countFile) {
|
|
|
|
if (1 != fscanf(countFile, "%i", &count)) {
|
2013-10-04 01:28:00 +04:00
|
|
|
cmSystemTools::Message("Could not read from count file.");
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
fclose(countFile);
|
|
|
|
} else {
|
2013-10-04 01:28:00 +04:00
|
|
|
count = atoi(args[3].c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (count) {
|
2013-10-04 01:28:00 +04:00
|
|
|
cmSystemTools::MakeDirectory(dirName.c_str());
|
|
|
|
// write the count into the directory
|
|
|
|
std::string fName = dirName;
|
|
|
|
fName += "/count.txt";
|
2016-05-16 17:34:04 +03:00
|
|
|
FILE* progFile = cmsys::SystemTools::Fopen(fName, "w");
|
|
|
|
if (progFile) {
|
|
|
|
fprintf(progFile, "%i\n", count);
|
2013-10-04 01:28:00 +04:00
|
|
|
fclose(progFile);
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
// Command to report progress for a build
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "cmake_progress_report" && args.size() >= 3) {
|
2015-02-06 00:48:16 +03:00
|
|
|
// This has been superseded by cmake_echo_color --progress-*
|
|
|
|
// options. We leave it here to avoid errors if somehow this
|
|
|
|
// is invoked by an existing makefile without regenerating.
|
2013-10-04 01:28:00 +04:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
// Command to create a symbolic link. Fails on platforms not
|
|
|
|
// supporting them.
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "create_symlink" && args.size() == 4) {
|
2013-10-04 01:28:00 +04:00
|
|
|
const char* destinationFileName = args[3].c_str();
|
2016-05-16 17:34:04 +03:00
|
|
|
if ((cmSystemTools::FileExists(destinationFileName) ||
|
|
|
|
cmSystemTools::FileIsSymlink(destinationFileName)) &&
|
|
|
|
!cmSystemTools::RemoveFile(destinationFileName)) {
|
2014-01-20 22:50:31 +04:00
|
|
|
std::string emsg = cmSystemTools::GetLastSystemError();
|
2016-05-16 17:34:04 +03:00
|
|
|
std::cerr << "failed to create symbolic link '" << destinationFileName
|
|
|
|
<< "' because existing path cannot be removed: " << emsg
|
|
|
|
<< "\n";
|
2014-01-20 22:50:31 +04:00
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!cmSystemTools::CreateSymlink(args[2], args[3])) {
|
2014-01-20 22:50:31 +04:00
|
|
|
std::string emsg = cmSystemTools::GetLastSystemError();
|
2016-05-16 17:34:04 +03:00
|
|
|
std::cerr << "failed to create symbolic link '" << destinationFileName
|
|
|
|
<< "': " << emsg << "\n";
|
2014-01-20 22:50:31 +04:00
|
|
|
return 1;
|
2013-10-04 01:28:00 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
// Internal CMake shared library support.
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "cmake_symlink_library" && args.size() == 5) {
|
2013-10-04 01:28:00 +04:00
|
|
|
return cmcmd::SymlinkLibrary(args);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
// Internal CMake versioned executable support.
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "cmake_symlink_executable" && args.size() == 4) {
|
2013-10-04 01:28:00 +04:00
|
|
|
return cmcmd::SymlinkExecutable(args);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
#if defined(CMAKE_HAVE_VS_GENERATORS)
|
|
|
|
// Internal CMake support for calling Visual Studio macros.
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "cmake_call_visual_studio_macro" && args.size() >= 4) {
|
2013-10-04 01:28:00 +04:00
|
|
|
// args[2] = full path to .sln file or "ALL"
|
|
|
|
// args[3] = name of Visual Studio macro to call
|
|
|
|
// args[4..args.size()-1] = [optional] args for Visual Studio macro
|
|
|
|
|
|
|
|
std::string macroArgs;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args.size() > 4) {
|
2013-10-04 01:28:00 +04:00
|
|
|
macroArgs = args[4];
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
for (size_t i = 5; i < args.size(); ++i) {
|
2013-10-04 01:28:00 +04:00
|
|
|
macroArgs += " ";
|
|
|
|
macroArgs += args[i];
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
|
|
|
|
return cmCallVisualStudioMacro::CallMacro(args[2], args[3], macroArgs,
|
|
|
|
true);
|
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Internal CMake dependency scanning support.
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "cmake_depends" && args.size() >= 6) {
|
2013-10-04 01:28:00 +04:00
|
|
|
// Use the make system's VERBOSE environment variable to enable
|
|
|
|
// verbose output. This can be skipped by also setting CMAKE_NO_VERBOSE
|
|
|
|
// (which is set by the Eclipse and KDevelop generators).
|
2016-05-16 17:34:04 +03:00
|
|
|
bool verbose = ((cmSystemTools::GetEnv("VERBOSE") != 0) &&
|
|
|
|
(cmSystemTools::GetEnv("CMAKE_NO_VERBOSE") == 0));
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
// Create a cmake object instance to process dependencies.
|
|
|
|
cmake cm;
|
|
|
|
std::string gen;
|
|
|
|
std::string homeDir;
|
|
|
|
std::string startDir;
|
|
|
|
std::string homeOutDir;
|
|
|
|
std::string startOutDir;
|
|
|
|
std::string depInfo;
|
|
|
|
bool color = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args.size() >= 8) {
|
2013-10-04 01:28:00 +04:00
|
|
|
// Full signature:
|
|
|
|
//
|
|
|
|
// -E cmake_depends <generator>
|
|
|
|
// <home-src-dir> <start-src-dir>
|
|
|
|
// <home-out-dir> <start-out-dir>
|
|
|
|
// <dep-info> [--color=$(COLOR)]
|
|
|
|
//
|
|
|
|
// All paths are provided.
|
|
|
|
gen = args[2];
|
|
|
|
homeDir = args[3];
|
|
|
|
startDir = args[4];
|
|
|
|
homeOutDir = args[5];
|
|
|
|
startOutDir = args[6];
|
|
|
|
depInfo = args[7];
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args.size() >= 9 && args[8].length() >= 8 &&
|
|
|
|
args[8].substr(0, 8) == "--color=") {
|
2013-10-04 01:28:00 +04:00
|
|
|
// Enable or disable color based on the switch value.
|
|
|
|
color = (args[8].size() == 8 ||
|
|
|
|
cmSystemTools::IsOn(args[8].substr(8).c_str()));
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2013-10-04 01:28:00 +04:00
|
|
|
// Support older signature for existing makefiles:
|
|
|
|
//
|
|
|
|
// -E cmake_depends <generator>
|
|
|
|
// <home-out-dir> <start-out-dir>
|
|
|
|
// <dep-info>
|
|
|
|
//
|
|
|
|
// Just pretend the source directories are the same as the
|
|
|
|
// binary directories so at least scanning will work.
|
|
|
|
gen = args[2];
|
|
|
|
homeDir = args[3];
|
|
|
|
startDir = args[4];
|
|
|
|
homeOutDir = args[3];
|
|
|
|
startOutDir = args[3];
|
|
|
|
depInfo = args[5];
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
// Create a local generator configured for the directory in
|
|
|
|
// which dependencies will be scanned.
|
2014-10-15 16:54:05 +04:00
|
|
|
homeDir = cmSystemTools::CollapseFullPath(homeDir);
|
|
|
|
startDir = cmSystemTools::CollapseFullPath(startDir);
|
|
|
|
homeOutDir = cmSystemTools::CollapseFullPath(homeOutDir);
|
|
|
|
startOutDir = cmSystemTools::CollapseFullPath(startOutDir);
|
2014-03-11 03:04:11 +04:00
|
|
|
cm.SetHomeDirectory(homeDir);
|
|
|
|
cm.SetHomeOutputDirectory(homeOutDir);
|
2015-10-13 22:48:46 +03:00
|
|
|
cm.GetCurrentSnapshot().SetDefaultDefinitions();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmGlobalGenerator* ggd = cm.CreateGlobalGenerator(gen)) {
|
2013-10-04 01:28:00 +04:00
|
|
|
cm.SetGlobalGenerator(ggd);
|
2015-05-31 02:43:31 +03:00
|
|
|
cmState::Snapshot snapshot = cm.GetCurrentSnapshot();
|
2016-02-05 16:55:15 +03:00
|
|
|
snapshot.GetDirectory().SetCurrentBinary(startOutDir);
|
|
|
|
snapshot.GetDirectory().SetCurrentSource(startDir);
|
2015-08-02 12:41:51 +03:00
|
|
|
cmsys::auto_ptr<cmMakefile> mf(new cmMakefile(ggd, snapshot));
|
2015-05-31 02:43:31 +03:00
|
|
|
cmsys::auto_ptr<cmLocalGenerator> lgd(
|
2016-05-16 17:34:04 +03:00
|
|
|
ggd->CreateLocalGenerator(mf.get()));
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
// Actually scan dependencies.
|
2016-05-16 17:34:04 +03:00
|
|
|
return lgd->UpdateDependencies(depInfo.c_str(), verbose, color) ? 0
|
|
|
|
: 2;
|
2013-10-04 01:28:00 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return 1;
|
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
// Internal CMake link script support.
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "cmake_link_script" && args.size() >= 3) {
|
2013-10-04 01:28:00 +04:00
|
|
|
return cmcmd::ExecuteLinkScript(args);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
// Internal CMake unimplemented feature notification.
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "cmake_unimplemented_variable") {
|
2013-10-04 01:28:00 +04:00
|
|
|
std::cerr << "Feature not implemented for this platform.";
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args.size() == 3) {
|
2013-10-04 01:28:00 +04:00
|
|
|
std::cerr << " Variable " << args[2] << " is not set.";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
std::cerr << std::endl;
|
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (args[1] == "vs_link_exe") {
|
2013-10-04 01:28:00 +04:00
|
|
|
return cmcmd::VisualStudioLink(args, 1);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (args[1] == "vs_link_dll") {
|
2013-10-04 01:28:00 +04:00
|
|
|
return cmcmd::VisualStudioLink(args, 2);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
// Internal CMake color makefile support.
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "cmake_echo_color") {
|
2013-10-04 01:28:00 +04:00
|
|
|
return cmcmd::ExecuteEchoColor(args);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-02-06 00:29:59 +03:00
|
|
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "cmake_autogen" && args.size() >= 4) {
|
|
|
|
cmQtAutoGenerators autogen;
|
|
|
|
std::string const& config = args[3];
|
|
|
|
bool autogenSuccess = autogen.Run(args[2], config);
|
|
|
|
return autogenSuccess ? 0 : 1;
|
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Tar files
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "tar" && args.size() > 3) {
|
|
|
|
const char* knownFormats[] = { "7zip", "gnutar", "pax", "paxr", "zip" };
|
2015-04-07 13:36:52 +03:00
|
|
|
|
2013-10-04 01:28:00 +04:00
|
|
|
std::string flags = args[2];
|
|
|
|
std::string outFile = args[3];
|
2014-02-10 09:21:34 +04:00
|
|
|
std::vector<std::string> files;
|
2015-01-14 21:22:29 +03:00
|
|
|
std::string mtime;
|
2015-04-07 13:36:52 +03:00
|
|
|
std::string format;
|
2015-01-14 21:22:29 +03:00
|
|
|
bool doing_options = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::string::size_type cc = 4; cc < args.size(); cc++) {
|
2015-01-14 21:22:29 +03:00
|
|
|
std::string const& arg = args[cc];
|
2016-05-16 17:34:04 +03:00
|
|
|
if (doing_options && cmHasLiteralPrefix(arg, "--")) {
|
|
|
|
if (arg == "--") {
|
2015-01-14 21:22:29 +03:00
|
|
|
doing_options = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (cmHasLiteralPrefix(arg, "--mtime=")) {
|
2015-01-14 21:22:29 +03:00
|
|
|
mtime = arg.substr(8);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (cmHasLiteralPrefix(arg, "--files-from=")) {
|
2015-01-26 21:28:31 +03:00
|
|
|
std::string const& files_from = arg.substr(13);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmTarFilesFrom(files_from, files)) {
|
2015-01-26 21:28:31 +03:00
|
|
|
return 1;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (cmHasLiteralPrefix(arg, "--format=")) {
|
2015-04-07 13:36:52 +03:00
|
|
|
format = arg.substr(9);
|
2016-05-16 17:34:04 +03:00
|
|
|
bool isKnown =
|
|
|
|
std::find(cmArrayBegin(knownFormats), cmArrayEnd(knownFormats),
|
|
|
|
format) != cmArrayEnd(knownFormats);
|
2015-04-07 13:36:52 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!isKnown) {
|
2015-04-07 13:36:52 +03:00
|
|
|
cmSystemTools::Error("Unknown -E tar --format= argument: ",
|
2016-05-16 17:34:04 +03:00
|
|
|
format.c_str());
|
2015-04-07 13:36:52 +03:00
|
|
|
return 1;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-01-14 21:22:29 +03:00
|
|
|
cmSystemTools::Error("Unknown option to -E tar: ", arg.c_str());
|
|
|
|
return 1;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-01-14 21:22:29 +03:00
|
|
|
files.push_back(arg);
|
2013-10-04 01:28:00 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-01-09 18:33:00 +03:00
|
|
|
cmSystemTools::cmTarCompression compress =
|
|
|
|
cmSystemTools::TarCompressNone;
|
2013-10-04 01:28:00 +04:00
|
|
|
bool verbose = false;
|
2015-01-09 18:33:36 +03:00
|
|
|
int nCompress = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (flags.find_first_of('j') != flags.npos) {
|
2015-01-09 18:33:00 +03:00
|
|
|
compress = cmSystemTools::TarCompressBZip2;
|
2015-01-09 18:33:36 +03:00
|
|
|
++nCompress;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (flags.find_first_of('J') != flags.npos) {
|
2015-01-09 18:33:00 +03:00
|
|
|
compress = cmSystemTools::TarCompressXZ;
|
2015-01-09 18:33:36 +03:00
|
|
|
++nCompress;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (flags.find_first_of('z') != flags.npos) {
|
2015-01-09 18:33:00 +03:00
|
|
|
compress = cmSystemTools::TarCompressGZip;
|
2015-01-09 18:33:36 +03:00
|
|
|
++nCompress;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if ((format == "7zip" || format == "zip") && nCompress > 0) {
|
2015-04-07 13:36:52 +03:00
|
|
|
cmSystemTools::Error("Can not use compression flags with format: ",
|
2016-05-16 17:34:04 +03:00
|
|
|
format.c_str());
|
2015-04-07 13:36:52 +03:00
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (nCompress > 1) {
|
2015-01-09 18:33:36 +03:00
|
|
|
cmSystemTools::Error("Can only compress a tar file one way; "
|
|
|
|
"at most one flag of z, j, or J may be used");
|
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (flags.find_first_of('v') != flags.npos) {
|
2013-10-04 01:28:00 +04:00
|
|
|
verbose = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (flags.find_first_of('t') != flags.npos) {
|
|
|
|
if (!cmSystemTools::ListTar(outFile.c_str(), verbose)) {
|
2015-01-05 21:53:53 +03:00
|
|
|
cmSystemTools::Error("Problem listing tar: ", outFile.c_str());
|
2013-10-04 01:28:00 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (flags.find_first_of('c') != flags.npos) {
|
|
|
|
if (!cmSystemTools::CreateTar(outFile.c_str(), files, compress,
|
|
|
|
verbose, mtime, format)) {
|
2013-10-04 01:28:00 +04:00
|
|
|
cmSystemTools::Error("Problem creating tar: ", outFile.c_str());
|
|
|
|
return 1;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (flags.find_first_of('x') != flags.npos) {
|
|
|
|
if (!cmSystemTools::ExtractTar(outFile.c_str(), verbose)) {
|
2013-10-04 01:28:00 +04:00
|
|
|
cmSystemTools::Error("Problem extracting tar: ", outFile.c_str());
|
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
#ifdef WIN32
|
|
|
|
// OK, on windows 7 after we untar some files,
|
|
|
|
// sometimes we can not rename the directory after
|
|
|
|
// the untar is done. This breaks the external project
|
|
|
|
// untar and rename code. So, by default we will wait
|
|
|
|
// 1/10th of a second after the untar. If CMAKE_UNTAR_DELAY
|
|
|
|
// is set in the env, its value will be used instead of 100.
|
|
|
|
int delay = 100;
|
|
|
|
const char* delayVar = cmSystemTools::GetEnv("CMAKE_UNTAR_DELAY");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (delayVar) {
|
2013-10-04 01:28:00 +04:00
|
|
|
delay = atoi(delayVar);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (delay) {
|
2013-10-04 01:28:00 +04:00
|
|
|
cmSystemTools::Delay(delay);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
#endif
|
2013-10-04 01:28:00 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
|
|
|
// Internal CMake Fortran module support.
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "cmake_copy_f90_mod" && args.size() >= 4) {
|
|
|
|
return cmDependsFortran::CopyModule(args) ? 0 : 1;
|
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
|
// Write registry value
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "write_regv" && args.size() > 3) {
|
2013-10-04 01:28:00 +04:00
|
|
|
return cmSystemTools::WriteRegistryValue(args[2].c_str(),
|
2016-05-16 17:34:04 +03:00
|
|
|
args[3].c_str())
|
|
|
|
? 0
|
|
|
|
: 1;
|
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
// Delete registry value
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "delete_regv" && args.size() > 2) {
|
2013-10-04 01:28:00 +04:00
|
|
|
return cmSystemTools::DeleteRegistryValue(args[2].c_str()) ? 0 : 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
// Remove file
|
2016-05-16 17:34:04 +03:00
|
|
|
else if (args[1] == "comspec" && args.size() > 2) {
|
2013-10-18 23:37:09 +04:00
|
|
|
std::cerr << "Win9x helper \"cmake -E comspec\" no longer supported\n";
|
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (args[1] == "env_vs8_wince" && args.size() == 3) {
|
2013-10-04 01:28:00 +04:00
|
|
|
return cmcmd::WindowsCEEnvironment("8.0", args[2]);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (args[1] == "env_vs9_wince" && args.size() == 3) {
|
2013-10-04 01:28:00 +04:00
|
|
|
return cmcmd::WindowsCEEnvironment("9.0", args[2]);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
#endif
|
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
::CMakeCommandUsage(args[0].c_str());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cmcmd::SymlinkLibrary(std::vector<std::string>& args)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
std::string realName = args[2];
|
|
|
|
std::string soName = args[3];
|
|
|
|
std::string name = args[4];
|
2016-05-16 17:34:04 +03:00
|
|
|
if (soName != realName) {
|
|
|
|
if (!cmcmd::SymlinkInternal(realName, soName)) {
|
2013-10-04 01:28:00 +04:00
|
|
|
cmSystemTools::ReportLastSystemError("cmake_symlink_library");
|
|
|
|
result = 1;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (name != soName) {
|
|
|
|
if (!cmcmd::SymlinkInternal(soName, name)) {
|
2013-10-04 01:28:00 +04:00
|
|
|
cmSystemTools::ReportLastSystemError("cmake_symlink_library");
|
|
|
|
result = 1;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cmcmd::SymlinkExecutable(std::vector<std::string>& args)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
std::string realName = args[2];
|
|
|
|
std::string name = args[3];
|
2016-05-16 17:34:04 +03:00
|
|
|
if (name != realName) {
|
|
|
|
if (!cmcmd::SymlinkInternal(realName, name)) {
|
2013-10-04 01:28:00 +04:00
|
|
|
cmSystemTools::ReportLastSystemError("cmake_symlink_executable");
|
|
|
|
result = 1;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cmcmd::SymlinkInternal(std::string const& file, std::string const& link)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileExists(link.c_str()) ||
|
|
|
|
cmSystemTools::FileIsSymlink(link)) {
|
2014-10-15 16:54:05 +04:00
|
|
|
cmSystemTools::RemoveFile(link);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
|
return cmSystemTools::CopyFileAlways(file.c_str(), link.c_str());
|
|
|
|
#else
|
|
|
|
std::string linktext = cmSystemTools::GetFilenameName(file);
|
2014-11-23 13:05:50 +03:00
|
|
|
return cmSystemTools::CreateSymlink(linktext, link);
|
2013-10-04 01:28:00 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
static void cmcmdProgressReport(std::string const& dir, std::string const& num)
|
2015-02-06 00:48:16 +03:00
|
|
|
{
|
|
|
|
std::string dirName = dir;
|
|
|
|
dirName += "/Progress";
|
|
|
|
std::string fName;
|
2016-05-16 17:34:04 +03:00
|
|
|
FILE* progFile;
|
2015-02-06 00:48:16 +03:00
|
|
|
|
|
|
|
// read the count
|
|
|
|
fName = dirName;
|
|
|
|
fName += "/count.txt";
|
2016-05-16 17:34:04 +03:00
|
|
|
progFile = cmsys::SystemTools::Fopen(fName, "r");
|
2015-02-06 00:48:16 +03:00
|
|
|
int count = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!progFile) {
|
2015-02-06 00:48:16 +03:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
|
|
|
if (1 != fscanf(progFile, "%i", &count)) {
|
2015-02-06 00:48:16 +03:00
|
|
|
cmSystemTools::Message("Could not read from progress file.");
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
fclose(progFile);
|
|
|
|
}
|
2015-02-06 00:48:16 +03:00
|
|
|
const char* last = num.c_str();
|
2016-05-16 17:34:04 +03:00
|
|
|
for (const char* c = last;; ++c) {
|
|
|
|
if (*c == ',' || *c == '\0') {
|
|
|
|
if (c != last) {
|
2015-02-06 00:48:16 +03:00
|
|
|
fName = dirName;
|
|
|
|
fName += "/";
|
2016-05-16 17:34:04 +03:00
|
|
|
fName.append(last, c - last);
|
|
|
|
progFile = cmsys::SystemTools::Fopen(fName, "w");
|
|
|
|
if (progFile) {
|
|
|
|
fprintf(progFile, "empty");
|
2015-02-06 00:48:16 +03:00
|
|
|
fclose(progFile);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (*c == '\0') {
|
2015-02-06 00:48:16 +03:00
|
|
|
break;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
last = c + 1;
|
2015-02-06 00:48:16 +03:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
int fileNum =
|
|
|
|
static_cast<int>(cmsys::Directory::GetNumberOfFilesInDirectory(dirName));
|
|
|
|
if (count > 0) {
|
2015-02-06 00:48:16 +03:00
|
|
|
// print the progress
|
2016-05-16 17:34:04 +03:00
|
|
|
fprintf(stdout, "[%3i%%] ", ((fileNum - 3) * 100) / count);
|
|
|
|
}
|
2015-02-06 00:48:16 +03:00
|
|
|
}
|
|
|
|
|
2013-10-04 01:28:00 +04:00
|
|
|
int cmcmd::ExecuteEchoColor(std::vector<std::string>& args)
|
|
|
|
{
|
|
|
|
// The arguments are
|
|
|
|
// argv[0] == <cmake-executable>
|
|
|
|
// argv[1] == cmake_echo_color
|
|
|
|
|
|
|
|
bool enabled = true;
|
|
|
|
int color = cmsysTerminal_Color_Normal;
|
|
|
|
bool newline = true;
|
2015-02-06 00:48:16 +03:00
|
|
|
std::string progressDir;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (unsigned int i = 2; i < args.size(); ++i) {
|
|
|
|
if (args[i].find("--switch=") == 0) {
|
2013-10-04 01:28:00 +04:00
|
|
|
// Enable or disable color based on the switch value.
|
|
|
|
std::string value = args[i].substr(9);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!value.empty()) {
|
|
|
|
if (cmSystemTools::IsOn(value.c_str())) {
|
2013-10-04 01:28:00 +04:00
|
|
|
enabled = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2013-10-04 01:28:00 +04:00
|
|
|
enabled = false;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (cmHasLiteralPrefix(args[i], "--progress-dir=")) {
|
2015-02-06 00:48:16 +03:00
|
|
|
progressDir = args[i].substr(15);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (cmHasLiteralPrefix(args[i], "--progress-num=")) {
|
|
|
|
if (!progressDir.empty()) {
|
2015-02-06 00:48:16 +03:00
|
|
|
std::string const& progressNum = args[i].substr(15);
|
|
|
|
cmcmdProgressReport(progressDir, progressNum);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (args[i] == "--normal") {
|
2013-10-04 01:28:00 +04:00
|
|
|
color = cmsysTerminal_Color_Normal;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (args[i] == "--black") {
|
2013-10-04 01:28:00 +04:00
|
|
|
color = cmsysTerminal_Color_ForegroundBlack;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (args[i] == "--red") {
|
2013-10-04 01:28:00 +04:00
|
|
|
color = cmsysTerminal_Color_ForegroundRed;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (args[i] == "--green") {
|
2013-10-04 01:28:00 +04:00
|
|
|
color = cmsysTerminal_Color_ForegroundGreen;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (args[i] == "--yellow") {
|
2013-10-04 01:28:00 +04:00
|
|
|
color = cmsysTerminal_Color_ForegroundYellow;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (args[i] == "--blue") {
|
2013-10-04 01:28:00 +04:00
|
|
|
color = cmsysTerminal_Color_ForegroundBlue;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (args[i] == "--magenta") {
|
2013-10-04 01:28:00 +04:00
|
|
|
color = cmsysTerminal_Color_ForegroundMagenta;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (args[i] == "--cyan") {
|
2013-10-04 01:28:00 +04:00
|
|
|
color = cmsysTerminal_Color_ForegroundCyan;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (args[i] == "--white") {
|
2013-10-04 01:28:00 +04:00
|
|
|
color = cmsysTerminal_Color_ForegroundWhite;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (args[i] == "--bold") {
|
2013-10-04 01:28:00 +04:00
|
|
|
color |= cmsysTerminal_Color_ForegroundBold;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (args[i] == "--no-newline") {
|
2013-10-04 01:28:00 +04:00
|
|
|
newline = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (args[i] == "--newline") {
|
2013-10-04 01:28:00 +04:00
|
|
|
newline = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2013-10-04 01:28:00 +04:00
|
|
|
// Color is enabled. Print with the current color.
|
2016-05-16 17:34:04 +03:00
|
|
|
cmSystemTools::MakefileColorEcho(color, args[i].c_str(), newline,
|
|
|
|
enabled);
|
2013-10-04 01:28:00 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cmcmd::ExecuteLinkScript(std::vector<std::string>& args)
|
|
|
|
{
|
|
|
|
// The arguments are
|
|
|
|
// argv[0] == <cmake-executable>
|
|
|
|
// argv[1] == cmake_link_script
|
|
|
|
// argv[2] == <link-script-name>
|
|
|
|
// argv[3] == --verbose=?
|
|
|
|
bool verbose = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args.size() >= 4) {
|
|
|
|
if (args[3].find("--verbose=") == 0) {
|
|
|
|
if (!cmSystemTools::IsOff(args[3].substr(10).c_str())) {
|
2013-10-04 01:28:00 +04:00
|
|
|
verbose = true;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
// Allocate a process instance.
|
|
|
|
cmsysProcess* cp = cmsysProcess_New();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cp) {
|
2013-10-04 01:28:00 +04:00
|
|
|
std::cerr << "Error allocating process instance in link script."
|
|
|
|
<< std::endl;
|
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
// Children should share stdout and stderr with this process.
|
|
|
|
cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDOUT, 1);
|
|
|
|
cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDERR, 1);
|
|
|
|
|
|
|
|
// Run the command lines verbatim.
|
|
|
|
cmsysProcess_SetOption(cp, cmsysProcess_Option_Verbatim, 1);
|
|
|
|
|
|
|
|
// Read command lines from the script.
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ifstream fin(args[2].c_str());
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!fin) {
|
|
|
|
std::cerr << "Error opening link script \"" << args[2] << "\""
|
|
|
|
<< std::endl;
|
2013-10-04 01:28:00 +04:00
|
|
|
return 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
// Run one command at a time.
|
|
|
|
std::string command;
|
|
|
|
int result = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (result == 0 && cmSystemTools::GetLineFromStream(fin, command)) {
|
2013-10-04 01:28:00 +04:00
|
|
|
// Skip empty command lines.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (command.find_first_not_of(" \t") == command.npos) {
|
2013-10-04 01:28:00 +04:00
|
|
|
continue;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
// Setup this command line.
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* cmd[2] = { command.c_str(), 0 };
|
2013-10-04 01:28:00 +04:00
|
|
|
cmsysProcess_SetCommand(cp, cmd);
|
|
|
|
|
|
|
|
// Report the command if verbose output is enabled.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (verbose) {
|
2013-10-04 01:28:00 +04:00
|
|
|
std::cout << command << std::endl;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
// Run the command and wait for it to exit.
|
|
|
|
cmsysProcess_Execute(cp);
|
|
|
|
cmsysProcess_WaitForExit(cp, 0);
|
|
|
|
|
|
|
|
// Report failure if any.
|
2016-05-16 17:34:04 +03:00
|
|
|
switch (cmsysProcess_GetState(cp)) {
|
|
|
|
case cmsysProcess_State_Exited: {
|
2013-10-04 01:28:00 +04:00
|
|
|
int value = cmsysProcess_GetExitValue(cp);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (value != 0) {
|
2013-10-04 01:28:00 +04:00
|
|
|
result = value;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} break;
|
2013-10-04 01:28:00 +04:00
|
|
|
case cmsysProcess_State_Exception:
|
|
|
|
std::cerr << "Error running link command: "
|
|
|
|
<< cmsysProcess_GetExceptionString(cp) << std::endl;
|
|
|
|
result = 1;
|
|
|
|
break;
|
|
|
|
case cmsysProcess_State_Error:
|
|
|
|
std::cerr << "Error running link command: "
|
|
|
|
<< cmsysProcess_GetErrorString(cp) << std::endl;
|
|
|
|
result = 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2016-05-16 17:34:04 +03:00
|
|
|
};
|
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
|
|
|
// Free the process instance.
|
|
|
|
cmsysProcess_Delete(cp);
|
|
|
|
|
|
|
|
// Return the final resulting return value.
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cmcmd::WindowsCEEnvironment(const char* version, const std::string& name)
|
|
|
|
{
|
|
|
|
#if defined(CMAKE_HAVE_VS_GENERATORS)
|
|
|
|
cmVisualStudioWCEPlatformParser parser(name.c_str());
|
|
|
|
parser.ParseVersion(version);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (parser.Found()) {
|
2013-10-04 01:28:00 +04:00
|
|
|
std::cout << "@echo off" << std::endl;
|
|
|
|
std::cout << "echo Environment Selection: " << name << std::endl;
|
|
|
|
std::cout << "set PATH=" << parser.GetPathDirectories() << std::endl;
|
2016-05-16 17:34:04 +03:00
|
|
|
std::cout << "set INCLUDE=" << parser.GetIncludeDirectories() << std::endl;
|
|
|
|
std::cout << "set LIB=" << parser.GetLibraryDirectories() << std::endl;
|
2013-10-04 01:28:00 +04:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
#else
|
|
|
|
(void)version;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
std::cerr << "Could not find " << name;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-09-15 22:51:19 +03:00
|
|
|
class cmVSLink
|
|
|
|
{
|
|
|
|
int Type;
|
|
|
|
bool Verbose;
|
|
|
|
bool Incremental;
|
|
|
|
bool LinkGeneratesManifest;
|
|
|
|
std::vector<std::string> LinkCommand;
|
2015-09-16 17:24:16 +03:00
|
|
|
std::vector<std::string> UserManifests;
|
2015-09-15 22:51:19 +03:00
|
|
|
std::string LinkerManifestFile;
|
|
|
|
std::string ManifestFile;
|
|
|
|
std::string ManifestFileRC;
|
|
|
|
std::string ManifestFileRes;
|
|
|
|
std::string TargetFile;
|
2016-05-16 17:34:04 +03:00
|
|
|
|
2015-09-15 22:51:19 +03:00
|
|
|
public:
|
|
|
|
cmVSLink(int type, bool verbose)
|
|
|
|
: Type(type)
|
|
|
|
, Verbose(verbose)
|
|
|
|
, Incremental(false)
|
|
|
|
, LinkGeneratesManifest(true)
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
}
|
2015-09-15 22:51:19 +03:00
|
|
|
bool Parse(std::vector<std::string>::const_iterator argBeg,
|
|
|
|
std::vector<std::string>::const_iterator argEnd);
|
|
|
|
int Link();
|
2016-05-16 17:34:04 +03:00
|
|
|
|
2015-09-15 22:51:19 +03:00
|
|
|
private:
|
|
|
|
int LinkIncremental();
|
|
|
|
int LinkNonIncremental();
|
|
|
|
int RunMT(std::string const& out, bool notify);
|
|
|
|
};
|
|
|
|
|
2013-10-04 01:28:00 +04:00
|
|
|
// For visual studio 2005 and newer manifest files need to be embedded into
|
|
|
|
// exe and dll's. This code does that in such a way that incremental linking
|
|
|
|
// still works.
|
|
|
|
int cmcmd::VisualStudioLink(std::vector<std::string>& args, int type)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args.size() < 2) {
|
2013-10-04 01:28:00 +04:00
|
|
|
return -1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
bool verbose = cmSystemTools::GetEnv("VERBOSE") ? true : false;
|
2013-10-04 01:28:00 +04:00
|
|
|
std::vector<std::string> expandedArgs;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (std::vector<std::string>::iterator i = args.begin(); i != args.end();
|
|
|
|
++i) {
|
2013-10-04 01:28:00 +04:00
|
|
|
// check for nmake temporary files
|
2016-05-16 17:34:04 +03:00
|
|
|
if ((*i)[0] == '@' && i->find("@CMakeFiles") != 0) {
|
2014-01-04 09:47:13 +04:00
|
|
|
cmsys::ifstream fin(i->substr(1).c_str());
|
2013-10-04 01:28:00 +04:00
|
|
|
std::string line;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (cmSystemTools::GetLineFromStream(fin, line)) {
|
2013-10-04 01:28:00 +04:00
|
|
|
cmSystemTools::ParseWindowsCommandLine(line.c_str(), expandedArgs);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2013-10-04 01:28:00 +04:00
|
|
|
expandedArgs.push_back(*i);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
|
2015-09-15 22:51:19 +03:00
|
|
|
cmVSLink vsLink(type, verbose);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!vsLink.Parse(expandedArgs.begin() + 2, expandedArgs.end())) {
|
2013-10-04 01:28:00 +04:00
|
|
|
return -1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-15 22:51:19 +03:00
|
|
|
return vsLink.Link();
|
2013-10-04 01:28:00 +04:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
static bool RunCommand(const char* comment, std::vector<std::string>& command,
|
|
|
|
bool verbose, int* retCodeOut = 0)
|
2013-10-04 01:28:00 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (verbose) {
|
2013-10-04 01:28:00 +04:00
|
|
|
std::cout << comment << ":\n";
|
2015-02-12 22:53:43 +03:00
|
|
|
std::cout << cmJoin(command, " ") << "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
std::string output;
|
2016-05-16 17:34:04 +03:00
|
|
|
int retCode = 0;
|
2013-10-04 01:28:00 +04:00
|
|
|
// use rc command to create .res file
|
2016-05-16 17:34:04 +03:00
|
|
|
bool res = cmSystemTools::RunSingleCommand(
|
|
|
|
command, &output, &output, &retCode, 0, cmSystemTools::OUTPUT_NONE);
|
2013-10-04 01:28:00 +04:00
|
|
|
// always print the output of the command, unless
|
|
|
|
// it is the dumb rc command banner, but if the command
|
|
|
|
// returned an error code then print the output anyway as
|
|
|
|
// the banner may be mixed with some other important information.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (output.find("Resource Compiler Version") == output.npos || !res ||
|
|
|
|
retCode) {
|
2013-10-04 01:28:00 +04:00
|
|
|
std::cout << output;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!res) {
|
2015-08-08 08:06:27 +03:00
|
|
|
std::cout << comment << " failed to run." << std::endl;
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
// if retCodeOut is requested then always return true
|
|
|
|
// and set the retCodeOut to retCode
|
2016-05-16 17:34:04 +03:00
|
|
|
if (retCodeOut) {
|
2013-10-04 01:28:00 +04:00
|
|
|
*retCodeOut = retCode;
|
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (retCode != 0) {
|
2013-10-04 01:28:00 +04:00
|
|
|
std::cout << comment << " failed. with " << retCode << "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
return retCode == 0;
|
|
|
|
}
|
|
|
|
|
2015-09-15 22:51:19 +03:00
|
|
|
bool cmVSLink::Parse(std::vector<std::string>::const_iterator argBeg,
|
|
|
|
std::vector<std::string>::const_iterator argEnd)
|
|
|
|
{
|
|
|
|
// Parse our own arguments.
|
|
|
|
std::string intDir;
|
|
|
|
std::vector<std::string>::const_iterator arg = argBeg;
|
2016-05-16 17:34:04 +03:00
|
|
|
while (arg != argEnd && cmHasLiteralPrefix(*arg, "-")) {
|
|
|
|
if (*arg == "--") {
|
2015-09-15 22:51:19 +03:00
|
|
|
++arg;
|
|
|
|
break;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (*arg == "--manifests") {
|
|
|
|
for (++arg; arg != argEnd && !cmHasLiteralPrefix(*arg, "-"); ++arg) {
|
2015-09-16 17:24:16 +03:00
|
|
|
this->UserManifests.push_back(*arg);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (cmHasLiteralPrefix(*arg, "--intdir=")) {
|
2015-09-15 22:51:19 +03:00
|
|
|
intDir = arg->substr(9);
|
|
|
|
++arg;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-09-15 22:51:19 +03:00
|
|
|
std::cerr << "unknown argument '" << *arg << "'\n";
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (intDir.empty()) {
|
2015-09-15 22:51:19 +03:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-15 22:51:19 +03:00
|
|
|
|
|
|
|
// The rest of the arguments form the link command.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (arg == argEnd) {
|
2015-09-15 22:51:19 +03:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-15 22:51:19 +03:00
|
|
|
this->LinkCommand.insert(this->LinkCommand.begin(), arg, argEnd);
|
|
|
|
|
|
|
|
// Parse the link command to extract information we need.
|
2016-05-16 17:34:04 +03:00
|
|
|
for (; arg != argEnd; ++arg) {
|
|
|
|
if (cmSystemTools::Strucmp(arg->c_str(), "/INCREMENTAL:YES") == 0) {
|
2015-09-15 22:51:19 +03:00
|
|
|
this->Incremental = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (cmSystemTools::Strucmp(arg->c_str(), "/INCREMENTAL") == 0) {
|
2015-09-15 22:51:19 +03:00
|
|
|
this->Incremental = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (cmSystemTools::Strucmp(arg->c_str(), "/MANIFEST:NO") == 0) {
|
2015-09-15 22:51:19 +03:00
|
|
|
this->LinkGeneratesManifest = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (cmHasLiteralPrefix(*arg, "/Fe")) {
|
2015-09-15 22:51:19 +03:00
|
|
|
this->TargetFile = arg->substr(3);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (cmHasLiteralPrefix(*arg, "/out:")) {
|
2015-09-15 22:51:19 +03:00
|
|
|
this->TargetFile = arg->substr(5);
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-15 22:51:19 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->TargetFile.empty()) {
|
2015-09-15 22:51:19 +03:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-15 22:51:19 +03:00
|
|
|
|
|
|
|
this->ManifestFile = intDir + "/embed.manifest";
|
|
|
|
this->LinkerManifestFile = intDir + "/intermediate.manifest";
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Incremental) {
|
2015-09-15 22:51:19 +03:00
|
|
|
// We will compile a resource containing the manifest and
|
|
|
|
// pass it to the link command.
|
|
|
|
this->ManifestFileRC = intDir + "/manifest.rc";
|
|
|
|
this->ManifestFileRes = intDir + "/manifest.res";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (this->UserManifests.empty()) {
|
2015-09-16 17:24:16 +03:00
|
|
|
// Prior to support for user-specified manifests CMake placed the
|
|
|
|
// linker-generated manifest next to the binary (as if it were not to be
|
|
|
|
// embedded) when not linking incrementally. Preserve this behavior.
|
2015-09-15 22:51:19 +03:00
|
|
|
this->ManifestFile = this->TargetFile + ".manifest";
|
|
|
|
this->LinkerManifestFile = this->ManifestFile;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-15 22:51:19 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->LinkGeneratesManifest) {
|
2015-09-15 22:51:19 +03:00
|
|
|
this->LinkCommand.push_back("/MANIFEST");
|
|
|
|
this->LinkCommand.push_back("/MANIFESTFILE:" + this->LinkerManifestFile);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-15 22:51:19 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cmVSLink::Link()
|
|
|
|
{
|
|
|
|
if (this->Incremental &&
|
2016-05-16 17:34:04 +03:00
|
|
|
(this->LinkGeneratesManifest || !this->UserManifests.empty())) {
|
|
|
|
if (this->Verbose) {
|
2015-09-15 22:51:19 +03:00
|
|
|
std::cout << "Visual Studio Incremental Link with embedded manifests\n";
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
return LinkIncremental();
|
|
|
|
}
|
|
|
|
if (this->Verbose) {
|
|
|
|
if (!this->Incremental) {
|
2015-09-15 22:51:19 +03:00
|
|
|
std::cout << "Visual Studio Non-Incremental Link\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-09-15 22:51:19 +03:00
|
|
|
std::cout << "Visual Studio Incremental Link without manifests\n";
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-15 22:51:19 +03:00
|
|
|
return LinkNonIncremental();
|
|
|
|
}
|
|
|
|
|
|
|
|
int cmVSLink::LinkIncremental()
|
2013-10-04 01:28:00 +04:00
|
|
|
{
|
|
|
|
// This follows the steps listed here:
|
|
|
|
// http://blogs.msdn.com/zakramer/archive/2006/05/22/603558.aspx
|
|
|
|
|
|
|
|
// 1. Compiler compiles the application and generates the *.obj files.
|
|
|
|
// 2. An empty manifest file is generated if this is a clean build and if
|
|
|
|
// not the previous one is reused.
|
|
|
|
// 3. The resource compiler (rc.exe) compiles the *.manifest file to a
|
|
|
|
// *.res file.
|
|
|
|
// 4. Linker generates the binary (EXE or DLL) with the /incremental
|
|
|
|
// switch and embeds the dummy manifest file. The linker also generates
|
|
|
|
// the real manifest file based on the binaries that your binary depends
|
|
|
|
// on.
|
|
|
|
// 5. The manifest tool (mt.exe) is then used to generate the final
|
|
|
|
// manifest.
|
|
|
|
|
|
|
|
// If the final manifest is changed, then 6 and 7 are run, if not
|
|
|
|
// they are skipped, and it is done.
|
|
|
|
|
|
|
|
// 6. The resource compiler is invoked one more time.
|
|
|
|
// 7. Finally, the Linker does another incremental link, but since the
|
|
|
|
// only thing that has changed is the *.res file that contains the
|
|
|
|
// manifest it is a short link.
|
2015-09-15 22:51:19 +03:00
|
|
|
|
|
|
|
// Create a resource file referencing the manifest.
|
|
|
|
std::string absManifestFile =
|
|
|
|
cmSystemTools::CollapseFullPath(this->ManifestFile);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->Verbose) {
|
2015-09-15 22:51:19 +03:00
|
|
|
std::cout << "Create " << this->ManifestFileRC << "\n";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-15 22:51:19 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
cmsys::ofstream fout(this->ManifestFileRC.c_str());
|
|
|
|
if (!fout) {
|
|
|
|
return -1;
|
2013-10-04 01:28:00 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
fout << this->Type << " /* CREATEPROCESS_MANIFEST_RESOURCE_ID */ "
|
|
|
|
"24 /* RT_MANIFEST */ \""
|
|
|
|
<< absManifestFile << "\"";
|
2015-09-15 22:51:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we have not previously generated a manifest file,
|
|
|
|
// generate an empty one so the resource compiler succeeds.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::FileExists(this->ManifestFile)) {
|
|
|
|
if (this->Verbose) {
|
2015-09-15 22:51:19 +03:00
|
|
|
std::cout << "Create empty: " << this->ManifestFile << "\n";
|
2013-10-04 01:28:00 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
cmsys::ofstream foutTmp(this->ManifestFile.c_str());
|
|
|
|
}
|
2015-09-15 22:51:19 +03:00
|
|
|
|
|
|
|
// Compile the resource file.
|
|
|
|
std::vector<std::string> rcCommand;
|
|
|
|
rcCommand.push_back(cmSystemTools::FindProgram("rc.exe"));
|
|
|
|
rcCommand.push_back("/fo" + this->ManifestFileRes);
|
|
|
|
rcCommand.push_back(this->ManifestFileRC);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!RunCommand("RC Pass 1", rcCommand, this->Verbose)) {
|
2013-10-04 01:28:00 +04:00
|
|
|
return -1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-15 22:51:19 +03:00
|
|
|
|
2015-11-18 17:10:51 +03:00
|
|
|
// Tell the linker to use our manifest compiled into a resource.
|
|
|
|
this->LinkCommand.push_back(this->ManifestFileRes);
|
|
|
|
|
2015-09-15 22:51:19 +03:00
|
|
|
// Run the link command (possibly generates intermediate manifest).
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!RunCommand("LINK Pass 1", this->LinkCommand, this->Verbose)) {
|
2015-08-08 08:06:27 +03:00
|
|
|
return -1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-15 22:51:19 +03:00
|
|
|
|
|
|
|
// Run the manifest tool to create the final manifest.
|
|
|
|
int mtRet = this->RunMT("/out:" + this->ManifestFile, true);
|
|
|
|
|
|
|
|
// If mt returns 1090650113 (or 187 on a posix host) then it updated the
|
|
|
|
// manifest file so we need to embed it again. Otherwise we are done.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (mtRet != 1090650113 && mtRet != 187) {
|
2013-10-04 01:28:00 +04:00
|
|
|
return mtRet;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-15 22:51:19 +03:00
|
|
|
|
|
|
|
// Compile the resource file again.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!RunCommand("RC Pass 2", rcCommand, this->Verbose)) {
|
2013-10-04 01:28:00 +04:00
|
|
|
return -1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-15 22:51:19 +03:00
|
|
|
|
|
|
|
// Link incrementally again to use the updated resource.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!RunCommand("FINAL LINK", this->LinkCommand, this->Verbose)) {
|
2013-10-04 01:28:00 +04:00
|
|
|
return -1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-10-04 01:28:00 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-09-15 22:51:19 +03:00
|
|
|
int cmVSLink::LinkNonIncremental()
|
2013-10-04 01:28:00 +04:00
|
|
|
{
|
2015-09-15 22:51:19 +03:00
|
|
|
// Run the link command (possibly generates intermediate manifest).
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!RunCommand("LINK", this->LinkCommand, this->Verbose)) {
|
2013-10-04 01:28:00 +04:00
|
|
|
return -1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-15 22:51:19 +03:00
|
|
|
|
|
|
|
// If we have no manifest files we are done.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->LinkGeneratesManifest && this->UserManifests.empty()) {
|
2013-10-04 01:28:00 +04:00
|
|
|
return 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-15 22:51:19 +03:00
|
|
|
|
|
|
|
// Run the manifest tool to embed the final manifest in the binary.
|
|
|
|
std::string mtOut =
|
2016-05-16 17:34:04 +03:00
|
|
|
"/outputresource:" + this->TargetFile + (this->Type == 1 ? ";#1" : ";#2");
|
2015-09-15 22:51:19 +03:00
|
|
|
return this->RunMT(mtOut, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
int cmVSLink::RunMT(std::string const& out, bool notify)
|
|
|
|
{
|
2014-02-10 09:21:34 +04:00
|
|
|
std::vector<std::string> mtCommand;
|
2013-10-04 01:28:00 +04:00
|
|
|
mtCommand.push_back(cmSystemTools::FindProgram("mt.exe"));
|
|
|
|
mtCommand.push_back("/nologo");
|
|
|
|
mtCommand.push_back("/manifest");
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->LinkGeneratesManifest) {
|
2015-09-15 22:51:19 +03:00
|
|
|
mtCommand.push_back(this->LinkerManifestFile);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
mtCommand.insert(mtCommand.end(), this->UserManifests.begin(),
|
|
|
|
this->UserManifests.end());
|
2015-09-15 22:51:19 +03:00
|
|
|
mtCommand.push_back(out);
|
2016-05-16 17:34:04 +03:00
|
|
|
if (notify) {
|
2015-09-15 22:51:19 +03:00
|
|
|
// Add an undocumented option that enables a special return
|
|
|
|
// code to notify us when the manifest is modified.
|
|
|
|
mtCommand.push_back("/notify_update");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-15 22:51:19 +03:00
|
|
|
int mtRet = 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!RunCommand("MT", mtCommand, this->Verbose, &mtRet)) {
|
2013-10-04 01:28:00 +04:00
|
|
|
return -1;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2015-09-15 22:51:19 +03:00
|
|
|
return mtRet;
|
2013-10-04 01:28:00 +04:00
|
|
|
}
|