diff options
author | Alexander Neundorf <neundorf@kde.org> | 2007-05-24 12:56:14 (GMT) |
---|---|---|
committer | Alexander Neundorf <neundorf@kde.org> | 2007-05-24 12:56:14 (GMT) |
commit | 00e6d62fd13953ce52f5507f6263504261e7687c (patch) | |
tree | 49d56cc76c50d839e303ee222b89141e787d6676 /Source/cmTryRunCommand.cxx | |
parent | 79756b0e676c9e5e02ad13039ad092b78f64f63d (diff) | |
download | CMake-00e6d62fd13953ce52f5507f6263504261e7687c.zip CMake-00e6d62fd13953ce52f5507f6263504261e7687c.tar.gz CMake-00e6d62fd13953ce52f5507f6263504261e7687c.tar.bz2 |
ENH: move output file search to cmTryCompileCommand.cxx, so it can be used
there too... many public static functions with lots of arguments... :-/
Alex
Diffstat (limited to 'Source/cmTryRunCommand.cxx')
-rw-r--r-- | Source/cmTryRunCommand.cxx | 154 |
1 files changed, 38 insertions, 116 deletions
diff --git a/Source/cmTryRunCommand.cxx b/Source/cmTryRunCommand.cxx index ab8670c..8179a77 100644 --- a/Source/cmTryRunCommand.cxx +++ b/Source/cmTryRunCommand.cxx @@ -71,140 +71,62 @@ bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv) } } // do the try compile - int res = cmTryCompileCommand::CoreTryCompileCode(this->Makefile, - tryCompile, false); - + std::string fullPath; + int res = cmTryCompileCommand::CoreTryCompileCode(this->Makefile, tryCompile, + false, this->GetName(), fullPath); + // now try running the command if it compiled - std::string binaryDirectory = argv[2]; - binaryDirectory += cmake::GetCMakeFilesDirectory(); - binaryDirectory += "/CMakeTmp"; - if (!res) + if (!res==0) + { + if (fullPath.size() > 0) { int retVal = -1; std::string output; - std::string executableSuffix=this->Makefile->GetDefinition( - "CMAKE_EXECUTABLE_SUFFIX"); - std::string command1 = binaryDirectory; - std::vector<std::string> attemptedPaths; - command1 += "/cmTryCompileExec"; - command1 += executableSuffix; - std::string fullPath; - if(cmSystemTools::FileExists(command1.c_str())) - { - fullPath = cmSystemTools::CollapseFullPath(command1.c_str()); - } - attemptedPaths.push_back(command1); - command1 = binaryDirectory; - // try CMAKE_TRY_COMPILE_CONFIGURATION if it is set - if (fullPath.empty()) + std::string finalCommand = fullPath; + finalCommand = cmSystemTools::ConvertToRunCommandPath(fullPath.c_str()); + if(runArgs.size()) { - const char* config = - this->Makefile->GetDefinition("CMAKE_TRY_COMPILE_CONFIGURATION"); - // if a config was specified try that first - if (config && config[0]) - { - command1 += "/"; - command1 += config; - command1 += "/cmTryCompileExec"; - command1 += executableSuffix; - if(cmSystemTools::FileExists(command1.c_str())) - { - fullPath = cmSystemTools::CollapseFullPath(command1.c_str()); - } - attemptedPaths.push_back(command1); - } + finalCommand += runArgs; } - // try Debug if still not found - if (fullPath.empty()) + int timeout = 0; + bool worked = cmSystemTools::RunSingleCommand(finalCommand.c_str(), + &output, &retVal, + 0, false, timeout); + if(outputVariable.size()) { - command1 = binaryDirectory; - command1 += "/Debug/cmTryCompileExec"; - command1 += executableSuffix; - if(cmSystemTools::FileExists(command1.c_str())) + // if the TryCompileCore saved output in this outputVariable then + // prepend that output to this output + const char* compileOutput + = this->Makefile->GetDefinition(outputVariable.c_str()); + if(compileOutput) { - fullPath = cmSystemTools::CollapseFullPath(command1.c_str()); + output = std::string(compileOutput) + output; } - attemptedPaths.push_back(command1); + this->Makefile->AddDefinition(outputVariable.c_str(), output.c_str()); } - // try Deployment if still not found - if (fullPath.empty()) + // set the run var + char retChar[1000]; + if(worked) { - command1 = binaryDirectory; - command1 += "/Development/cmTryCompileExec"; - command1 += executableSuffix; - if(cmSystemTools::FileExists(command1.c_str())) - { - fullPath = cmSystemTools::CollapseFullPath(command1.c_str()); - } - attemptedPaths.push_back(command1); - } - if (fullPath.empty()) - { - cmOStringStream emsg; - emsg << "Unable to find executable for TRY_RUN: tried \""; - for (i = 0; i < attemptedPaths.size(); ++i) - { - emsg << attemptedPaths[i]; - if (i < attemptedPaths.size() - 1) - { - emsg << "\" and \""; - } - else - { - emsg << "\"."; - } - } - cmSystemTools::Error(emsg.str().c_str()); + sprintf(retChar,"%i",retVal); } - if (fullPath.size() > 1) + else { - std::string finalCommand = fullPath; - finalCommand = cmSystemTools::ConvertToRunCommandPath(fullPath.c_str()); - if(runArgs.size()) - { - finalCommand += runArgs; - } - int timeout = 0; - bool worked = cmSystemTools::RunSingleCommand(finalCommand.c_str(), - &output, &retVal, - 0, false, timeout); - if(outputVariable.size()) - { - // if the TryCompileCore saved output in this outputVariable then - // prepend that output to this output - const char* compileOutput - = this->Makefile->GetDefinition(outputVariable.c_str()); - if(compileOutput) - { - output = std::string(compileOutput) + output; - } - this->Makefile->AddDefinition(outputVariable.c_str(), output.c_str()); - } - // set the run var - char retChar[1000]; - if(worked) - { - sprintf(retChar,"%i",retVal); - } - else - { - strcpy(retChar, "FAILED_TO_RUN"); - } - this->Makefile->AddCacheDefinition(argv[0].c_str(), retChar, - "Result of TRY_RUN", - cmCacheManager::INTERNAL); + strcpy(retChar, "FAILED_TO_RUN"); } + this->Makefile->AddCacheDefinition(argv[0].c_str(), retChar, + "Result of TRY_RUN", + cmCacheManager::INTERNAL); } - - // if we created a directory etc, then cleanup after ourselves - std::string cacheFile = binaryDirectory; - cacheFile += "/CMakeLists.txt"; + } + + // if we created a directory etc, then cleanup after ourselves if(!this->Makefile->GetCMakeInstance()->GetDebugTryCompile()) { + std::string binaryDirectory = argv[2]; + binaryDirectory += cmake::GetCMakeFilesDirectory(); + binaryDirectory += "/CMakeTmp"; cmTryCompileCommand::CleanupFiles(binaryDirectory.c_str()); } return true; } - - - |