grifcj
grifcj

Reputation: 433

cmake override archive command when building assembly source library w/ IAR toolchain

I'm attempting to build a static library with the IAR toolchain using cmake. I'm building only assembly files in this library (which I think is an important detail here), and they build fine. When it gets to the archiving step, however, I can see that its invoking the archiver with "GNU" style arguments.

"C:/Program Files (x86)/IAR Systems/Embedded Workbench 6.5/arm/bin/iarchive.exe" cr libasm.a  "somefile.s.obj" "someotherfile.s.obj"

Instead of 'cr' it needs to be '--create'

How does cmake determine the make up of this command and how can I specify what it needs to be for my toolchain?

My abridged cmake script for this library looks like this

enable_language(ASM)
add_library(asm ${ASM_SOURCES})
target_compile_options(asm PUBLIC ${ASM_COMPILE_FLAGS})
target_include_directories(asm PUBLIC ${INCLUDE_DIRS})

I am able to build some C/C++ archives in the same script with no issues. I've tried manually setting the CMAKE_AR in a few different spots and it doesn't work. Again, I'm building ONLY assembly files in this archive, so I'm not sure if that's why its not using those archive commands.

SET(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> --create -o <TARGET> <LINK_FLAGS> <OBJECTS>")
SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> --create -o <TARGET> <LINK_FLAGS> <OBJECTS>"

I've tried running this on cmake versions 3.4.0 and 3.4.1.

Upvotes: 2

Views: 809

Answers (1)

grifcj
grifcj

Reputation: 433

I found that setting CMAKE_ASM_CREATE_STATIC_LIBRARY replaced the command being invoked.

set(CMAKE_ASM_CREATE_STATIC_LIBRARY "<CMAKE_AR> <TARGET> --create <LINK_FLAGS> <OBJECTS> ")

I chose the makeup of the command based on the CXX archive command found in IAR-CXX.cmake

set(CMAKE_CXX_CREATE_STATIC_LIBRARY "<CMAKE_AR> <TARGET> --create <LINK_FLAGS> <OBJECTS> ")

Upvotes: 1

Related Questions