diff options
author | Alexander Neundorf <neundorf@kde.org> | 2007-05-25 20:46:50 (GMT) |
---|---|---|
committer | Alexander Neundorf <neundorf@kde.org> | 2007-05-25 20:46:50 (GMT) |
commit | 55f11b348bdfd94f28c95cea2e72a79fa1a1fc5d (patch) | |
tree | 550118d0573f523740fad14fdd0c55875aec5fa5 | |
parent | d6f779a9b0abf2a00119c9ab9ab73e360ba1bf7f (diff) | |
download | CMake-55f11b348bdfd94f28c95cea2e72a79fa1a1fc5d.zip CMake-55f11b348bdfd94f28c95cea2e72a79fa1a1fc5d.tar.gz CMake-55f11b348bdfd94f28c95cea2e72a79fa1a1fc5d.tar.bz2 |
ENH: add option to FILE(STRINGS NO_HEX_CONVERSION) to disable automatic
conversion of hex and srec files to binary.
Without this automatic conversion, everywhere where a compiled file is parsed for strings the
a file(HEX2BIN somefile binfile) command has to be added otherwise it will
not work for these compilers. I tried this with DetermineCompiler and
CheckTypeSize and nobody will do this except the users who work with such
compilers. For them it will break if they don't add this conversion command
in all these places.
If FILE(STRINGS) is used with a text file, it
will in most cases still work as expected, since it will only convert hex
and srec files. If a user actually wants to get text out of hex files, he
knows what he's doing and will see the hint in the documentation.
Anyway, it should work without having to create a temporary file, will work
on this later.
Alex
-rw-r--r-- | Modules/CMakeDetermineCompilerId.cmake | 2 | ||||
-rw-r--r-- | Source/cmFileCommand.cxx | 75 | ||||
-rw-r--r-- | Source/cmFileCommand.h | 13 |
3 files changed, 80 insertions, 10 deletions
diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index f0fce8f..e30db35 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -76,6 +76,8 @@ MACRO(CMAKE_DETERMINE_COMPILER_ID lang flagvar src) "${CMAKE_${lang}_COMPILER_ID_EXE}\"\n\n") # only check if we don't have it yet IF(NOT CMAKE_${lang}_COMPILER_ID) +# SET(CMAKE_${lang}_COMPILER_ID_EXE "${CMAKE_${lang}_COMPILER_ID_DIR}/ConvertedToBinary") +# FILE(HEX_TO_BIN "${CMAKE_${lang}_COMPILER_ID_EXE_TRY}" "${CMAKE_${lang}_COMPILER_ID_EXE}") # Read the compiler identification string from the executable file. FILE(STRINGS ${CMAKE_${lang}_COMPILER_ID_EXE} CMAKE_${lang}_COMPILER_ID_STRINGS LIMIT_COUNT 2 REGEX "INFO:") diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 5b3390d..f75ed79 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -76,6 +76,10 @@ bool cmFileCommand::InitialPass(std::vector<std::string> const& args) { return this->HandleStringsCommand(args); } +/* else if ( subCommand == "HEX_TO_BIN" ) + { + return this->HandleHex2BinCommand(args); + }*/ else if ( subCommand == "GLOB" ) { return this->HandleGlobCommand(args, false); @@ -258,6 +262,53 @@ bool cmFileCommand::HandleReadCommand(std::vector<std::string> const& args) } //---------------------------------------------------------------------------- +/*bool cmFileCommand::HandleHex2BinCommand(std::vector<std::string> const& args) +{ + if(args.size() != 3) + { + this->SetError("HEX_TO_BIN requires an input and an output file name"); + return false; + } + // Get the file to read. + std::string inFileName = args[1]; + if(!cmsys::SystemTools::FileIsFullPath(inFileName.c_str())) + { + inFileName = this->Makefile->GetCurrentDirectory(); + inFileName += "/" + args[1]; + } + + // Get the file to write. + std::string outFileName = args[2]; + if(!cmsys::SystemTools::FileIsFullPath(outFileName.c_str())) + { + outFileName = this->Makefile->GetCurrentDirectory(); + outFileName += "/" + args[2]; + } + + if ( !this->Makefile->CanIWriteThisFile(outFileName.c_str()) ) + { + std::string e + = "attempted to write a file: " + outFileName + + " into a source directory."; + this->SetError(e.c_str()); + cmSystemTools::SetFatalErrorOccured(); + return false; + } + + std::string dir = cmSystemTools::GetFilenamePath(outFileName); + cmSystemTools::MakeDirectory(dir.c_str()); + + bool success = cmHexFileConverter::TryConvert(inFileName.c_str(), + outFileName.c_str()); + if (!success) + { + success = cmSystemTools::CopyFileAlways(inFileName.c_str(), + outFileName.c_str()); + } + return success; +} */ + +//---------------------------------------------------------------------------- bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args) { if(args.size() < 3) @@ -294,6 +345,7 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args) cmsys::RegularExpression regex; bool have_regex = false; bool newline_consume = false; + bool hex_conversion_enabled = true; int arg_mode = arg_none; for(unsigned int i=3; i < args.size(); ++i) { @@ -326,6 +378,11 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args) newline_consume = true; arg_mode = arg_none; } + else if(args[i] == "NO_HEX_CONVERSION") + { + hex_conversion_enabled = false; + arg_mode = arg_none; + } else if(arg_mode == arg_limit_input) { if(sscanf(args[i].c_str(), "%d", &limit_input) != 1 || @@ -416,15 +473,19 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args) return false; } } - - std::string binaryFileName = this->Makefile->GetCurrentOutputDirectory(); - binaryFileName += cmake::GetCMakeFilesDirectory(); - binaryFileName += "/FileCommandStringsBinaryFile"; - if (cmHexFileConverter::TryConvert(fileName.c_str(), binaryFileName.c_str())) + + if (hex_conversion_enabled) { - fileName = binaryFileName; + // TODO: should work without temp file, but just on a memory buffer + std::string binaryFileName = this->Makefile->GetCurrentOutputDirectory(); + binaryFileName += cmake::GetCMakeFilesDirectory(); + binaryFileName += "/FileCommandStringsBinaryFile"; + if (cmHexFileConverter::TryConvert(fileName.c_str(), binaryFileName.c_str())) + { + fileName = binaryFileName; + } } - + // Open the specified file. #if defined(_WIN32) || defined(__CYGWIN__) std::ifstream fin(fileName.c_str(), std::ios::in | std::ios::binary); diff --git a/Source/cmFileCommand.h b/Source/cmFileCommand.h index 5868725..029e698 100644 --- a/Source/cmFileCommand.h +++ b/Source/cmFileCommand.h @@ -72,7 +72,9 @@ public: " FILE(STRINGS filename variable [LIMIT_COUNT num]\n" " [LIMIT_INPUT numBytes] [LIMIT_OUTPUT numBytes]\n" " [LENGTH_MINIMUM numBytes] [LENGTH_MAXIMUM numBytes]\n" - " [NEWLINE_CONSUME] [REGEX regex])\n" + " [NEWLINE_CONSUME] [REGEX regex]\n" + " [NO_HEX_CONVERSION])\n" + " FILE(HEX_TO_BIN inputfile outputfile)\n" " FILE(GLOB variable [RELATIVE path] [globbing expressions]...)\n" " FILE(GLOB_RECURSE variable [RELATIVE path] \n" " [globbing expressions]...)\n" @@ -93,10 +95,14 @@ public: "want to generate input files to CMake.\n" "READ will read the content of a file and store it into the " "variable.\n" - "STRINGS will parse a list of ASCII strings from a binary file and " + "STRINGS will parse a list of ASCII strings from a file and " "store it in a variable. Binary data in the file are ignored. Carriage " "return (CR) characters are ignored. It works also for Intel Hex and " - "Motorola S-record files.\n " + "Motorola S-record files, which are automatically converted to binary " + "format when reading them. Disable this using NO_HEX_CONVERSION.\n " +/* "HEX_TO_BIN will convert an Intel hex file or Motorola S-record file " + "to a binary file. If the input file is no such file it will simply " + "be copied. \n"*/ "LIMIT_COUNT sets the maximum number of strings to return. " "LIMIT_INPUT sets the maximum number of bytes to read from " "the input file. " @@ -147,6 +153,7 @@ protected: bool HandleWriteCommand(std::vector<std::string> const& args, bool append); bool HandleReadCommand(std::vector<std::string> const& args); bool HandleStringsCommand(std::vector<std::string> const& args); +// bool HandleHex2BinCommand(std::vector<std::string> const& args); bool HandleGlobCommand(std::vector<std::string> const& args, bool recurse); bool HandleMakeDirectoryCommand(std::vector<std::string> const& args); |