[cmake-developers] [CMake 0015694]: STRING(LENGTH ...) fails when loading a file larger than 17 KB

Mantis Bug Tracker mantis at public.kitware.com
Wed Aug 12 17:32:50 EDT 2015


The following issue has been SUBMITTED. 
====================================================================== 
http://public.kitware.com/Bug/view.php?id=15694 
====================================================================== 
Reported By:                Scott
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   15694
Category:                   CMake
Reproducibility:            always
Severity:                   major
Priority:                   high
Status:                     new
====================================================================== 
Date Submitted:             2015-08-12 17:32 EDT
Last Modified:              2015-08-12 17:32 EDT
====================================================================== 
Summary:                    STRING(LENGTH ...) fails when loading a file larger
than 17 KB
Description: 
Attached is our cmake command (makeheader.cmake), which loads in a text file and
creates a C++ header during the compiler phase.

It works great until files larger than 17 KBs are used.  The error it produces
is very strange, it fails to return the size of the FILEDATA string, which
should never be more than 40 bytes in size.

while(NOT DONE)
	FILE(READ ${FILENAME} FILEDATA LIMIT 20 OFFSET ${CURRENT_OFFSET} HEX)
	STRING(LENGTH ${FILEDATA} READLEN)

Steps to Reproduce: 
Using this code in a CMake project for VS 2013 x64:

foreach(COMPILED_IN_FILE ManualPages.txt)
	get_filename_component(BASENAME ${COMPILED_IN_FILE} NAME_WE)
	get_filename_component(EXT ${COMPILED_IN_FILE} EXT)
	string(SUBSTRING ${EXT} 1 1 CAMEL_CHAR)
	string(TOUPPER ${CAMEL_CHAR} CAMEL_CHAR)
	string(SUBSTRING ${EXT} 2 -1 EXT)
	set(OUT_HEADER "${BASENAME}${CAMEL_CHAR}${EXT}.h")
	set(OUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/${OUT_HEADER})
	set(IN_PATH ${CMAKE_SOURCE_DIR}/NwConsole/${COMPILED_IN_FILE})
	
	list(APPEND HEADER_FILES ${OUT_PATH})
	
	add_custom_command(OUTPUT ${OUT_PATH}
		COMMAND ${CMAKE_COMMAND} 
			-DFILENAME=${IN_PATH}
			-DDESTINATION=${OUT_PATH}
			-P "${CMAKE_SOURCE_DIR}/CMake/makeheader.cmake"
		MAIN_DEPENDENCY ${IN_PATH}
		DEPENDS ${CMAKE_SOURCE_DIR}/CMake/makeheader.cmake)
endforeach()

Use any text file you have that is more than 17 KBs in size.  Even though the
string read in from the file should never be more than 40 bytes, it eventually
returns this error:

3>  Generating ManualPagesTxt.h
3>  CMake Error at C:/Dev/ngtrunk/src/CMake/makeheader.cmake:18 (STRING):
3>    string sub-command LENGTH requires two arguments.
3>  
3>  
3>C:\Program Files
(x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(170,5): error
MSB6006: "cmd.exe" exited with code 1.

Additional Information: 
It fails on 3.3 and 2.8.12.2 as well.
====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2015-08-12 17:32 Scott          New Issue                                    
2015-08-12 17:32 Scott          File Added: makeheader.cmake                    
======================================================================



More information about the cmake-developers mailing list