Why is CMake ignoring assembly files when building static library?
Asked Answered
C

3

7

I've set

set(CAN_USE_ASSEMBLER TRUE)

And it's not helping at all. I'm trying to create a static library with a command like:

add_library(${CMAKE_PROJECT_NAME} STATIC
            ../PropWare ../spi ../spi_as.S ../sd)

where the files without extensions are C++ or C files and the .S file is assembly. But when I run cmake and make, it compiles the C/C++ sources and just ignores the assembly file... no warnings, no errors... just skips right over it.

I'd love any ideas. Full source is available on github (do note: this link is to the cmake branch, all others should be ignored). The first line is in this file and the second line is in this file.

Cowled answered 4/5, 2014 at 2:52 Comment(1)
Cmake still does this a decade later. You tell it about some asm source, it silently ignores it, until you stumble across this post in confusion and raise a PR adding the line 'project'. Thank you for the question - without it I'd have never found this in their docs.Plasticine
U
4

Note that you can enable ASM in the project() command too. For example:

project(abc
        LANGUAGES C CXX ASM)
Uncurl answered 9/6, 2021 at 10:43 Comment(1)
This is really the right answer to the question :) Not sure why I never came back and updated it lolCowled
C
13

Update

See this better answer https://mcmap.net/q/1412861/-why-is-cmake-ignoring-assembly-files-when-building-static-library It's not always possible to know what languages you need enabled at the time that the project() command is invoked... but probably 99.9% of the time it is, so go with this route. If, however, you need to programmatically enable different languages, based on some configure-time logic, then my original answer will work for you.

Original Answer

Finally found it. Instead of

set(CAN_USE_ASSEMBLER TRUE)

I should have used

enable_language(ASM)
Cowled answered 4/5, 2014 at 3:41 Comment(0)
U
4

Note that you can enable ASM in the project() command too. For example:

project(abc
        LANGUAGES C CXX ASM)
Uncurl answered 9/6, 2021 at 10:43 Comment(1)
This is really the right answer to the question :) Not sure why I never came back and updated it lolCowled
C
1

When using gcc, you can compile .S files with your C compiler (no explicit invocation of asm needed). CMake can be told to do so using

set_property(SOURCE <myfile>.S PROPERTY LANGUAGE C)

for each of your .S files. Then they got compiled in...

Chamfron answered 11/3, 2015 at 14:12 Comment(3)
I suppose that is an option that would work. But why not just enable assembly via the enable_language(ASM) command?Cowled
And actually, I do have CMake set to use gcc instead of as for building assembly files.Cowled
I actually had to use this technique with the language set to ASM_NASM so cmake would include my files. Otherwise, it would just ignore the nasm altogether.Kerianne

© 2022 - 2024 — McMap. All rights reserved.