diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index f21807b6a..815f99403 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -79,10 +79,7 @@ LINK_DIRECTORIES(${CMake_BINARY_DIR}/Source) ADD_EXECUTABLE(cmake cmakemain.cxx) ADD_EXECUTABLE(DumpDocumentation cmDumpDocumentation) - ADD_EXECUTABLE(ctest ctest.cxx cmSystemTools.cxx cmRegularExpression.cxx) -ADD_EXECUTABLE(ccommand ccommand.cxx cmSystemTools.cxx cmMakefile.cxx) - IF (UNIX) INCLUDE (${CMake_SOURCE_DIR}/Modules/FindCurses.cmake OPTIONAL) @@ -214,6 +211,5 @@ INCLUDE (${CMAKE_SOURCE_DIR}/Source/LocalUserOptions.cmake OPTIONAL) INSTALL_TARGETS(/bin cmake) INSTALL_TARGETS(/bin ctest) -INSTALL_TARGETS(/bin ccommand) INSTALL_TARGETS(/bin cmaketest) diff --git a/Source/cmBorlandMakefileGenerator.cxx b/Source/cmBorlandMakefileGenerator.cxx index c73d27b3f..b0643643e 100644 --- a/Source/cmBorlandMakefileGenerator.cxx +++ b/Source/cmBorlandMakefileGenerator.cxx @@ -102,8 +102,6 @@ void cmBorlandMakefileGenerator::OutputMakeVariables(std::ostream& fout) std::string replaceVars = variables; m_Makefile->ExpandVariablesInString(replaceVars); - std::string ccommand = m_Makefile->GetDefinition("CCOMMAND_COMMAND"); - fout << "RM = " << this->ConvertToOutputPath(ccommand.c_str()) << " remove -f\n"; std::string ccompiler = m_Makefile->GetDefinition("CMAKE_C_COMPILER"); fout << "CMAKE_C_COMPILER = " << this->ConvertToOutputPath(ccompiler.c_str()) @@ -123,6 +121,7 @@ void cmBorlandMakefileGenerator::OutputMakeVariables(std::ostream& fout) std::string cmakecommand = m_Makefile->GetDefinition("CMAKE_COMMAND"); fout << "CMAKE_COMMAND = " << this->ShortPath(cmakecommand.c_str()) << "\n"; + fout << "RM = " << this->ShortPath(cmakecommand.c_str()) << " -E remove -f\n"; fout << replaceVars.c_str(); fout << "CMAKE_CURRENT_SOURCE = " diff --git a/Source/cmNMakeMakefileGenerator.cxx b/Source/cmNMakeMakefileGenerator.cxx index cdb42b17e..14222ad1a 100644 --- a/Source/cmNMakeMakefileGenerator.cxx +++ b/Source/cmNMakeMakefileGenerator.cxx @@ -170,8 +170,6 @@ void cmNMakeMakefileGenerator::OutputMakeVariables(std::ostream& fout) std::string replaceVars = variables; m_Makefile->ExpandVariablesInString(replaceVars); fout << replaceVars.c_str(); - std::string ccommand = m_Makefile->GetDefinition("CCOMMAND_COMMAND"); - fout << "RM = " << this->ShortPath(ccommand.c_str()) << " remove -f\n"; std::string ccompiler = m_Makefile->GetDefinition("CMAKE_C_COMPILER"); fout << "CMAKE_C_COMPILER = " << this->ShortPath(ccompiler.c_str()) << "\n"; @@ -191,6 +189,7 @@ void cmNMakeMakefileGenerator::OutputMakeVariables(std::ostream& fout) std::string cmakecommand = m_Makefile->GetDefinition("CMAKE_COMMAND"); fout << "CMAKE_COMMAND = " << this->ShortPath(cmakecommand.c_str()) << "\n"; + fout << "RM = " << this->ShortPath(cmakecommand.c_str()) << " -E remove -f\n"; if(m_Makefile->GetDefinition("CMAKE_EDIT_COMMAND")) { diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 6fef8499a..a24ddde40 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -15,6 +15,7 @@ =========================================================================*/ #include "cmake.h" +#include "time.h" #include "cmCacheManager.h" // include the generator @@ -230,8 +231,15 @@ void cmake::AddCMakePaths(const std::vector& args) if(!cmSystemTools::FileExists(cMakeSelf.c_str())) { #ifdef CMAKE_BUILD_DIR - cMakeSelf = CMAKE_BUILD_DIR; - cMakeSelf += "/Source/cmake"; + std::string intdir = "."; +#ifdef CMAKE_INTDIR + intdir = CMAKE_INTDIR; +#endif + cMakeSelf = CMAKE_BUILD_DIR; + cMakeSelf += "/Source/"; + cMakeSelf += intdir; + cMakeSelf += "/cmake"; + cMakeSelf += cmSystemTools::GetExecutableExtension(); #endif } #ifdef CMAKE_PREFIX @@ -251,17 +259,6 @@ void cmake::AddCMakePaths(const std::vector& args) ("CMAKE_COMMAND",cMakeSelf.c_str(), "Path to CMake executable.", cmCacheManager::INTERNAL); - // Find ccommand - std::string cCommand = cmSystemTools::GetFilenamePath(cMakeSelf) + - "/ccommand" + cmSystemTools::GetFilenameExtension(cMakeSelf); - if( cmSystemTools::FileExists(cCommand.c_str())) - { - // Save the value in the cache - cmCacheManager::GetInstance()->AddCacheEntry - ("CCOMMAND_COMMAND",cCommand.c_str(), - "Path to CMakeCommand executable.", cmCacheManager::INTERNAL); - } - // Find and save the command to edit the cache std::string editCacheCommand = cmSystemTools::GetFilenamePath(cMakeSelf) + "/ccmake" + cmSystemTools::GetFilenameExtension(cMakeSelf); @@ -519,3 +516,108 @@ int cmake::Generate(const std::vector& args, bool buildMakefiles) return 0; } + +void CMakeCommandUsage(const char* program) +{ + std::strstream errorStream; + + errorStream + << "cmake version " << cmMakefile::GetMajorVersion() + << "." << cmMakefile::GetMinorVersion() << "\n"; + + errorStream + << "Usage: " << program << " -E [command] [arguments ...]\n" + << "Available commands: \n" + << " copy file destination - copy file to destination (either file or directory)\n" + << " remove file1 file2 ... - remove the file(s)\n" + << " time command [args] ... - run command and return elapsed time\n" +#if defined(_WIN32) && !defined(__CYGWIN__) + << " write_regv key value - write registry value\n" + << " delete_regv key - delete registry value\n" +#endif + << std::ends; + + cmSystemTools::Error(errorStream.str()); +} + +int cmake::CMakeCommand(std::vector& args) +{ + if (args.size() > 1) + { + // Copy file + if (args[1] == "copy" && args.size() == 4) + { + cmSystemTools::cmCopyFile(args[2].c_str(), args[3].c_str()); + return cmSystemTools::GetErrorOccuredFlag(); + } + + // Remove file + else if (args[1] == "remove" && args.size() > 2) + { + for (std::string::size_type cc = 2; cc < args.size(); cc ++) + { + if(args[cc] != "-f") + { + if(args[cc] == "\\-f") + { + args[cc] = "-f"; + } + cmSystemTools::RemoveFile(args[cc].c_str()); + } + } + return 0; + } + + // Clock command + else if (args[1] == "time" && args.size() > 2) + { + std::string command = args[2]; + std::string output; + for (std::string::size_type cc = 3; cc < args.size(); cc ++) + { + command += " "; + command += args[cc]; + } + + clock_t clock_start, clock_finish; + time_t time_start, time_finish; + + time(&time_start); + clock_start = clock(); + + cmSystemTools::RunCommand(command.c_str(), output, 0, true); + + clock_finish = clock(); + time(&time_finish); + + std::cout << output.c_str(); + + double clocks_per_sec = (double)CLOCKS_PER_SEC; + std::cout << "Elapsed time: " + << (long)(time_finish - time_start) << " s. (time)" + << ", " + << (double)(clock_finish - clock_start) / clocks_per_sec + << " s. (clock)" + << "\n"; + return 0; + } + +#if defined(_WIN32) && !defined(__CYGWIN__) + // Write registry value + else if (args[1] == "write_regv" && args.size() > 3) + { + return cmSystemTools::WriteRegistryValue(args[2].c_str(), + args[3].c_str()) ? 0 : 1; + } + + // Delete registry value + else if (args[1] == "delete_regv" && args.size() > 2) + { + return cmSystemTools::DeleteRegistryValue(args[2].c_str()) ? 0 : 1; + } +#endif + } + + ::CMakeCommandUsage(args[0].c_str()); + return 1; +} diff --git a/Source/cmake.h b/Source/cmake.h index 53203e338..86c9f7158 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -41,6 +41,12 @@ class cmake */ int Generate(const std::vector&, bool buildMakefiles = true); + /** + * Execute commands during the build process. Supports options such + * as echo, remove file etc. + */ + static int CMakeCommand(std::vector&); + ///! Parse command line arguments void SetArgs(cmMakefile& builder, const std::vector&); ///! Parse command line arguments that might set cache values diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 710284dc0..e08e19f59 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -21,6 +21,7 @@ int main(int ac, char** av) { bool wiz = false; + bool command = false; std::vector args; for(int i =0; i < ac; ++i) { @@ -30,18 +31,31 @@ int main(int ac, char** av) } else { - args.push_back(av[i]); + if (strcmp(av[i], "-E") == 0) + { + command = true; + } + else + { + args.push_back(av[i]); + } } } - if(!wiz) + + if(command) { - cmake cm; - int ret = cm.Generate(args); - cmMakefileGenerator::UnRegisterGenerators(); + int ret = cmake::CMakeCommand(args); return ret; } - cmakewizard wizard; - wizard.RunWizard(args); + if (wiz) + { + cmakewizard wizard; + wizard.RunWizard(args); + cmMakefileGenerator::UnRegisterGenerators(); + return 0; + } + cmake cm; + int ret = cm.Generate(args); cmMakefileGenerator::UnRegisterGenerators(); - return 0; + return ret; } diff --git a/Tests/Complex/CMakeLists.txt b/Tests/Complex/CMakeLists.txt index 7bed23ec0..58a128123 100644 --- a/Tests/Complex/CMakeLists.txt +++ b/Tests/Complex/CMakeLists.txt @@ -137,12 +137,12 @@ IF (WIN32) ${Complex_SOURCE_DIR}/Library/dummy "${dir}/${file}" COPYONLY IMMEDIATE) - EXEC_PROGRAM(${CCOMMAND_COMMAND} ARGS "write_regv \"${hkey}\" \"${dir}\"") + EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E write_regv \"${hkey}\" \"${dir}\"") FIND_PATH(REGISTRY_TEST_PATH ${file} "[${hkey}]" DOC "Registry_Test_Path") - EXEC_PROGRAM(${CCOMMAND_COMMAND} ARGS "delete_regv \"${hkey}\"") - EXEC_PROGRAM(${CCOMMAND_COMMAND} ARGS "remove \"${dir}/${file}\"") + EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E delete_regv \"${hkey}\"") + EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E remove \"${dir}/${file}\"") ENDIF (NOT UNIX) ENDIF (WIN32) diff --git a/Tests/ComplexOneConfig/CMakeLists.txt b/Tests/ComplexOneConfig/CMakeLists.txt index 7bed23ec0..58a128123 100644 --- a/Tests/ComplexOneConfig/CMakeLists.txt +++ b/Tests/ComplexOneConfig/CMakeLists.txt @@ -137,12 +137,12 @@ IF (WIN32) ${Complex_SOURCE_DIR}/Library/dummy "${dir}/${file}" COPYONLY IMMEDIATE) - EXEC_PROGRAM(${CCOMMAND_COMMAND} ARGS "write_regv \"${hkey}\" \"${dir}\"") + EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E write_regv \"${hkey}\" \"${dir}\"") FIND_PATH(REGISTRY_TEST_PATH ${file} "[${hkey}]" DOC "Registry_Test_Path") - EXEC_PROGRAM(${CCOMMAND_COMMAND} ARGS "delete_regv \"${hkey}\"") - EXEC_PROGRAM(${CCOMMAND_COMMAND} ARGS "remove \"${dir}/${file}\"") + EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E delete_regv \"${hkey}\"") + EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E remove \"${dir}/${file}\"") ENDIF (NOT UNIX) ENDIF (WIN32) diff --git a/Tests/ComplexRelativePaths/CMakeLists.txt b/Tests/ComplexRelativePaths/CMakeLists.txt index 7bed23ec0..58a128123 100644 --- a/Tests/ComplexRelativePaths/CMakeLists.txt +++ b/Tests/ComplexRelativePaths/CMakeLists.txt @@ -137,12 +137,12 @@ IF (WIN32) ${Complex_SOURCE_DIR}/Library/dummy "${dir}/${file}" COPYONLY IMMEDIATE) - EXEC_PROGRAM(${CCOMMAND_COMMAND} ARGS "write_regv \"${hkey}\" \"${dir}\"") + EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E write_regv \"${hkey}\" \"${dir}\"") FIND_PATH(REGISTRY_TEST_PATH ${file} "[${hkey}]" DOC "Registry_Test_Path") - EXEC_PROGRAM(${CCOMMAND_COMMAND} ARGS "delete_regv \"${hkey}\"") - EXEC_PROGRAM(${CCOMMAND_COMMAND} ARGS "remove \"${dir}/${file}\"") + EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E delete_regv \"${hkey}\"") + EXEC_PROGRAM(${CMAKE_COMMAND} ARGS "-E remove \"${dir}/${file}\"") ENDIF (NOT UNIX) ENDIF (WIN32)