MantisBT - CMake
View Issue Details
0015969CMakeCMakepublic2016-02-11 02:582016-06-10 14:21
A. Klitzing 
 
normalmajoralways
closedno change required 
iOSOSX10.10
 
 
0015969: String property broken in cmake 3.5.0-rc2 with XCode
We build our application for iOS with cmake and iOS toolchain file [1].

We pass some strings with "-D" property to the compiler. In cmake 3.5.0rc2 (rc1 not tested) the build will fail as the quotes of the strings are broken.

Same code works with cmake 3.4.1.


[1] https://github.com/cristeab/ios-cmake [^]
1. cmake ../source -DCMAKE_BUILD_TYPE=release -DCMAKE_PREFIX_PATH=/[...]/dist -DCMAKE_TOOLCHAIN_FILE=../source/cmake/iOS.toolchain.cmake -GXcode

2. xcodebuild -target install -configuration Release

3. Compiler failed
Snippets of compiler cmdline:
See at -DVERSION=


3.5.0-rc2:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c++ -arch armv7 [.....] -std=c++11 -ObjC++ -fPIC -DVERSION=\\1.6.3+5-default-53920e4f2686\\ -MMD -MT dependencies [...] -c /.../src/main.cpp -o /.../build/src/XYZ.build/Release-iphoneos/XYZ.build/Objects-normal/armv7/main.o



3.4.1:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c++ -arch armv7 [.....] -std=c++11 -fPIC -DVERSION=\"1.6.3+5-default-53920e4f2686\" -MMD -MT dependencies -c /.../src/main.cpp -o /.../build/src/XYZ.build/Release-iphoneos/XYZ.build/Objects-normal/armv7/main.o




We use a little wrapper for quoted strings as XCode, windres and other compilers works different here.




FUNCTION(GET_QUOTED_STRING _dest _str _filename)
    IF(CMAKE_GENERATOR STREQUAL Xcode)
        SET(tmp_var \\\\"${_str}\\\\")
    ELSEIF(NOT ${arg} MATCHES ".rc$")
        SET(tmp_var \\"${_str}\\")
    ELSE()
        SET(tmp_var ${_str})
    ENDIF()

    SET(${_dest} ${tmp_var} PARENT_SCOPE)
ENDFUNCTION()

FUNCTION(ADD_STRING_DEFINITION _str _def)
    IF(ARGN)
        FOREACH(arg ${ARGN})
            IF (${arg} MATCHES "^AppTargetName")
                SET(ARG_TYPE TARGET)
            ELSE()
                SET(ARG_TYPE SOURCE)
            ENDIF()

            IF(NOT "${_str}" STREQUAL "")
                GET_QUOTED_STRING(tmp_var ${_str} ${arg})
                SET(tmp_var =${tmp_var})
            ENDIF()

            SET_PROPERTY(${ARG_TYPE} ${arg} APPEND_STRING PROPERTY COMPILE_FLAGS " -D${_def}${tmp_var}")
        ENDFOREACH()
    ELSE()
        IF(NOT "${_str}" STREQUAL "")
            GET_QUOTED_STRING(tmp_var ${_str} ${arg})
            SET(tmp_var =${tmp_var})
        ENDIF()
        ADD_DEFINITIONS(-D${_def}${tmp_var})
    ENDIF()
ENDFUNCTION()

FUNCTION(ADD_DEFINITION _def)
    ADD_STRING_DEFINITION("" ${_def} ${ARGN})
ENDFUNCTION()


##########################################

PROJECT(XYZ VERSION 1.6.3 CXX)
SET(VERSION_MERCURIAL ${PROJECT_VERSION}+5-default-53920e4f2686)
ADD_STRING_DEFINITION(${VERSION_MERCURIAL} "VERSION" main.cpp)
No tags attached.
related to 0015328closed Gregor Jasny cmake generates corrupt Xcode projects for KDE projects 
Issue History
2016-02-11 02:58A. KlitzingNew Issue
2016-02-11 08:25Brad KingRelationship addedrelated to 0015328
2016-02-11 08:27Brad KingNote Added: 0040470
2016-02-11 09:42A. KlitzingNote Added: 0040472
2016-02-11 09:58Brad KingNote Added: 0040473
2016-02-11 09:59Brad KingStatusnew => resolved
2016-02-11 09:59Brad KingResolutionopen => no change required
2016-06-10 14:21Kitware RobotNote Added: 0041255
2016-06-10 14:21Kitware RobotStatusresolved => closed

Notes
(0040470)
Brad King   
2016-02-11 08:27   
If you remove your CMAKE_GENERATOR==Xcode workaround does it work as expected? That looks like a workaround for the lack of the fix in 0015328.
(0040472)
A. Klitzing   
2016-02-11 09:42   
Thanks for quick response!

Yeah, that was the problem... the build works again. We need to adjust our work-around. :-)

IF(CMAKE_GENERATOR STREQUAL Xcode AND CMAKE_VERSION VERSION_LESS "3.5")
(0040473)
Brad King   
2016-02-11 09:58   
Re 0015969:0040472: Thanks for checking. Normally we use a policy for behavior changes but in this case I think that would be too heavy since fixes to projects that worked around the bug are easy. I've added a release note for 3.5 to call attention to the change:

 Help: Add release note about Xcode escaping fix
 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=878632c9 [^]
(0041255)
Kitware Robot   
2016-06-10 14:21   
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.