[CMake] Assembly language support using gcc or gas

Glenn Coombs glenn.coombs at gmail.com
Sun Aug 7 08:51:35 EDT 2011


Hi Alex,

I've tested your zip file example and it works as expected: the -I options
are present but not the -D options.  After some more testing of what is
different in my setup I think I have isolated the cause.  If I change this
one line in your example from this:

    add_definitions(-DFOO)

to this:

    add_definitions("-DFOO -DBAR")

then I get the same behaviour I was seeing before: the -DFOO -DBAR options
are passed through to the assembler command line.  I see from the
documentation that I should really be using add_definitions(-DFOO -DBAR)
without the double quotes but they were harmless before.  Should I file this
as a bug - or will it just be marked as "not a bug", i.e. don't use double
quotes like that with add_definitions ?

--
Glenn


2011/8/3 Alexander Neundorf <a.neundorf-work at gmx.net>

> Hi,
>
> On Wednesday 03 August 2011, Glenn Coombs wrote:
> > I tried changing from ASM to ASM-ATT and that fails like this:
> >
> > /usr/bin/as  -I/user/grc/msvdx-cvsfiles/sim/msvdx-cmake-2.8.5/systemC/src
> > -I/user/grc/msvdx-cvsfiles/sim/msvdx-cmake-2.8.5/systemC/src/sysc/kernel
> > -DNOMINMAX -DUSE_SIM_NAMESPACE -o
> > CMakeFiles/systemc.dir/src/sysc/qt/md/i386.s.o
> >
> /user/grc/msvdx-cvsfiles/sim/msvdx-cmake-2.8.5/systemC/src/sysc/qt/md/i386.
> > s /usr/bin/as: unrecognized option `-NOMINMAX'
> >
> > I really don't think the -I and -D options should be passed through for
> > assembler files.  They only make sense for C/C++ files.  There should be
> a
> > separate variable like CMAKE_ASM_FLAGS that is used instead of
> > CMAKE_C_FLAGS or CMAKE_CXX_FLAGS.  And maybe there needs to be a change
> to
> > the
> > add_definitions() command to allow an optional LANG argument ?  Do
> > assembers even support preprocessor definitions ?
> >
> > I was able to get it to work for both 2.8.4 and 2.8.5 with the following
> > code:
> >
> > if(UNIX)
> >     list(APPEND sources "src/sysc/qt/qt.c")
> >
> >     # see if we are building 32-bit or 64-bit executables
> >     file(WRITE ${CMAKE_BINARY_DIR}/check_32or64bit.cpp "int main(int
> argc,
> > char *argv[]) { return 8 * sizeof(char *); }\n")
> >
> >     try_run(
> >         run_result
> >         compile_result
> >         ${CMAKE_BINARY_DIR}
> > ${CMAKE_BINARY_DIR}/check_32or64bit.cpp
> >         )
> >
> >     if (${run_result} EQUAL 32)
> >         list(APPEND sources "src/sysc/qt/md/i386.s")
> >         if(APPLE)
> >             set(ASM_SYS_FLAGS "-arch i386")
> >         else()
> >             set(ASM_SYS_FLAGS "-32")
> >         endif()
> >     else()
> >         list(APPEND sources "src/sysc/qt/md/iX86_64.s")
> >         if(APPLE)
> >             set(ASM_SYS_FLAGS "-arch x86_64")
> >         else()
> >             set(ASM_SYS_FLAGS "-64")
> >         endif()
> >     endif()
> >
> >     enable_language(ASM-ATT)
> >
> >     set(CMAKE_ASM-ATT_COMPILE_OBJECT "<CMAKE_ASM-ATT_COMPILER>
> > ${ASM_SYS_FLAGS} -o <OBJECT> <SOURCE>")
> > endif()
> >
> > I'm not sure if this is the recommended way to do this though.  I thought
> > the documentation said to override CMAKE_ASM-ATT_COMPILE_OBJECT before
> the
> > enable_language() command.
>
> You should not have to override it.
> To set flags, there are for every enabled language CMAKE_<LANGUAGE>_FLAGS
> in
> the cmake cache, i.e. CMAKE_ASM-ATT_FLAGS in this case.
>
> I tried to reproduce the problem with the attached tiny project, and I
> don't
> get the problem you describe. This is the output:
>
> as-test/b$ /opt/cmake-HEAD/bin/cmake ..
> -- The C compiler identification is GNU
> -- The CXX compiler identification is GNU
> -- Check for working C compiler: /usr/bin/gcc
> -- Check for working C compiler: /usr/bin/gcc -- works
> -- Detecting C compiler ABI info
> -- Detecting C compiler ABI info - done
> -- Check for working CXX compiler: /usr/bin/c++
> -- Check for working CXX compiler: /usr/bin/c++ -- works
> -- Detecting CXX compiler ABI info
> -- Detecting CXX compiler ABI info - done
> -- The ASM-ATT compiler identification is GNU
> -- Found assembler: /usr/bin/as
> -- Configuring done
> -- Generating done
> -- Build files have been written to: /home/alex/src/CMake/build dir/CMake-
> git/Tests/Assembler/as-test/b
> as-test/b$ make VERBOSE=1
> ...
> Scanning dependencies of target hello
> make[2]: Leaving directory `/home/alex/src/CMake/build dir/CMake-
> git/Tests/Assembler/as-test/b'
> make -f CMakeFiles/hello.dir/build.make CMakeFiles/hello.dir/build
> make[2]: Entering directory `/home/alex/src/CMake/build dir/CMake-
> git/Tests/Assembler/as-test/b'
> /opt/cmake-HEAD/bin/cmake -E cmake_progress_report
> "/home/alex/src/CMake/build
> dir/CMake-git/Tests/Assembler/as-test/b/CMakeFiles" 1
>
> [ 50%] Building C object CMakeFiles/hello.dir/main.c.o
> /usr/bin/gcc  -DFOO -DBLUB=blub -DBAR=bar -I/opt/include    -o
> CMakeFiles/hello.dir/main.c.o   -c "/home/alex/src/CMake/build dir/CMake-
> git/Tests/Assembler/as-test/main.c"
> /opt/cmake-HEAD/bin/cmake -E cmake_progress_report
> "/home/alex/src/CMake/build
> dir/CMake-git/Tests/Assembler/as-test/b/CMakeFiles" 2
>
> [100%] Building ASM-ATT object CMakeFiles/hello.dir/foo.s.o
> /usr/bin/as  -I/opt/include    -o CMakeFiles/hello.dir/foo.s.o
> "/home/alex/src/CMake/build dir/CMake-git/Tests/Assembler/as-test/foo.s"
> Linking C executable hello
> ...
>
>
> So, here main.c gets all the -D's, and foo.s gets the -I, but not the -D's.
> Is that different for you ?
>
> Alex
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110807/6720b0c7/attachment.htm>


More information about the CMake mailing list