From 157e2b4ac3a067107561d4ccc2b08ea3555cce44 Mon Sep 17 00:00:00 2001 From: Andy Cedilnik Date: Fri, 20 Sep 2002 13:15:56 -0400 Subject: Add option of TRY_COMPILE to store the output of compilation so that if the output fails you can display it or store it in the file --- Source/cmGlobalGenerator.cxx | 7 ++++--- Source/cmGlobalGenerator.h | 3 ++- Source/cmMakefile.cxx | 6 ++++-- Source/cmMakefile.h | 3 ++- Source/cmTryCompileCommand.cxx | 34 ++++++++++++++++++++++++++++++---- 5 files changed, 42 insertions(+), 11 deletions(-) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 3bb4082..9a46ab0 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -141,7 +141,8 @@ void cmGlobalGenerator::LocalGenerate() } int cmGlobalGenerator::TryCompile(const char *, const char *bindir, - const char *, const char *target) + const char *, const char *target, + std::string *output) { // now build the test std::string makeCommand = @@ -157,7 +158,6 @@ int cmGlobalGenerator::TryCompile(const char *, const char *bindir, /** * Run an executable command and put the stdout in output. */ - std::string output; std::string cwd = cmSystemTools::GetCurrentWorkingDirectory(); cmSystemTools::ChangeDirectory(bindir); @@ -172,7 +172,8 @@ int cmGlobalGenerator::TryCompile(const char *, const char *bindir, makeCommand += " all"; } int retVal; - if (!cmSystemTools::RunCommand(makeCommand.c_str(), output, retVal, 0, false)) + + if (!cmSystemTools::RunCommand(makeCommand.c_str(), *output, retVal, 0, false)) { cmSystemTools::Error("Generator: execution of make failed."); // return to the original directory diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 4f994fb..226a67b 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -87,7 +87,8 @@ public: * loaded commands, not as part of the usual build process. */ virtual int TryCompile(const char *srcdir, const char *bindir, - const char *projectName, const char *targetName); + const char *projectName, const char *targetName, + std::string *output); ///! Set the CMake instance void SetCMakeInstance(cmake *cm) { diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 106d373..92fe82e 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1340,7 +1340,8 @@ void cmMakefile::ExpandSourceListArguments( int cmMakefile::TryCompile(const char *srcdir, const char *bindir, const char *projectName, const char *targetName, - const std::vector *cmakeArgs) + const std::vector *cmakeArgs, + std::string *output) { // does the binary directory exist ? If not create it... if (!cmSystemTools::FileIsDirectory(bindir)) @@ -1409,7 +1410,8 @@ int cmMakefile::TryCompile(const char *srcdir, const char *bindir, int ret = m_LocalGenerator->GetGlobalGenerator()->TryCompile(srcdir,bindir, projectName, - targetName); + targetName, + output); cmSystemTools::ChangeDirectory(cwd.c_str()); return ret; diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 56b5080..959677b 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -85,7 +85,8 @@ public: */ int TryCompile(const char *srcdir, const char *bindir, const char *projectName, const char *targetName, - const std::vector *cmakeArgs); + const std::vector *cmakeArgs, + std::string *output); /** * Specify the makefile generator. This is platform/compiler diff --git a/Source/cmTryCompileCommand.cxx b/Source/cmTryCompileCommand.cxx index 9e243a5..cf54a09 100644 --- a/Source/cmTryCompileCommand.cxx +++ b/Source/cmTryCompileCommand.cxx @@ -33,7 +33,8 @@ int cmTryCompileCommand::CoreTryCompileCode( std::string tmpString; // do we have a srcfile signature - if (argv.size() == 3 || argv[3] == "CMAKE_FLAGS" || argv[3] == "COMPILE_DEFINITIONS") + if (argv.size() == 3 || argv[3] == "CMAKE_FLAGS" || argv[3] == "COMPILE_DEFINITIONS" || + argv[3] == "OUTPUT_VARIABLE") { srcFileSignature = true; } @@ -44,7 +45,8 @@ int cmTryCompileCommand::CoreTryCompileCode( { if (argv[i] == "CMAKE_FLAGS") { - for (; i < argv.size() && argv[i] != "COMPILE_DEFINITIONS"; + for (; i < argv.size() && argv[i] != "COMPILE_DEFINITIONS" && + argv[i] != "OUTPUT_VARIABLE"; ++i) { cmakeFlags.push_back(argv[i]); @@ -53,6 +55,23 @@ int cmTryCompileCommand::CoreTryCompileCode( } } + // look for OUTPUT_VARIABLE and store them + std::string outputVariable; + for (i = 3; i < argv.size(); ++i) + { + if (argv[i] == "OUTPUT_VARIABLE") + { + if ( argv.size() <= (i+1) ) + { + cmSystemTools::Error( + "OUTPUT_VARIABLE specified but there is no variable"); + return -1; + } + outputVariable = argv[i+1]; + break; + } + } + // look for COMPILE_DEFINITIONS and store them std::vector compileFlags; for (i = 3; i < argv.size(); ++i) @@ -66,7 +85,8 @@ int cmTryCompileCommand::CoreTryCompileCode( "COMPILE_FLAGS specified on a srcdir type TRY_COMPILE"); return -1; } - for (i = i + 1; i < argv.size() && argv[i] != "CMAKE_FLAGS"; + for (i = i + 1; i < argv.size() && argv[i] != "CMAKE_FLAGS" && + argv[i] != "OUTPUT_VARIABLE"; ++i) { compileFlags.push_back(argv[i]); @@ -144,12 +164,18 @@ int cmTryCompileCommand::CoreTryCompileCode( } } + std::string output; // actually do the try compile now that everything is setup int res = mf->TryCompile(sourceDirectory, binaryDirectory, - projectName, targetName, &cmakeFlags); + projectName, targetName, &cmakeFlags, &output); // set the result var to the return value to indicate success or failure mf->AddDefinition(argv[0].c_str(), (res == 0 ? "TRUE" : "FALSE")); + + if ( outputVariable.size() > 0 ) + { + mf->AddDefinition(outputVariable.c_str(), output.c_str()); + } // if They specified clean then we clean up what we can if (srcFileSignature && clean) -- cgit v0.12