2002-09-19 17:48:39 +04:00
|
|
|
/*=========================================================================
|
|
|
|
|
2002-10-24 02:03:27 +04:00
|
|
|
Program: CMake - Cross-Platform Makefile Generator
|
2002-09-19 17:48:39 +04:00
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
2002-10-24 02:03:27 +04:00
|
|
|
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
|
|
|
|
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
|
2002-09-19 17:48:39 +04:00
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
PURPOSE. See the above copyright notices for more information.
|
|
|
|
|
|
|
|
=========================================================================*/
|
|
|
|
#include "cmTryRunCommand.h"
|
|
|
|
#include "cmCacheManager.h"
|
|
|
|
#include "cmTryCompileCommand.h"
|
|
|
|
|
ENH: merge CMake-CrossCompileBasic to HEAD
-add a RESULT_VARIABLE to INCLUDE()
-add CMAKE_TOOLCHAIN_FILE for specifiying your (potentially crosscompiling) toolchain
-have TRY_RUN() complain if you try to use it in crosscompiling mode (which were compiled but cannot run on this system)
-use CMAKE_EXECUTABLE_SUFFIX in TRY_RUN(), probably TRY_RUN won't be able to
run the executables if they have a different suffix because they are
probably crosscompiled, but nevertheless it should be able to find them
-make several cmake variables presettable by the user: CMAKE_C/CXX_COMPILER, CMAKE_C/CXX_OUTPUT_EXTENSION, CMAKE_SYSTEM_NAME, CMAKE_SYSTEM_INFO_FILE
-support prefix for GNU toolchains (arm-elf-gcc, arm-elf-ar, arm-elf-strip etc.)
-move ranlib on OSX from the file command to a command in executed in cmake_install.cmake
-add support for stripping during install in cmake_install.cmake
-split out cl.cmake from Windows-cl.cmake, first (very incomplete) step to support MS crosscompiling tools
-remove stdio.h from the simple C program which checks if the compiler works, since this may not exist for some embedded platforms
-create a new CMakeFindBinUtils.cmake which collects the search fro ar, ranlib, strip, ld, link, install_name_tool and other tools like these
-add support for CMAKE_FIND_ROOT_PATH for all FIND_XXX commands, which is a
list of directories which will be prepended to all search directories, right
now as a cmake variable, turning it into a global cmake property may need
some more work
-remove cmTestTestHandler::TryExecutable(), it's unused
-split cmFileCommand::HandleInstall() into slightly smaller functions
Alex
2007-05-17 21:20:44 +04:00
|
|
|
// cmTryRunCommand
|
2002-09-19 17:48:39 +04:00
|
|
|
bool cmTryRunCommand::InitialPass(std::vector<std::string> const& argv)
|
|
|
|
{
|
|
|
|
if(argv.size() < 4)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
ENH: merge CMake-CrossCompileBasic to HEAD
-add a RESULT_VARIABLE to INCLUDE()
-add CMAKE_TOOLCHAIN_FILE for specifiying your (potentially crosscompiling) toolchain
-have TRY_RUN() complain if you try to use it in crosscompiling mode (which were compiled but cannot run on this system)
-use CMAKE_EXECUTABLE_SUFFIX in TRY_RUN(), probably TRY_RUN won't be able to
run the executables if they have a different suffix because they are
probably crosscompiled, but nevertheless it should be able to find them
-make several cmake variables presettable by the user: CMAKE_C/CXX_COMPILER, CMAKE_C/CXX_OUTPUT_EXTENSION, CMAKE_SYSTEM_NAME, CMAKE_SYSTEM_INFO_FILE
-support prefix for GNU toolchains (arm-elf-gcc, arm-elf-ar, arm-elf-strip etc.)
-move ranlib on OSX from the file command to a command in executed in cmake_install.cmake
-add support for stripping during install in cmake_install.cmake
-split out cl.cmake from Windows-cl.cmake, first (very incomplete) step to support MS crosscompiling tools
-remove stdio.h from the simple C program which checks if the compiler works, since this may not exist for some embedded platforms
-create a new CMakeFindBinUtils.cmake which collects the search fro ar, ranlib, strip, ld, link, install_name_tool and other tools like these
-add support for CMAKE_FIND_ROOT_PATH for all FIND_XXX commands, which is a
list of directories which will be prepended to all search directories, right
now as a cmake variable, turning it into a global cmake property may need
some more work
-remove cmTestTestHandler::TryExecutable(), it's unused
-split cmFileCommand::HandleInstall() into slightly smaller functions
Alex
2007-05-17 21:20:44 +04:00
|
|
|
|
|
|
|
if (this->Makefile->IsOn("CMAKE_CROSSCOMPILING"))
|
|
|
|
{
|
|
|
|
this->SetError("doesn't work when crosscompiling.");
|
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
|
|
|
return false;
|
|
|
|
}
|
2002-09-19 17:48:39 +04:00
|
|
|
|
|
|
|
// build an arg list for TryCompile and extract the runArgs
|
|
|
|
std::vector<std::string> tryCompile;
|
2004-09-22 22:42:05 +04:00
|
|
|
std::string outputVariable;
|
2002-09-19 17:48:39 +04:00
|
|
|
std::string runArgs;
|
2002-09-20 16:09:03 +04:00
|
|
|
unsigned int i;
|
2002-09-19 17:48:39 +04:00
|
|
|
for (i = 1; i < argv.size(); ++i)
|
|
|
|
{
|
|
|
|
if (argv[i] == "ARGS")
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
while (i < argv.size() && argv[i] != "COMPILE_DEFINITIONS" &&
|
|
|
|
argv[i] != "CMAKE_FLAGS")
|
|
|
|
{
|
|
|
|
runArgs += " ";
|
|
|
|
runArgs += argv[i];
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
if (i < argv.size())
|
|
|
|
{
|
|
|
|
tryCompile.push_back(argv[i]);
|
|
|
|
}
|
2004-09-22 22:42:05 +04:00
|
|
|
}
|
|
|
|
else
|
2002-09-19 17:48:39 +04:00
|
|
|
{
|
|
|
|
tryCompile.push_back(argv[i]);
|
2004-09-22 22:42:05 +04:00
|
|
|
if (argv[i] == "OUTPUT_VARIABLE")
|
|
|
|
{
|
|
|
|
if ( argv.size() <= (i+1) )
|
|
|
|
{
|
|
|
|
cmSystemTools::Error(
|
2006-03-10 21:54:57 +03:00
|
|
|
"OUTPUT_VARIABLE specified but there is no variable");
|
2004-09-22 22:42:05 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
outputVariable = argv[i+1];
|
|
|
|
}
|
2002-09-19 17:48:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// do the try compile
|
2007-05-24 19:27:51 +04:00
|
|
|
int res = this->TryCompileCode(tryCompile);
|
2007-05-24 16:56:14 +04:00
|
|
|
|
2002-09-19 17:48:39 +04:00
|
|
|
// now try running the command if it compiled
|
2007-05-24 19:27:51 +04:00
|
|
|
if (!res)
|
2002-09-19 17:48:39 +04:00
|
|
|
{
|
2007-05-24 19:27:51 +04:00
|
|
|
if (this->OutputFile.size() == 0)
|
2002-09-19 17:48:39 +04:00
|
|
|
{
|
2007-05-24 19:27:51 +04:00
|
|
|
cmSystemTools::Error(this->FindErrorMessage.c_str());
|
2007-05-03 23:25:41 +04:00
|
|
|
}
|
2007-05-24 19:27:51 +04:00
|
|
|
else
|
2007-05-03 23:25:41 +04:00
|
|
|
{
|
2007-05-24 19:27:51 +04:00
|
|
|
int retVal = -1;
|
|
|
|
std::string output;
|
|
|
|
std::string finalCommand = cmSystemTools::ConvertToRunCommandPath(
|
|
|
|
this->OutputFile.c_str());
|
|
|
|
if(runArgs.size())
|
2007-05-03 23:25:41 +04:00
|
|
|
{
|
2007-05-24 19:27:51 +04:00
|
|
|
finalCommand += runArgs;
|
2007-05-03 23:25:41 +04:00
|
|
|
}
|
2007-05-24 19:27:51 +04:00
|
|
|
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);
|
2002-09-19 17:48:39 +04:00
|
|
|
}
|
2007-05-24 16:56:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// if we created a directory etc, then cleanup after ourselves
|
2006-03-15 19:02:08 +03:00
|
|
|
if(!this->Makefile->GetCMakeInstance()->GetDebugTryCompile())
|
2004-08-05 01:21:19 +04:00
|
|
|
{
|
2007-05-24 19:27:51 +04:00
|
|
|
this->CleanupFiles(this->BinaryDirectory.c_str());
|
2004-08-05 01:21:19 +04:00
|
|
|
}
|
2002-09-19 17:48:39 +04:00
|
|
|
return true;
|
|
|
|
}
|