View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0015694CMakeCMakepublic2015-08-12 17:322016-01-04 11:52
ReporterScott 
Assigned To 
PriorityhighSeveritymajorReproducibilityalways
StatusclosedResolutionno change required 
PlatformVS 2013OSWindowsOS Version8.1
Product VersionCMake 3.3 
Target VersionFixed in Version 
Summary0015694: STRING(LENGTH ...) fails when loading a file larger than 17 KB
DescriptionAttached 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 ReproduceUsing 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 InformationIt fails on 3.3 and 2.8.12.2 as well.
TagsNo tags attached.
Attached Files? file icon makeheader.cmake [^] (1,069 bytes) 2015-08-12 17:32

 Relationships

  Notes
(0039276)
Brad King (manager)
2015-08-13 09:02

> STRING(LENGTH ${FILEDATA} READLEN)

When FILEDATA is empty this will expand to

 STRING(LENGTH READLEN)

which is the incorrect number of arguments. You need to quote the argument:

 STRING(LENGTH "${FILEDATA}" READLEN)

See the cmake-language(7) manual for details:

 http://www.cmake.org/cmake/help/v3.3/manual/cmake-language.7.html#command-arguments [^]
(0039277)
Scott (reporter)
2015-08-13 10:21

You are right, it works now. Thanks
(0040114)
Robert Maynard (manager)
2016-01-04 11:52

Closing resolved issues that have not been updated in more than 4 months.

 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
2015-08-13 09:02 Brad King Note Added: 0039276
2015-08-13 09:02 Brad King Status new => resolved
2015-08-13 09:02 Brad King Resolution open => no change required
2015-08-13 10:21 Scott Note Added: 0039277
2016-01-04 11:52 Robert Maynard Note Added: 0040114
2016-01-04 11:52 Robert Maynard Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team