MantisBT - CMake
View Issue Details
0013069CMakeCMakepublic2012-03-28 16:212013-01-09 10:55
Ben Boeckel 
Peter Collingbourne 
normalmajoralways
closedfixed 
CMake 2.8.8 
CMake 2.8.9CMake 2.8.9 
0013069: Ninja: CMAKE_<LANG>_FLAGS_<TYPE> flags not applied to executable commands
When compiling with custom flags which are applied per-build type, they are not added to the linker line with the Ninja generator. The commands run by ninja and make are pasted below for comparison.

With ninja:
[1/6] /usr/lib64/ccache/gcc -g -O0 -pg -fprofile-arcs -ftest-coverage -DFLAG=\"Debug\" -MMD -MF CMakeFiles/lib.dir/lib.c.o.d -o CMakeFiles/lib.dir/lib.c.o -c ../lib.c
[2/6] /usr/lib64/ccache/gcc -Dlib_shared_EXPORTS -g -O0 -pg -fprofile-arcs -ftest-coverage -DFLAG=\"Debug\" -fPIC -MMD -MF CMakeFiles/lib_shared.dir/lib.c.o.d -o CMakeFiles/lib_shared.dir/lib.c.o -c ../lib.c
[3/6] : && /usr/lib64/ccache/gcc -fPIC -g -O0 -pg -fprofile-arcs -ftest-coverage -DFLAG=\"Debug\" -shared -Wl,-soname,liblib_shared.so -o liblib_shared.so CMakeFiles/lib_shared.dir/lib.c.o && :
[4/6] : && /home/boeckb/code/cmake/build/bin/cmake -E remove liblib.a && /usr/bin/ar cr liblib.a CMakeFiles/lib.dir/lib.c.o && /usr/bin/ranlib liblib.a && :
[5/6] /usr/lib64/ccache/gcc -g -O0 -pg -fprofile-arcs -ftest-coverage -DFLAG=\"Debug\" -MMD -MF CMakeFiles/flags.dir/flags.c.o.d -o CMakeFiles/flags.dir/flags.c.o -c ../flags.c
[6/6] : && /usr/lib64/ccache/gcc -fPIC CMakeFiles/flags.dir/flags.c.o -o flags -rdynamic liblib.a && :

With Unix Makefiles:
/usr/lib64/ccache/gcc -g -O0 -pg -fprofile-arcs -ftest-coverage -DFLAG=\"Debug\" -o CMakeFiles/lib.dir/lib.c.o -c /home/boeckb/misc/code/sb/ninja/lib.c
/usr/bin/ar cr liblib.a CMakeFiles/lib.dir/lib.c.o
/usr/bin/ranlib liblib.a
/usr/lib64/ccache/gcc -g -O0 -pg -fprofile-arcs -ftest-coverage -DFLAG=\"Debug\" -o CMakeFiles/flags.dir/flags.c.o -c /home/boeckb/misc/code/sb/ninja/flags.c
/usr/lib64/ccache/gcc -g -O0 -pg -fprofile-arcs -ftest-coverage -DFLAG=\"Debug\" CMakeFiles/flags.dir/flags.c.o -o flags -rdynamic liblib.a
/usr/lib64/ccache/gcc -Dlib_shared_EXPORTS -g -O0 -pg -fprofile-arcs -ftest-coverage -DFLAG=\"Debug\" -fPIC -o CMakeFiles/lib_shared.dir/lib.c.o -c /home/boeckb/misc/code/sb/ninja/lib.c
/usr/lib64/ccache/gcc -fPIC -g -O0 -pg -fprofile-arcs -ftest-coverage -DFLAG=\"Debug\" -shared -Wl,-soname,liblib_shared.so -o liblib_shared.so CMakeFiles/lib_shared.dir/lib.c.o
Attached tarball with CMakeLists and shell script used to track down the error.

Run the shell script as:

cmake=/path/to/cmake sh mktrees.sh
cmake-2.8.8-git58db6ac
ninja-master-gitabd33d5
No tags attached.
bz2 ninja-flags.tar.bz2 (1,048) 2012-03-28 16:21
https://public.kitware.com/Bug/file/4270/ninja-flags.tar.bz2
patch cmake-0001-Ninja-Fix-13069-CMAKE_-LANG-_FLAGS_-TYPE-flags-not-a.patch (1,350) 2012-04-26 07:11
https://public.kitware.com/Bug/file/4316/cmake-0001-Ninja-Fix-13069-CMAKE_-LANG-_FLAGS_-TYPE-flags-not-a.patch
Issue History
2012-03-28 16:21Ben BoeckelNew Issue
2012-03-28 16:21Ben BoeckelFile Added: ninja-flags.tar.bz2
2012-03-28 17:07Brad KingAssigned To => Peter Collingbourne
2012-03-28 17:07Brad KingStatusnew => assigned
2012-04-26 07:11Zaheer ChothiaNote Added: 0029347
2012-04-26 07:11Zaheer ChothiaFile Added: cmake-0001-Ninja-Fix-13069-CMAKE_-LANG-_FLAGS_-TYPE-flags-not-a.patch
2012-05-16 18:10Peter CollingbourneNote Added: 0029488
2012-07-03 06:40Peter KuemmelNote Added: 0029891
2012-07-03 06:40Peter KuemmelStatusassigned => resolved
2012-07-03 06:40Peter KuemmelResolutionopen => fixed
2012-08-09 16:54David ColeFixed in Version => CMake 2.8.9
2012-08-09 16:54David ColeTarget Version => CMake 2.8.9
2013-01-09 10:55Robert MaynardNote Added: 0032014
2013-01-09 10:55Robert MaynardStatusresolved => closed

