From 5bbae885693f74b50b1f4265d8ab32fe65288194 Mon Sep 17 00:00:00 2001 From: Andy Cedilnik Date: Fri, 15 Mar 2002 15:42:59 -0500 Subject: [PATCH] Add ccommand for executing commands on the system, so by using ADD_CUSTOM_COMMAND, you can make rules to do some system commands during build. Currently supported commands are copy and remove. Others will follow. --- Source/CMakeLists.txt | 2 + Source/CMakeSetup.dsw | 18 +++++++ Source/ccommand.cxx | 61 +++++++++++++++++++++++ Source/ccommand.dsp | 109 ++++++++++++++++++++++++++++++++++++++++++ Source/cmake.cxx | 17 +++++++ 5 files changed, 207 insertions(+) create mode 100644 Source/ccommand.cxx create mode 100644 Source/ccommand.dsp diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 1d658f1eb..a18d37634 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -97,6 +97,7 @@ ADD_EXECUTABLE(cmake cmakemain) ADD_EXECUTABLE(DumpDocumentation cmDumpDocumentation) ADD_EXECUTABLE(ctest ctest.cxx cmSystemTools.cxx cmRegularExpression.cxx) +ADD_EXECUTABLE(ccommand ccommand.cxx cmSystemTools.cxx cmMakefile.cxx) CONFIGURE_FILE( ${CMake_SOURCE_DIR}/Source/cmaketest.h.in @@ -149,5 +150,6 @@ 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/CMakeSetup.dsw b/Source/CMakeSetup.dsw index 7d2d8cfff..6f9a26016 100644 --- a/Source/CMakeSetup.dsw +++ b/Source/CMakeSetup.dsw @@ -32,6 +32,9 @@ Package=<4> Begin Project Dependency Project_Dep_Name ctest End Project Dependency + Begin Project Dependency + Project_Dep_Name ccommand + End Project Dependency }}} ############################################################################### @@ -81,6 +84,21 @@ Package=<4> ############################################################################### +Project: "ccommand"=.\ccommand.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name CMakeLib + End Project Dependency +}}} + +############################################################################### + Global: Package=<5> diff --git a/Source/ccommand.cxx b/Source/ccommand.cxx new file mode 100644 index 000000000..fc67aadc4 --- /dev/null +++ b/Source/ccommand.cxx @@ -0,0 +1,61 @@ +/*========================================================================= + + Program: Insight Segmentation & Registration Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision$ + + Copyright (c) 2002 Insight Consortium. All rights reserved. + See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. + + 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 "cmMakefile.h" +#include "cmSystemTools.h" + +void CMakeCommandUsage(const char* program) +{ + std::strstream errorStream; + + errorStream << "cmake version " << cmMakefile::GetMajorVersion() + << "." << cmMakefile::GetMinorVersion() << "\n"; + errorStream << "Usage: " << program << " [command] [arguments ...]\n" + << " Available commands: \n" + << " copy file1 file2 - copy first file to the second one\n" + << " remove file1 file2 ... - remove the file(s)\n"; + errorStream << std::ends; + cmSystemTools::Error(errorStream.str()); +} + +int main(int ac, char** av) +{ + std::vector args; + for(int i =0; i < ac; ++i) + { + args.push_back(av[i]); + } + + if ( args.size() > 1 ) + { + if ( args[1] == "copy" && args.size() == 4 ) + { + cmSystemTools::cmCopyFile(args[2].c_str(), args[3].c_str()); + return 0; + } + if ( args[1] == "remove" && args.size() > 2 ) + { + for ( int cc = 2; cc < args.size(); cc ++ ) + { + cmSystemTools::RemoveFile(args[cc].c_str()); + } + return 0; + } + } + ::CMakeCommandUsage(args[0].c_str()); + return 1; +} diff --git a/Source/ccommand.dsp b/Source/ccommand.dsp new file mode 100644 index 000000000..b52944da2 --- /dev/null +++ b/Source/ccommand.dsp @@ -0,0 +1,109 @@ +# Microsoft Developer Studio Project File - Name="ccommand" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=ccommand - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "ccommand.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "ccommand.mak" CFG="ccommand - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "ccommand - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "ccommand - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "ccommand - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /pdb:"ccommand.pdb" /machine:I386 /out:"ccommand.exe" +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "ccommand - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "ccommand___Win32_Debug" +# PROP BASE Intermediate_Dir "ccommand___Win32_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "ccommand___Win32_Debug" +# PROP Intermediate_Dir "ccommand___Win32_Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /pdb:"ccommand.pdb" /debug /machine:I386 /out:"ccommand.exe" /pdbtype:sept +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "ccommand - Win32 Release" +# Name "ccommand - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\ccommand.cxx +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\ccommand.h +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff --git a/Source/cmake.cxx b/Source/cmake.cxx index c2cec36b6..e2a1dd8ab 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -252,6 +252,23 @@ void cmake::AddCMakePaths(const std::vector& args) cmSystemTools::EscapeSpaces(cMakeSelf.c_str()).c_str(), "Path to CMake executable.", cmCacheManager::INTERNAL); + + // Find ccommand + std::string cCommand = cmSystemTools::GetFilenamePath(cMakeSelf) + + "/ccommand" + cmSystemTools::GetFilenameExtension(cMakeSelf); + if( !cmSystemTools::FileExists(cMakeSelf.c_str())) + { + cmSystemTools::Error("CMAKE can not find the command line program " + "ccommand. Attempted path: ", cMakeSelf.c_str()); + return; + } + + // Save the value in the cache + cmCacheManager::GetInstance()->AddCacheEntry + ("CCOMMAND_COMMAND", + cmSystemTools::EscapeSpaces(cCommand.c_str()).c_str(), + "Path to CMakeCommand executable.", + cmCacheManager::INTERNAL); // do CMAKE_ROOT, look for the environment variable first std::string cMakeRoot;