summaryrefslogtreecommitdiffstats
path: root/Source/cmGlobalUnixMakefileGenerator3.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2011-05-24 18:48:14 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2011-05-24 18:48:14 (GMT)
commite51bbc14f6c23087e5c1acd48f556de27d0bfdaa (patch)
tree048068a82996ac61495f5554065ea7803e5b5548 /Source/cmGlobalUnixMakefileGenerator3.cxx
parentc5e00bf0b25fb816a80215c4c110d319c6cce079 (diff)
parentcdc2b41cc2161b21192460bb92da40c6d4c6107f (diff)
downloadCMake-e51bbc14f6c23087e5c1acd48f556de27d0bfdaa.zip
CMake-e51bbc14f6c23087e5c1acd48f556de27d0bfdaa.tar.gz
CMake-e51bbc14f6c23087e5c1acd48f556de27d0bfdaa.tar.bz2
Merge topic 'output-compile-lines'
cdc2b41 Fix CompileCommandOutput test build on Windows 7039d1f Fix CompileCommandOutput test for Make tools not supporting spaces 4268e3d run_compile_commands: Cast istream::get() result to char c45c60b run_compile_commands: Avoid extra stl vector conversion 7c5be51 run_compile_commands: Avoid shadow in std::map<>::at workaround 169bb05 Provide std::map<>::at for use in run_compile_commands 4e2185c Make std::map usage more portable in language=>flags/defines maps a7e7a04 Fix run_compile_commands build on Apple GCC 3.3 c9174c0 Fix signed/unsigned comparison in EscapeJSON 8346a28 Only offer the compile command output feature on unix systems 0e6b05f Adds a test for the compile command line output. 5674844 make compile command output optional fe07b05 implement cxx command output 65c0c24 cache flags and defines 3f064ef refactor flags and defines
Diffstat (limited to 'Source/cmGlobalUnixMakefileGenerator3.cxx')
-rw-r--r--Source/cmGlobalUnixMakefileGenerator3.cxx41
1 files changed, 41 insertions, 0 deletions
diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx
index 55ff87e..169d77d 100644
--- a/Source/cmGlobalUnixMakefileGenerator3.cxx
+++ b/Source/cmGlobalUnixMakefileGenerator3.cxx
@@ -30,6 +30,7 @@ cmGlobalUnixMakefileGenerator3::cmGlobalUnixMakefileGenerator3()
#else
this->UseLinkScript = true;
#endif
+ this->CommandDatabase = NULL;
}
void cmGlobalUnixMakefileGenerator3
@@ -138,6 +139,17 @@ void cmGlobalUnixMakefileGenerator3
}
//----------------------------------------------------------------------------
+std::string EscapeJSON(const std::string& s) {
+ std::string result;
+ for (std::string::size_type i = 0; i < s.size(); ++i) {
+ if (s[i] == '"' || s[i] == '\\') {
+ result += '\\';
+ }
+ result += s[i];
+ }
+ return result;
+}
+
void cmGlobalUnixMakefileGenerator3::Generate()
{
// first do superclass method
@@ -179,6 +191,35 @@ void cmGlobalUnixMakefileGenerator3::Generate()
// write the main makefile
this->WriteMainMakefile2();
this->WriteMainCMakefile();
+
+ if (this->CommandDatabase != NULL) {
+ *this->CommandDatabase << std::endl << "]";
+ delete this->CommandDatabase;
+ this->CommandDatabase = NULL;
+ }
+}
+
+void cmGlobalUnixMakefileGenerator3::AddCXXCompileCommand(
+ const std::string &sourceFile, const std::string &workingDirectory,
+ const std::string &compileCommand) {
+ if (this->CommandDatabase == NULL)
+ {
+ std::string commandDatabaseName =
+ std::string(this->GetCMakeInstance()->GetHomeOutputDirectory())
+ + "/compile_commands.json";
+ this->CommandDatabase =
+ new cmGeneratedFileStream(commandDatabaseName.c_str());
+ *this->CommandDatabase << "[" << std::endl;
+ } else {
+ *this->CommandDatabase << "," << std::endl;
+ }
+ *this->CommandDatabase << "{" << std::endl
+ << " \"directory\": \"" << EscapeJSON(workingDirectory) << "\","
+ << std::endl
+ << " \"command\": \"" << EscapeJSON(compileCommand) << "\","
+ << std::endl
+ << " \"file\": \"" << EscapeJSON(sourceFile) << "\""
+ << std::endl << "}";
}
void cmGlobalUnixMakefileGenerator3::WriteMainMakefile2()