Notes
(0029347)
Zaheer Chothia   
2012-04-26 07:11   
Attached is a patch which resolves this issue. Note this also addresses a similar issue with CMAKE_SHARED_LIBRARY_<LANG>_FLAGS_<TYPE>.
Thanks very much for the isolated testcase! For reference, these are the commands executed once the fix has been applied:

With ninja:
[1/6] /usr/bin/gcc -g -O0 -pg -fprofile-arcs -ftest-coverage -DFLAG=\"Debug\" -MMD -MT CMakeFiles/lib.dir/lib.c.o -MF CMakeFiles/lib.dir/lib.c.o.d -o CMakeFiles/lib.dir/lib.c.o -c ../lib.c
[2/6] /usr/bin/gcc -Dlib_shared_EXPORTS -g -O0 -pg -fprofile-arcs -ftest-coverage -DFLAG=\"Debug\" -fPIC -MMD -MT CMakeFiles/lib_shared.dir/lib.c.o -MF CMakeFiles/lib_shared.dir/lib.c.o.d -o CMakeFiles/lib_shared.dir/lib.c.o -c ../lib.c
[3/6] : && /home/zchothia/cmake_ninja_flags_bug13069/CMake_git/build_debug/bin/cmake -E remove liblib.a && /usr/bin/ar cr liblib.a CMakeFiles/lib.dir/lib.c.o && /usr/bin/ranlib liblib.a && :
[4/6] : && /usr/bin/gcc -fPIC -g -O0 -pg -fprofile-arcs -ftest-coverage -DFLAG=\"Debug\" -shared -Wl,-soname,liblib_shared.so -o liblib_shared.so CMakeFiles/lib_shared.dir/lib.c.o && :
[5/6] /usr/bin/gcc -g -O0 -pg -fprofile-arcs -ftest-coverage -DFLAG=\"Debug\" -MMD -MT CMakeFiles/flags.dir/flags.c.o -MF CMakeFiles/flags.dir/flags.c.o.d -o CMakeFiles/flags.dir/flags.c.o -c ../flags.c
[6/6] : && /usr/bin/gcc -g -O0 -pg -fprofile-arcs -ftest-coverage -DFLAG=\"Debug\" -fPIC CMakeFiles/flags.dir/flags.c.o -o flags -rdynamic liblib.a && :

With Unix Makefiles:
/usr/bin/gcc -g -O0 -pg -fprofile-arcs -ftest-coverage -DFLAG=\"Debug\" -o CMakeFiles/lib.dir/lib.c.o -c /home/zchothia/cmake_ninja_flags_bug13069/testcase/lib.c
/usr/bin/ar cr liblib.a CMakeFiles/lib.dir/lib.c.o
/usr/bin/ranlib liblib.a
/usr/bin/gcc -g -O0 -pg -fprofile-arcs -ftest-coverage -DFLAG=\"Debug\" -o CMakeFiles/flags.dir/flags.c.o -c /home/zchothia/cmake_ninja_flags_bug13069/testcase/flags.c
/usr/bin/gcc -g -O0 -pg -fprofile-arcs -ftest-coverage -DFLAG=\"Debug\" CMakeFiles/flags.dir/flags.c.o -o flags -rdynamic liblib.a
/usr/bin/gcc -Dlib_shared_EXPORTS -g -O0 -pg -fprofile-arcs -ftest-coverage -DFLAG=\"Debug\" -fPIC -o CMakeFiles/lib_shared.dir/lib.c.o -c /home/zchothia/cmake_ninja_flags_bug13069/testcase/lib.c
/usr/bin/gcc -fPIC -g -O0 -pg -fprofile-arcs -ftest-coverage -DFLAG=\"Debug\" -shared -Wl,-soname,liblib_shared.so -o liblib_shared.so CMakeFiles/lib_shared.dir/lib.c.o

Tested with:
cmake-master-git8bb46ee
ninja-master-git16cab01
(0029488)
Peter Collingbourne   
2012-05-16 18:10   
I've pushed a commit to next which should fix this bug. Note that as far as I can tell CMake does not use CMAKE_SHARED_LIBRARY_<LANG>_FLAGS_<TYPE> so I did not apply that part of your patch.
(0029891)
Peter Kuemmel   
2012-07-03 06:40   
Verified.

And I've added it as 'BuildTypeFlag' test.
(0032014)
Robert Maynard   
2013-01-09 10:55   
Closing resolved issues that have not been updated in more than 4 months.