View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0014935CMakeCMakepublic2014-05-26 04:562016-06-10 14:31
Reporterth.thielemann 
Assigned ToKitware Robot 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionmoved 
PlatformVmware Player 6.0.2 on Win7OSUbuntuOS Version12.04 LTS
Product Version 
Target VersionFixed in Version 
Summary0014935: file(APPEND "message...") writes nulls into file
DescriptionI am using a shared folder between my Win7 and VmWare with Ubuntu 12.04.
Fore some reasons I write out some properties into a file during cmake run.
First line with file(WRITE "key=value"). All others with file(APPEND ...)
Sucessful tested on Windows, Linux using the local file system. But if I share a folder between Windows and Linux, the result is "00 00 00 00 ... 00 The appended message".
Steps To ReproduceCreate the environment Win7 + VmWare + Ubuntu 12.04 LTS + shared folder.

Here is my function

function(write_env_script Mode EnvKey EnvValue)
    # Possible option flags
    list(FIND ARGN EXTEND IsExtend)

    # Resulting script name
    if(CMAKE_HOST_WIN32)
        file(TO_NATIVE_PATH ${EnvValue} EnvValue)
    endif()
    set(ScriptName ${PROJECT_BINARY_DIR}/setprojectenv${SSP_SCRIPT_TYPE})

    # Reset mode to WRITE if file does not exist
    if(("${Mode}" STREQUAL "APPEND") AND (NOT EXISTS ${ScriptName}))
        set(Mode "WRITE")
    endif()

    # overwrite or extend the env variable's value
    set(EnvValueAlreadySet -1)
    if(NOT IsExtend EQUAL -1)
        if(NOT "$ENV{${EnvKey}}" STREQUAL "")
            if(CMAKE_HOST_UNIX)
                set(CurrentEnvValue "$ENV{${EnvKey}}:")
            elseif(CMAKE_HOST_WIN32)
                set(CurrentEnvValue "$ENV{${EnvKey}};")
            endif()
        endif()
        # Contains the env variable the value already?
        string(FIND "$ENV{${EnvKey}}" "${EnvValue}" EnvValueAlreadySet REVERSE)
    endif()

    if(EnvValueAlreadySet EQUAL -1)
        if(CMAKE_HOST_UNIX)
#### Error! Replace the following line with workaround
                        file(${Mode} ${ScriptName} "${PreviousScriptContent} export ${EnvKey}=${CurrentEnvValue}${EnvValue}\n" )
            execute_process(COMMAND chmod u+x ${ScriptName} WORKING_DIRECTORY "${PROJECT_BINARY_DIR}")
        elseif(CMAKE_HOST_WIN32)
            file(${Mode} ${ScriptName} "set ${EnvKey}=${CurrentEnvValue}${EnvValue}\n\r" )
        endif()
    endif()
endfunction()


The workaround for linux using VmWare share.
            if("${Mode}" STREQUAL "APPEND")
                file(READ ${ScriptName} PreviousScriptContent)
            endif()
            file(WRITE ${ScriptName} "${PreviousScriptContent} export ${EnvKey}=${CurrentEnvValue}${EnvValue}\n" )


Usage of the function:
    write_env_script(APPEND QT_PLUGIN_PATH "${QtLibs_PATH}/plugins")
    write_env_script(APPEND QML2_IMPORT_PATH "${QtLibs_PATH}/qml")
    write_env_script(APPEND PATH "${QtLibs_PATH}/bin" EXTEND)
TagsCMake, linux, shared, Windows 7
Attached Files

 Relationships

  Notes
(0035930)
David Cole (manager)
2014-05-26 07:22

Are you certain the null characters are not coming from the value of some environment variable?
(0035931)
th.thielemann (reporter)
2014-05-26 08:50

The values inserted are display on screen without any issues. In the case I use the workaround (Read previous file content into cmake variable, add the new content and write all back) everything is fine.
At first I assumed the reason is the file system only (the shared folder between Win7 and Linux). But I build in the shared folder too and no other file generated by cmake, compiler, linker shows this issue.
(0042552)
Kitware Robot (administrator)
2016-06-10 14:29

Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.

 Issue History
Date Modified Username Field Change
2014-05-26 04:56 th.thielemann New Issue
2014-05-26 07:22 David Cole Note Added: 0035930
2014-05-26 08:50 th.thielemann Note Added: 0035931
2014-05-26 08:53 th.thielemann Tag Attached: CMake
2014-05-26 08:53 th.thielemann Tag Attached: linux
2014-05-26 08:53 th.thielemann Tag Attached: shared
2014-05-26 08:53 th.thielemann Tag Attached: Windows 7
2016-06-10 14:29 Kitware Robot Note Added: 0042552
2016-06-10 14:29 Kitware Robot Status new => resolved
2016-06-10 14:29 Kitware Robot Resolution open => moved
2016-06-10 14:29 Kitware Robot Assigned To => Kitware Robot
2016-06-10 14:31 Kitware Robot Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team