MantisBT - CMake
View Issue Details
0014401CMakeCMakepublic2013-09-12 09:292016-06-10 14:31
Pawel Defee 
Alex Neundorf 
highmajoralways
closedmoved 
X86Linux 2.6.32-220.23.1.el6.i686RedHat RHEL 6
CMake 2.8.11.2 
 
0014401: CMake incorrectly passes C/CXX flags to assembler
When building mixed C/CXX/ASM projects, CMake incorrectly passes C/CXX compiler options to assembler. On some platform (standard X86 GNU compilers), this is not an issue, but in my case where I cross-compile on X86 for ARM target, the assembler refuses to compile due to invalid options as follows:

[user@host temp]$ make
Scanning dependencies of target asmbug
[ 50%] Building CXX object CMakeFiles/asmbug.dir/main.cpp.obj
[100%] Building ASM object CMakeFiles/asmbug.dir/asmfunction.S.obj
/usr/local/embedded-cross-compilers/arm-eabi-as: unrecognized option '-O3'
make[2]: *** [CMakeFiles/asmbug.dir/asmfunction.S.obj] Error 1
make[1]: *** [CMakeFiles/asmbug.dir/all] Error 2
make: *** [all] Error 2
Run CMake on the attached example project. This requires an arm cross compilation toolchain to be installed.
No tags attached.
tar asmbug.tar (10,240) 2013-09-12 09:29
https://public.kitware.com/Bug/file/4876/asmbug.tar
Issue History
2013-09-12 09:29Pawel DefeeNew Issue
2013-09-12 09:29Pawel DefeeFile Added: asmbug.tar
2013-09-12 09:33Pawel DefeeNote Added: 0033809
2013-09-12 09:39Brad KingAssigned To => Alex Neundorf
2013-09-12 09:39Brad KingStatusnew => assigned
2013-09-12 09:40Brad KingNote Added: 0033810
2013-09-12 16:04Alex NeundorfNote Added: 0033811
2013-09-13 02:55Pawel DefeeNote Added: 0033814
2016-06-10 14:29Kitware RobotNote Added: 0042364
2016-06-10 14:29Kitware RobotStatusassigned => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0033809)
Pawel Defee   
2013-09-12 09:33   
I should add that it appears that this was broken after 2.8.4, i.e. 2.8.4 works fine.
(0033810)
Brad King   
2013-09-12 09:40   
IIRC there was an effort to use the C compiler as the default assembler, in which case passing the C flags makes sense.

Alex, what is the intended way to use a different assembler?
(0033811)
Alex Neundorf   
2013-09-12 16:04   
By default, for "ASM" the C compiler will be used as ASM compiler, i.e. CMAKE_ASM_COMPILER will be set to it.
This shouldn't mean that it receives C or C++ flags.

I tried it here, it doesn't look too bad:

make[2]: Entering directory `/home/alex/src/CMake/tests/asmbug-14401/build'
/opt/cmake-2.8.11.2-Linux-i386/bin/cmake -E cmake_progress_report /home/alex/src/CMake/tests/asmbug-14401/build/CMakeFiles 1
[ 50%] Building CXX object CMakeFiles/asmbug.dir/main.cpp.obj

/opt/eldk-4.1/arm/usr/bin/arm-linux-g++ -DCXX_FLAGS -O3 -DNDEBUG -o CMakeFiles/asmbug.dir/main.cpp.obj -c /home/alex/src/CMake/tests/asmbug-14401/main.cpp

/opt/cmake-2.8.11.2-Linux-i386/bin/cmake -E cmake_progress_report /home/alex/src/CMake/tests/asmbug-14401/build/CMakeFiles 2
[100%] Building ASM object CMakeFiles/asmbug.dir/asmfunction.S.obj

/opt/eldk-4.1/arm/usr/bin/arm-linux-as -DASM_FLAGS -O3 -DNDEBUG -o CMakeFiles/asmbug.dir/asmfunction.S.obj -c /home/alex/src/CMake/tests/asmbug-14401/asmfunction.S

The C++ file gets -DCXX_FLAGS and the S file gets -DASM_FLAGS, as they should.

There is the issue that as is used for "ASM". ASM is supposed to be used when the C/CXX compiler can be used for assembler too.
Here ASM-ATT should be used, i.e. CMAKE_ASM-ATT_COMPILER should be set, and the ASM-ATT language should be enabled.
The as doesn't receive the -O3 and -DNDEBUG flags.

I have to update the wiki page http://www.cmake.org/Wiki/CMake/Assembler [^]
(0033814)
Pawel Defee   
2013-09-13 02:55   
Thanks for your suggestion. Adding the directive 'enable_language(ASM_ATT)' to our toolchain file did indeed solve the issue.

Please do update the wiki just in case someone else stumbles upon this same problem.

As far as I am concerned, this issue can be closed. Thanks again!
(0042364)
Kitware Robot   
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.