MantisBT - CMake
View Issue Details
0015439CMakeCMakepublic2015-03-10 16:542015-11-02 09:15
Thomas Herz 
Brad King 
normalmajoralways
closedfixed 
Win32WindowsWindows 7
CMake 3.2 
CMake 3.3CMake 3.3 
0015439: ninja: no possibility to control type of path delimiter and line break for linker response file
I'm working with the Windriver VxWorks GNU tool chain on Windows host.
   Compiler Version: ccpentium.exe (Wind River VxWorks G++ DWARF-EH 4.1-131) 4.1.2
    --host=i686-mingw32
    --target=i586-wrs-vxworks

I adapted our existing 'unix makefile' project to ninja builder and I'm getting following linker error:

   @CMakeFiles/myLib.rsp: No such file or directory

Finally, I figured out the reason. Actually, there are two of them:

1) The linker response file uses '\' for path delimiters, but this version of GCC can't handle them, even if it is running on Windows host.
It only handles '/' or '\\' correctly. I managed to work around this problem by setting 'CMAKE_COMPILER_IS_MINGW' to '1'. But, I guess, this may have some unwanted side effects. Related bug report: 0015278

2) The linker response file uses Windows style line-breaks (CR-LF) to separate individual object paths. This version of GCC can't handle them. It works fine with Unix style (LF) or without any line breaks and whitespace instead.
The behaviour of ninja generator was changed with commit a55d5ca48179d3be4d8406028c0992d45ada8882. I think, this patch is too 'global'.
According to commit message 'Avoid LNK1170 linker error' this commit should solve Microsoft compiler/linker problems. Furthermore LNK1170 is not listed anymore for VS2010 and above.

Anyhow, for both issues, some kind of automagic with the possibility to change the automagic decision with a particular cmake-variable would be the best solution for such kind of problems.

backslash, CMake, linefeed, ninja
related to 0015278closed  Ninja generator breaks when creating archives with GNU 'ar' in Windows 
patch 0001-Use-always-forward-slashes-in-response-files-when-co.patch (3,080) 2015-05-07 03:59
https://public.kitware.com/Bug/file/5450/0001-Use-always-forward-slashes-in-response-files-when-co.patch
patch 0002-Do-not-use-newlines-in-response-files-when-compiling.patch (1,163) 2015-05-07 03:59
https://public.kitware.com/Bug/file/5451/0002-Do-not-use-newlines-in-response-files-when-compiling.patch
patch 0001-ninja-Replaced-last-left-MinGW-check-with-GCCOnWindo.patch (934) 2015-05-08 10:25
https://public.kitware.com/Bug/file/5453/0001-ninja-Replaced-last-left-MinGW-check-with-GCCOnWindo.patch
Issue History
2015-03-10 16:54Thomas HerzNew Issue
2015-03-11 05:21Thomas HerzTag Attached: backslash
2015-03-11 05:21Thomas HerzTag Attached: CMake
2015-03-11 05:21Thomas HerzTag Attached: linefeed
2015-03-11 05:21Thomas HerzTag Attached: ninja
2015-03-11 08:27Brad KingRelationship addedrelated to 0015278
2015-04-07 16:01Brad KingNote Added: 0038471
2015-05-07 03:58Thomas HerzNote Added: 0038724
2015-05-07 03:59Thomas HerzFile Added: 0001-Use-always-forward-slashes-in-response-files-when-co.patch
2015-05-07 03:59Thomas HerzFile Added: 0002-Do-not-use-newlines-in-response-files-when-compiling.patch
2015-05-07 15:11Brad KingNote Added: 0038728
2015-05-07 15:12Brad KingAssigned To => Brad King
2015-05-07 15:12Brad KingStatusnew => assigned
2015-05-07 15:12Brad KingTarget Version => CMake 3.3
2015-05-08 09:38Brad KingNote Added: 0038734
2015-05-08 09:38Brad KingStatusassigned => resolved
2015-05-08 09:38Brad KingResolutionopen => fixed
2015-05-08 09:38Brad KingFixed in Version => CMake 3.3
2015-05-08 10:25Thomas HerzFile Added: 0001-ninja-Replaced-last-left-MinGW-check-with-GCCOnWindo.patch
2015-05-08 10:30Thomas HerzNote Added: 0038737
2015-05-08 11:22Brad KingNote Added: 0038738
2015-11-02 09:15Robert MaynardNote Added: 0039807
2015-11-02 09:15Robert MaynardStatusresolved => closed

Notes
(0038471)
Brad King   
2015-04-07 16:01   
For problem (1), here is a trace back of how CMake decides which kind of slash to use:

 http://www.cmake.org/gitweb?p=cmake.git;a=blob;f=Source/cmGlobalNinjaGenerator.cxx;hb=v3.2.1#l94 [^]
 http://www.cmake.org/gitweb?p=cmake.git;a=blob;f=Source/cmGlobalNinjaGenerator.cxx;hb=v3.2.1#l538 [^]
 http://www.cmake.org/gitweb?p=cmake.git;a=blob;f=Modules/CMakeDetermineCCompiler.cmake;hb=v3.2.1#l114 [^]
 http://www.cmake.org/gitweb?p=cmake.git;a=blob;f=Modules/CMakePlatformId.h.in;hb=v3.2.1#l8 [^]

The "CMAKE_COMPILER_IS_MINGW" variable is an ancient value that pre-dates proper compiler id logic. The Ninja generator should probably learn to make its choice of slash direction based on something else.

For problem (2), the $in_newline was added to produce nicer response files. It is Ninja that actually generates the response files:

 http://martine.github.io/ninja/manual.html#ref_rule [^]

so it is Ninja that would have to be taught what kind of newline to use to fix this.
(0038724)
Thomas Herz   
2015-05-07 03:58   
Brad, sorry for late response.

The code spots you mentioned are mostly the ones I fixed in my local branch. See my attached patch files. Take them as a proposal or inspiration...

In fact, neither CMake nor Ninja has really a bug. The problem is the ancient GNU cross-toolchain we use. We cannot fix this, though so we patched CMake here to get it working.

For the second problem: It was more easy to do this in CMake because CMake has all necessary knowledge to handle it correctly.
The former patch was mainly done for MSVC linker, which tells Ninja manual as well. I guess, it was working before in all environments without newlines except with MSVC.
(0038728)
Brad King   
2015-05-07 15:11   
Thanks for the patches. I did some cleanup:

 RC: Simplify selection of resource compiler based on C/C++ toolchain
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=957c2aac [^]

 Ninja: Refactor detection of MinGW tools on Windows
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=378c2a0e [^]

and then applied changes based on the patches:

 Ninja: Use forward slashes for any GCC on Windows
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b3de0dfe [^]

 Ninja: Do not use newlines in response files with Windows GNU tools
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=20560e8d [^]

Please try it out as of that last commit.
(0038734)
Brad King   
2015-05-08 09:38   
The changes linked in 0015439:0038728 passed nightly testing. I'm marking this resolved. Please comment with the results of testing for your use case.
(0038737)
Thomas Herz   
2015-05-08 10:30   
Brad,
I tested your changes. It looks fine except one thing: I missed one code-change in my previous patch-files. See my additionally attached patch-file for this (last) change. With this change the complete response file is created with forward slashes and without line feeds.
(0038738)
Brad King   
2015-05-08 11:22   
Re 0015439:0038737: Thanks. Applied:

 Ninja: Use forward slashes for linking with any GCC on Windows
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ca658a45 [^]
(0039807)
Robert Maynard   
2015-11-02 09:15   
Closing resolved issues that have not been updated in more than 4 months.