summaryrefslogtreecommitdiffstats
path: root/Source/cmake.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2006-06-15 20:17:11 (GMT)
committerBrad King <brad.king@kitware.com>2006-06-15 20:17:11 (GMT)
commit0bbcb49f65eb92daafc5ad87162f1ecedc3438dc (patch)
tree4889b6c00d1b1fb55a0e55c1ec17cb16edf0a4ab /Source/cmake.cxx
parent6438bec4c9355960f47e4b853f27b548a55ec5e0 (diff)
downloadCMake-0bbcb49f65eb92daafc5ad87162f1ecedc3438dc.zip
CMake-0bbcb49f65eb92daafc5ad87162f1ecedc3438dc.tar.gz
CMake-0bbcb49f65eb92daafc5ad87162f1ecedc3438dc.tar.bz2
ENH: Added generation of link rules into script files executed by a cmake -E command in order to support longer link lines. This is needed only on platforms without response file support and that may have weak shells.
Diffstat (limited to 'Source/cmake.cxx')
-rw-r--r--Source/cmake.cxx105
1 files changed, 105 insertions, 0 deletions
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 550e0a6..44efd23 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -32,6 +32,7 @@
#endif
# include <cmsys/Directory.hxx>
+#include <cmsys/Process.h>
// only build kdevelop generator on non-windows platforms
// when not bootstrapping cmake
@@ -1178,6 +1179,12 @@ int cmake::ExecuteCMakeCommand(std::vector<std::string>& args)
return 1;
}
+ // Internal CMake link script support.
+ else if (args[1] == "cmake_link_script" && args.size() >= 3)
+ {
+ return cmake::ExecuteLinkScript(args);
+ }
+
#ifdef CMAKE_BUILD_WITH_CMAKE
// Internal CMake color makefile support.
else if (args[1] == "cmake_echo_color")
@@ -2643,3 +2650,101 @@ int cmake::ExecuteEchoColor(std::vector<std::string>&)
return 1;
}
#endif
+
+//----------------------------------------------------------------------------
+int cmake::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;
+ if(args.size() >= 4)
+ {
+ if(args[3].find("--verbose=") == 0)
+ {
+ if(!cmSystemTools::IsOff(args[3].substr(10).c_str()))
+ {
+ verbose = true;
+ }
+ }
+ }
+
+ // Allocate a process instance.
+ cmsysProcess* cp = cmsysProcess_New();
+ if(!cp)
+ {
+ std::cerr << "Error allocating process instance in link script."
+ << std::endl;
+ return 1;
+ }
+
+ // 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.
+ std::ifstream fin(args[2].c_str());
+ if(!fin)
+ {
+ std::cerr << "Error opening link script \""
+ << args[2] << "\"" << std::endl;
+ return 1;
+ }
+
+ // Run one command at a time.
+ std::string command;
+ int result = 0;
+ while(result == 0 && cmSystemTools::GetLineFromStream(fin, command))
+ {
+ // Setup this command line.
+ const char* cmd[2] = {command.c_str(), 0};
+ cmsysProcess_SetCommand(cp, cmd);
+
+ // Report the command if verbose output is enabled.
+ if(verbose)
+ {
+ std::cout << command << std::endl;
+ }
+
+ // Run the command and wait for it to exit.
+ cmsysProcess_Execute(cp);
+ cmsysProcess_WaitForExit(cp, 0);
+
+ // Report failure if any.
+ switch(cmsysProcess_GetState(cp))
+ {
+ case cmsysProcess_State_Exited:
+ {
+ int value = cmsysProcess_GetExitValue(cp);
+ if(value != 0)
+ {
+ result = value;
+ }
+ }
+ break;
+ 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;
+ };
+ }
+
+ // Free the process instance.
+ cmsysProcess_Delete(cp);
+
+ // Return the final resulting return value.
+ return result;
+}