2002-01-21 23:30:43 +03:00
|
|
|
/*=========================================================================
|
|
|
|
|
2002-10-24 02:03:27 +04:00
|
|
|
Program: CMake - Cross-Platform Makefile Generator
|
2002-01-21 23:30:43 +03: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-01-21 23:30:43 +03: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.
|
|
|
|
|
|
|
|
=========================================================================*/
|
2001-06-22 01:52:54 +04:00
|
|
|
#include "cmaketest.h"
|
|
|
|
#include "cmSystemTools.h"
|
2001-08-29 23:57:57 +04:00
|
|
|
#include "cmake.h"
|
|
|
|
#include "cmListFileCache.h"
|
2002-08-23 21:46:32 +04:00
|
|
|
#include "cmCacheManager.h"
|
2002-10-10 01:47:24 +04:00
|
|
|
#include "cmDynamicLoader.h"
|
2003-06-23 22:10:12 +04:00
|
|
|
|
2001-11-28 18:51:28 +03:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
2001-10-26 23:42:02 +04:00
|
|
|
#include "windows.h"
|
|
|
|
#endif
|
2001-06-22 01:52:54 +04:00
|
|
|
|
2002-10-10 01:47:24 +04:00
|
|
|
int do_cmaketest(int ac, char** av);
|
|
|
|
|
|
|
|
int main(int ac, char** av)
|
|
|
|
{
|
2002-12-11 19:49:08 +03:00
|
|
|
cmSystemTools::EnableMSVCDebugHook();
|
2002-10-10 01:47:24 +04:00
|
|
|
int ret = do_cmaketest(ac, av);
|
|
|
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
|
|
|
cmDynamicLoader::FlushCache();
|
|
|
|
#endif
|
|
|
|
cmListFileCache::GetInstance()->ClearCache();
|
|
|
|
return ret;
|
|
|
|
}
|
2002-04-05 18:39:13 +04:00
|
|
|
|
2001-06-22 01:52:54 +04:00
|
|
|
// this is a test driver program for cmake.
|
2002-10-10 01:47:24 +04:00
|
|
|
int do_cmaketest (int argc, char **argv)
|
2001-06-22 01:52:54 +04:00
|
|
|
{
|
|
|
|
if (argc < 4)
|
|
|
|
{
|
2002-12-10 00:23:12 +03:00
|
|
|
std::cerr << "Usage: " << argv[0]
|
|
|
|
<< " test-src-dir test-bin-dir test-executable" << std::endl;
|
|
|
|
std::cerr << "\tOptional arguments: executable-directory project-name " << std::endl
|
|
|
|
<< "\t CMAKE_ARGS argument ...\n";
|
2001-06-22 01:52:54 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2003-01-16 01:31:22 +03:00
|
|
|
bool onlyOneConfig = false;
|
|
|
|
if(argc > 3)
|
|
|
|
{
|
|
|
|
if(strcmp(argv[argc-1], "ONLY_ONE_CONFIG") == 0)
|
|
|
|
{
|
|
|
|
onlyOneConfig = true;
|
|
|
|
argc--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-22 01:52:54 +04:00
|
|
|
// does the directory exist ?
|
|
|
|
if (!cmSystemTools::FileIsDirectory(argv[2]))
|
|
|
|
{
|
|
|
|
cmSystemTools::MakeDirectory(argv[2]);
|
|
|
|
}
|
2002-01-23 18:56:21 +03:00
|
|
|
|
2001-08-24 00:00:46 +04:00
|
|
|
const char* sourceDirectory = argv[1];
|
|
|
|
const char* binaryDirectory = argv[2];
|
|
|
|
const char* executableName = argv[3];
|
|
|
|
const char* executableDirectory = "";
|
2002-01-23 18:56:21 +03:00
|
|
|
|
2001-08-24 00:00:46 +04:00
|
|
|
if(argc > 4)
|
|
|
|
{
|
|
|
|
executableDirectory = argv[4];
|
|
|
|
}
|
2002-01-23 18:56:21 +03:00
|
|
|
|
2001-12-19 23:26:21 +03:00
|
|
|
const char* projectName = executableName;
|
|
|
|
if(argc > 5)
|
|
|
|
{
|
|
|
|
projectName = argv[5];
|
|
|
|
}
|
2002-03-07 00:30:55 +03:00
|
|
|
|
|
|
|
// WARNING: the rest of the args is passed to cmake
|
2002-01-23 18:56:21 +03:00
|
|
|
|
2001-06-22 01:52:54 +04:00
|
|
|
/**
|
|
|
|
* Run an executable command and put the stdout in output.
|
|
|
|
*/
|
|
|
|
std::string output;
|
|
|
|
|
|
|
|
// change to the tests directory and run cmake
|
2001-08-29 23:57:57 +04:00
|
|
|
// use the cmake object instead of calling cmake
|
2001-06-22 01:52:54 +04:00
|
|
|
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
|
2001-12-19 23:26:21 +03:00
|
|
|
std::cout << "Changing into directory: " << binaryDirectory << "\n";
|
2001-08-24 00:00:46 +04:00
|
|
|
cmSystemTools::ChangeDirectory(binaryDirectory);
|
2002-01-23 18:56:21 +03:00
|
|
|
|
2001-08-29 23:57:57 +04:00
|
|
|
std::vector<std::string> args;
|
2002-04-05 18:39:13 +04:00
|
|
|
std::string intdir = ".";
|
|
|
|
#ifdef CMAKE_INTDIR
|
|
|
|
intdir = CMAKE_INTDIR;
|
|
|
|
#endif
|
2002-01-23 18:56:21 +03:00
|
|
|
|
2001-11-15 02:12:22 +03:00
|
|
|
// make sure the same generator is used
|
2001-08-29 23:57:57 +04:00
|
|
|
// use this program as the cmake to be run, it should not
|
|
|
|
// be run that way but the cmake object requires a vailid path
|
2003-05-05 16:42:44 +04:00
|
|
|
std::string cmakeCommand = EXECUTABLE_OUTPUT_PATH;
|
2002-04-05 18:39:13 +04:00
|
|
|
cmakeCommand += "/";
|
|
|
|
cmakeCommand += intdir;
|
|
|
|
cmakeCommand += "/cmake";
|
|
|
|
cmakeCommand += cmSystemTools::GetExecutableExtension();
|
2002-01-23 18:56:21 +03:00
|
|
|
|
2002-04-05 18:39:13 +04:00
|
|
|
std::cout << "*** " << cmakeCommand << "\n";
|
2001-08-29 23:57:57 +04:00
|
|
|
args.push_back(cmakeCommand.c_str());
|
|
|
|
args.push_back(sourceDirectory);
|
2001-11-15 02:12:22 +03:00
|
|
|
std::string generator = "-G";
|
|
|
|
generator += CMAKE_GENERATOR;
|
|
|
|
args.push_back(generator);
|
2002-03-21 00:19:00 +03:00
|
|
|
|
|
|
|
std::vector<std::string> progArgs;
|
2002-03-07 00:30:55 +03:00
|
|
|
if(argc > 6)
|
|
|
|
{
|
2002-03-21 00:19:00 +03:00
|
|
|
if(strcmp(argv[6] , "CMAKE_ARGS") == 0)
|
|
|
|
{
|
|
|
|
for (int j = 7; j < argc ; j++)
|
|
|
|
{
|
|
|
|
args.push_back(argv[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2002-03-07 00:30:55 +03:00
|
|
|
{
|
2002-03-21 00:19:00 +03:00
|
|
|
for(int j = 6; j < argc; j++)
|
|
|
|
{
|
|
|
|
progArgs.push_back(argv[j]);
|
|
|
|
}
|
2002-03-07 00:30:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-19 23:26:21 +03:00
|
|
|
std::cout << "Generating build files...\n";
|
2002-01-23 18:56:21 +03:00
|
|
|
|
|
|
|
cmake cm;
|
2002-09-06 21:06:23 +04:00
|
|
|
if (cm.Run(args) != 0)
|
2001-06-22 01:52:54 +04:00
|
|
|
{
|
2001-06-22 17:27:11 +04:00
|
|
|
std::cerr << "Error: cmake execution failed\n";
|
2001-06-22 01:52:54 +04:00
|
|
|
// return to the original directory
|
|
|
|
cmSystemTools::ChangeDirectory(cwd.c_str());
|
|
|
|
return 1;
|
|
|
|
}
|
2001-12-19 23:26:21 +03:00
|
|
|
std::cout << "Done Generating build files.\n";
|
2003-01-16 01:31:22 +03:00
|
|
|
// if the option ONLY_ONE_CONFIG is passed to the program
|
|
|
|
// only run the config step once
|
|
|
|
if(!onlyOneConfig)
|
2002-01-23 18:56:21 +03:00
|
|
|
{
|
2003-01-16 01:31:22 +03:00
|
|
|
std::cout << "Generating build files (again)...\n";
|
|
|
|
if (cm.Run(args) != 0)
|
|
|
|
{
|
|
|
|
std::cerr << "Error: cmake execution failed\n";
|
|
|
|
// return to the original directory
|
|
|
|
cmSystemTools::ChangeDirectory(cwd.c_str());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
std::cout << "Done Generating build files (again).\n";
|
2002-01-23 18:56:21 +03:00
|
|
|
}
|
2003-01-16 01:31:22 +03:00
|
|
|
|
2002-01-23 18:56:21 +03:00
|
|
|
|
2001-08-29 23:57:57 +04:00
|
|
|
cmListFileCache::GetInstance()->ClearCache();
|
2002-01-23 18:56:21 +03:00
|
|
|
|
2001-06-22 01:52:54 +04:00
|
|
|
// now build the test
|
2001-06-27 17:17:12 +04:00
|
|
|
std::string makeCommand = MAKEPROGRAM;
|
2001-11-22 01:45:01 +03:00
|
|
|
if(makeCommand.size() == 0)
|
|
|
|
{
|
|
|
|
std::cerr << "Error: cmaketest does not have a valid MAKEPROGRAM\n";
|
|
|
|
}
|
2003-07-30 21:11:45 +04:00
|
|
|
|
|
|
|
// Return value for run command;
|
|
|
|
int retVal = 0;
|
|
|
|
int ret = 0;
|
|
|
|
|
2002-02-22 21:38:33 +03:00
|
|
|
makeCommand = cmSystemTools::ConvertToOutputPath(makeCommand.c_str());
|
2003-02-14 19:13:07 +03:00
|
|
|
std::string lowerCaseCommand = cmSystemTools::LowerCase(makeCommand);
|
2001-11-15 02:12:22 +03:00
|
|
|
// if msdev is the make program then do the following
|
2002-02-20 23:26:51 +03:00
|
|
|
// MSDEV 6.0
|
2001-11-15 02:12:22 +03:00
|
|
|
if(lowerCaseCommand.find("msdev") != std::string::npos)
|
2001-10-26 23:42:02 +04:00
|
|
|
{
|
2001-11-15 02:12:22 +03:00
|
|
|
// if there are spaces in the makeCommand, assume a full path
|
|
|
|
// and convert it to a path with no spaces in it as the
|
|
|
|
// RunCommand does not like spaces
|
2001-11-22 01:45:01 +03:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
2001-11-15 02:12:22 +03:00
|
|
|
if(makeCommand.find(' ') != std::string::npos)
|
2001-10-26 23:42:02 +04:00
|
|
|
{
|
2002-04-04 01:14:06 +04:00
|
|
|
cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
|
2001-10-26 23:42:02 +04:00
|
|
|
}
|
2001-11-22 01:45:01 +03:00
|
|
|
#endif
|
2001-11-15 02:12:22 +03:00
|
|
|
makeCommand += " ";
|
2001-12-19 23:26:21 +03:00
|
|
|
makeCommand += projectName;
|
2002-03-29 18:06:30 +03:00
|
|
|
makeCommand += ".dsw /MAKE \"ALL_BUILD - ";
|
2002-04-05 18:39:13 +04:00
|
|
|
makeCommand += intdir + "\" /REBUILD";
|
2001-11-15 02:12:22 +03:00
|
|
|
}
|
2002-02-20 23:26:51 +03:00
|
|
|
// MSDEV 7.0 .NET
|
|
|
|
else if (lowerCaseCommand.find("devenv") != std::string::npos)
|
|
|
|
{
|
2002-02-21 16:43:19 +03:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
2002-02-20 23:26:51 +03:00
|
|
|
if(makeCommand.find(' ') != std::string::npos)
|
|
|
|
{
|
2002-04-04 01:14:06 +04:00
|
|
|
cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
|
2002-02-20 23:26:51 +03:00
|
|
|
}
|
2002-02-21 16:43:19 +03:00
|
|
|
#endif
|
2002-02-20 23:26:51 +03:00
|
|
|
makeCommand += " ";
|
|
|
|
makeCommand += projectName;
|
2002-03-29 18:06:30 +03:00
|
|
|
makeCommand += ".sln /rebuild ";
|
2002-04-05 18:39:13 +04:00
|
|
|
makeCommand += intdir + " /project ALL_BUILD";
|
2002-02-20 23:26:51 +03:00
|
|
|
}
|
|
|
|
// command line make program
|
2001-11-15 02:12:22 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// assume a make sytle program
|
2002-01-18 00:35:26 +03:00
|
|
|
// clean first
|
|
|
|
std::string cleanCommand = makeCommand;
|
|
|
|
cleanCommand += " clean";
|
2002-01-23 18:56:21 +03:00
|
|
|
std::cout << "Running make clean command: " << cleanCommand.c_str() << " ...\n";
|
2003-07-30 21:11:45 +04:00
|
|
|
retVal = 0;
|
|
|
|
if (!cmSystemTools::RunCommand(cleanCommand.c_str(), output, retVal) || retVal)
|
2002-01-18 00:35:26 +03:00
|
|
|
{
|
|
|
|
std::cerr << "Error: " << cleanCommand.c_str() << " execution failed\n";
|
|
|
|
std::cerr << output.c_str() << "\n";
|
|
|
|
// return to the original directory
|
|
|
|
cmSystemTools::ChangeDirectory(cwd.c_str());
|
2003-07-30 21:11:45 +04:00
|
|
|
std::cerr << "Return value: " << retVal << std::endl;
|
2002-01-18 00:35:26 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// now build
|
2001-10-26 23:42:02 +04:00
|
|
|
}
|
2002-01-18 00:35:26 +03:00
|
|
|
|
2001-12-19 23:26:21 +03:00
|
|
|
std::cout << "Running make command: " << makeCommand.c_str() << " ...\n";
|
2003-07-30 21:11:45 +04:00
|
|
|
retVal = 0;
|
|
|
|
if (!cmSystemTools::RunCommand(makeCommand.c_str(), output, retVal))
|
2001-06-22 01:52:54 +04:00
|
|
|
{
|
2001-06-27 17:17:12 +04:00
|
|
|
std::cerr << "Error: " << makeCommand.c_str() << " execution failed\n";
|
2001-06-22 17:27:11 +04:00
|
|
|
std::cerr << output.c_str() << "\n";
|
2001-06-22 01:52:54 +04:00
|
|
|
// return to the original directory
|
|
|
|
cmSystemTools::ChangeDirectory(cwd.c_str());
|
|
|
|
return 1;
|
|
|
|
}
|
2003-07-30 21:11:45 +04:00
|
|
|
if ( retVal )
|
|
|
|
{
|
|
|
|
cmSystemTools::Error("Building of project failed\n");
|
|
|
|
std::cerr << output.c_str() << "\n";
|
|
|
|
// return to the original directory
|
|
|
|
cmSystemTools::ChangeDirectory(cwd.c_str());
|
|
|
|
ret = 1;
|
|
|
|
}
|
2001-06-22 01:52:54 +04:00
|
|
|
|
2001-06-27 17:17:12 +04:00
|
|
|
// now run the compiled test if we can find it
|
|
|
|
// See if the executable exists as written.
|
|
|
|
std::string fullPath;
|
2001-08-24 00:00:46 +04:00
|
|
|
if(cmSystemTools::FileExists(executableName))
|
2001-06-22 01:52:54 +04:00
|
|
|
{
|
2001-08-24 00:00:46 +04:00
|
|
|
fullPath = cmSystemTools::CollapseFullPath(executableName);
|
2001-06-27 17:17:12 +04:00
|
|
|
}
|
2001-08-24 00:00:46 +04:00
|
|
|
std::string tryPath = executableName;
|
2001-06-27 17:17:12 +04:00
|
|
|
tryPath += cmSystemTools::GetExecutableExtension();
|
|
|
|
if(cmSystemTools::FileExists(tryPath.c_str()))
|
|
|
|
{
|
|
|
|
fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
|
|
|
|
}
|
2001-08-29 23:57:57 +04:00
|
|
|
// try the Debug extension
|
2002-04-05 18:39:13 +04:00
|
|
|
tryPath = intdir + "/";
|
2001-08-24 00:00:46 +04:00
|
|
|
tryPath += cmSystemTools::GetFilenameName(executableName);
|
2001-06-27 17:17:12 +04:00
|
|
|
if(cmSystemTools::FileExists(tryPath.c_str()))
|
|
|
|
{
|
|
|
|
fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
|
|
|
|
}
|
|
|
|
tryPath += cmSystemTools::GetExecutableExtension();
|
|
|
|
if(cmSystemTools::FileExists(tryPath.c_str()))
|
|
|
|
{
|
|
|
|
fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
|
|
|
|
}
|
2001-08-24 00:00:46 +04:00
|
|
|
tryPath = executableDirectory;
|
|
|
|
tryPath += "/";
|
|
|
|
tryPath += executableName;
|
|
|
|
tryPath += cmSystemTools::GetExecutableExtension();
|
|
|
|
if(cmSystemTools::FileExists(tryPath.c_str()))
|
|
|
|
{
|
|
|
|
fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
|
|
|
|
}
|
|
|
|
tryPath = executableDirectory;
|
2002-03-29 18:06:30 +03:00
|
|
|
tryPath += "/";
|
2002-04-05 18:39:13 +04:00
|
|
|
tryPath += intdir + "/";
|
2001-08-24 00:00:46 +04:00
|
|
|
tryPath += executableName;
|
|
|
|
tryPath += cmSystemTools::GetExecutableExtension();
|
|
|
|
if(cmSystemTools::FileExists(tryPath.c_str()))
|
|
|
|
{
|
|
|
|
fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
|
|
|
|
}
|
2001-10-03 23:49:52 +04:00
|
|
|
if(!cmSystemTools::FileExists(fullPath.c_str()))
|
|
|
|
{
|
|
|
|
std::cerr << "Could not find path to executable, perhaps it was not built: " <<
|
|
|
|
executableName << "\n";
|
|
|
|
std::cerr << "Error: " << fullPath.c_str() << " execution failed\n";
|
|
|
|
// return to the original directory
|
|
|
|
cmSystemTools::ChangeDirectory(cwd.c_str());
|
|
|
|
return 1;
|
|
|
|
}
|
2002-02-22 21:38:33 +03:00
|
|
|
fullPath = cmSystemTools::ConvertToOutputPath(fullPath.c_str());
|
2002-03-21 00:19:00 +03:00
|
|
|
for(std::vector<std::string>::iterator p = progArgs.begin();
|
|
|
|
p != progArgs.end(); ++p)
|
|
|
|
{
|
|
|
|
fullPath += " ";
|
|
|
|
fullPath += *p;
|
|
|
|
}
|
2001-12-19 23:26:21 +03:00
|
|
|
std::cout << "Running test executable: " << fullPath.c_str() << "\n";
|
2003-07-30 21:11:45 +04:00
|
|
|
retVal = 0;
|
|
|
|
if (!cmSystemTools::RunCommand(fullPath.c_str(), output, retVal, 0, true))
|
2001-06-27 17:17:12 +04:00
|
|
|
{
|
|
|
|
std::cerr << "Error: " << fullPath.c_str() << " execution failed\n";
|
2001-06-22 01:52:54 +04:00
|
|
|
// return to the original directory
|
|
|
|
cmSystemTools::ChangeDirectory(cwd.c_str());
|
|
|
|
return 1;
|
2003-07-30 21:11:45 +04:00
|
|
|
}
|
2002-03-26 20:38:18 +03:00
|
|
|
std::cout << output << "\n";
|
2001-06-22 01:52:54 +04:00
|
|
|
// return to the original directory
|
|
|
|
cmSystemTools::ChangeDirectory(cwd.c_str());
|
2003-07-30 21:11:45 +04:00
|
|
|
if(retVal)
|
2002-01-21 18:38:42 +03:00
|
|
|
{
|
|
|
|
cmSystemTools::Error("test executable ", fullPath.c_str(),
|
|
|
|
"returned a non-zero value");
|
2003-07-30 21:11:45 +04:00
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
if ( ret )
|
|
|
|
{
|
|
|
|
cmSystemTools::Error("Test failed");
|
2002-01-21 18:38:42 +03:00
|
|
|
}
|
|
|
|
return ret;
|
2001-06-22 01:52:54 +04:00
|
|
|
}
|