ENH: fix for 1450

This commit is contained in:
Bill Hoffman 2005-02-09 23:00:16 -05:00
parent aa947ff48b
commit b7b501bbe8
3 changed files with 24 additions and 9 deletions

View File

@ -10,6 +10,9 @@ MACRO(TEST_BIG_ENDIAN VARIABLE)
${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}
${CMAKE_ROOT}/Modules/TestBigEndian.c ${CMAKE_ROOT}/Modules/TestBigEndian.c
OUTPUT_VARIABLE OUTPUT) OUTPUT_VARIABLE OUTPUT)
IF(${VARIABLE} STREQUAL "FAILED_TO_RUN")
MESSAGE(SEND_ERROR "TestBigEndian Failed to run with output: ${OUTPUT}")
ENDIF(${VARIABLE} STREQUAL "FAILED_TO_RUN")
MESSAGE(STATUS "Check if the system is big endian") MESSAGE(STATUS "Check if the system is big endian")
IF(HAVE_${VARIABLE}) IF(HAVE_${VARIABLE})
FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeError.log FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeError.log

View File

@ -61,7 +61,7 @@ bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv)
if ( argv.size() <= (i+1) ) if ( argv.size() <= (i+1) )
{ {
cmSystemTools::Error( cmSystemTools::Error(
"OUTPUT_VARIABLE specified but there is no variable"); "OUTPUT_VARIABLE specified but there is no variable");
return false; return false;
} }
outputVariable = argv[i+1]; outputVariable = argv[i+1];
@ -75,7 +75,7 @@ bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv)
std::string binaryDirectory = argv[2] + "/CMakeTmp"; std::string binaryDirectory = argv[2] + "/CMakeTmp";
if (!res) if (!res)
{ {
int retVal; int retVal = -1;
std::string output; std::string output;
std::string command; std::string command;
command = binaryDirectory; command = binaryDirectory;
@ -110,25 +110,34 @@ bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv)
finalCommand += runArgs; finalCommand += runArgs;
} }
int timeout = 0; int timeout = 0;
cmSystemTools::RunSingleCommand(finalCommand.c_str(), &output, &retVal, bool worked = cmSystemTools::RunSingleCommand(finalCommand.c_str(),
0, false, timeout); &output, &retVal,
0, false, timeout);
if(outputVariable.size()) if(outputVariable.size())
{ {
// if the TryCompileCore saved output in this outputVariable then // if the TryCompileCore saved output in this outputVariable then
// prepend that output to this output // prepend that output to this output
const char* compileOutput = m_Makefile->GetDefinition(outputVariable.c_str()); const char* compileOutput
= m_Makefile->GetDefinition(outputVariable.c_str());
if(compileOutput) if(compileOutput)
{ {
output = std::string(compileOutput) + output; output = std::string(compileOutput) + output;
} }
m_Makefile->AddDefinition(outputVariable.c_str(), output.c_str()); m_Makefile->AddDefinition(outputVariable.c_str(), output.c_str());
} }
// set the run var // set the run var
char retChar[1000]; char retChar[1000];
sprintf(retChar,"%i",retVal); if(worked)
{
sprintf(retChar,"%i",retVal);
}
else
{
strcpy(retChar, "FAILED_TO_RUN");
}
m_Makefile->AddCacheDefinition(argv[0].c_str(), retChar, m_Makefile->AddCacheDefinition(argv[0].c_str(), retChar,
"Result of TRY_RUN", cmCacheManager::INTERNAL); "Result of TRY_RUN",
cmCacheManager::INTERNAL);
} }
} }

View File

@ -66,7 +66,10 @@ public:
" <ARGUMENTS <arg1> <arg2>...>)\n" " <ARGUMENTS <arg1> <arg2>...>)\n"
"Try compiling a srcfile. Return the success or failure in " "Try compiling a srcfile. Return the success or failure in "
"COMPILE_RESULT_VAR. Then if the compile succeeded, run the " "COMPILE_RESULT_VAR. Then if the compile succeeded, run the "
"executable and return the result in RUN_RESULT_VAR."; "executable and return the result in RUN_RESULT_VAR."
"If the executable was built, but failed for to run for some "
"reason, then RUN_RESULT_VAR will be set to FAILED_TO_RUN, and "
"the output will be in the COMPILE_RESULT_VAR.";
} }
cmTypeMacro(cmTryRunCommand, cmCommand); cmTypeMacro(cmTryRunCommand, cmCommand);