Commit 610ff11c authored by Ken Martin's avatar Ken Martin
Browse files

now Try compile can include CMAKE_FLAGS

parent f835a83b
......@@ -1339,7 +1339,8 @@ void cmMakefile::ExpandSourceListArguments(
}
int cmMakefile::TryCompile(const char *srcdir, const char *bindir,
const char *projectName, const char *targetName)
const char *projectName, const char *targetName,
const std::vector<std::string> *cmakeArgs)
{
// does the binary directory exist ? If not create it...
if (!cmSystemTools::FileIsDirectory(bindir))
......@@ -1377,7 +1378,11 @@ int cmMakefile::TryCompile(const char *srcdir, const char *bindir,
cm.SetStartOutputDirectory(bindir);
cm.SetCMakeCommand(cmakeCommand.c_str());
cm.LoadCache();
// if cmake args were provided then pass them in
if (cmakeArgs)
{
cm.SetCacheArgs(*cmakeArgs);
}
// to save time we pass the EnableLanguage info directly
gg->EnableLanguagesFromGenerator(m_LocalGenerator->GetGlobalGenerator(),
this);
......
......@@ -84,7 +84,8 @@ public:
* loaded commands, not as part of the usual build process.
*/
int TryCompile(const char *srcdir, const char *bindir,
const char *projectName, const char *targetName);
const char *projectName, const char *targetName,
const std::vector<std::string> *cmakeArgs);
/**
* Specify the makefile generator. This is platform/compiler
......
......@@ -25,6 +25,27 @@ bool cmTryCompileCommand::InitialPass(std::vector<std::string> const& argv)
return false;
}
// which signature were we called with ?
bool srcFileSignature = true;
// look for CMAKE_FLAGS and store them
std::vector<std::string> cmakeFlags;
int i;
for (i = 3; i < argv.size(); ++i)
{
if (argv[i] == "CMAKE_FLAGS")
{
for (; i < argv.size(); ++i)
{
cmakeFlags.push_back(argv[i]);
}
}
else
{
srcFileSignature = false;
}
}
// where will the binaries be stored
const char* binaryDirectory = argv[1].c_str();
const char* sourceDirectory = argv[2].c_str();
......@@ -34,12 +55,11 @@ bool cmTryCompileCommand::InitialPass(std::vector<std::string> const& argv)
// compute the binary dir when TRY_COMPILE is called with a src file
// signature
if (argv.size() == 3)
if (srcFileSignature)
{
tmpString = argv[1] + "/CMakeTmp";
binaryDirectory = tmpString.c_str();
}
// make sure the binary directory exists
cmSystemTools::MakeDirectory(binaryDirectory);
......@@ -52,7 +72,7 @@ bool cmTryCompileCommand::InitialPass(std::vector<std::string> const& argv)
}
// which signature are we using? If we are using var srcfile bindir
if (argv.size() == 3)
if (srcFileSignature)
{
// remove any CMakeCache.txt files so we will have a clean test
std::string ccFile = tmpString + "/CMakeCache.txt";
......@@ -93,13 +113,13 @@ bool cmTryCompileCommand::InitialPass(std::vector<std::string> const& argv)
// actually do the try compile now that everything is setup
int res = m_Makefile->TryCompile(sourceDirectory, binaryDirectory,
projectName, targetName);
projectName, targetName, &cmakeFlags);
// set the result var to the return value to indicate success or failure
m_Makefile->AddDefinition(argv[0].c_str(), (res == 0 ? "TRUE" : "FALSE"));
// if we created a directory etc, then cleanup after ourselves
if (argv.size() == 3)
if (srcFileSignature)
{
cmDirectory dir;
dir.Load(binaryDirectory);
......
......@@ -62,11 +62,11 @@ public:
virtual const char* GetFullDocumentation()
{
return
"TRY_COMPILE(RESULT_VAR bindir srcdir projectName <targetName>)\n"
"TRY_COMPILE(RESULT_VAR bindir srcdir projectName <CMAKE_FLAGS <Flags>>)\n"
"Try compiling a program. Return the success or failure in RESULT_VAR "
"If <target name> is specified then build just that target "
"otherwise the all or ALL_BUILD target is built.\n"
"TRY_COMPILE(RESULT_VAR bindir srcfile)\n"
"TRY_COMPILE(RESULT_VAR bindir srcfile <CMAKE_FLAGS <Flags>>)\n"
"Try compiling a srcfile. Return the success or failure in RESULT_VAR.";
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment