compiling assembly(.s) files in cmake

1.4k views Asked by At

I am working on an embedded project with windriver compiler The obj file(crt0.o) has the starting point(contains “main”) as per compiler design. In my project, we have written our own assemlbly file(crt0.s). now i want to compile this into crt0.o and put it for linking. I tried the below way,

file(GLOB src_pbl ${BOOT_DIR}/pbl/src/.c
                  ${BOOT_DIR}/pbl/src/crt0.s
                  ${BOOT_DIR}/common/FlexCAN/.c)
add_executable(pbl ${src_pbl})

But it is not working. The crt0.s file is not getting compiled into crt0.o file. the linker took the crt0.o file from the default compiler path.

am I passing the .s file correctly to the target?

1

There are 1 answers

1
bad1dea5 On

If you haven't already you need to enable_language(ASM) for your project, or one of the other assembly compilers ie ASM_ATT or ASM_MASM etc. This has to be done before the project function.

Also don't use file(GLOB), use target_sources instead.

I do it like this:

enable_language(ASM)

project(${METADATA_NAME})

target_sources(${PROJECT_NAME}
    PRIVATE
        #
        #   assembler
        #
        ${CMAKE_CURRENT_LIST_DIR}/_start.s

        #
        #   c++
        #
        ${CMAKE_CURRENT_LIST_DIR}/Main.cpp
)