[CMake] Build flags not applied during compiler testing on Ubuntu

Richard Shaw hobbes1069 at gmail.com
Wed Aug 22 16:23:47 EDT 2018


On Wed, Aug 22, 2018 at 3:02 PM Brad King <brad.king at kitware.com> wrote:

> On 08/22/2018 03:49 PM, Richard Shaw wrote:
> > Initially I tried setting the flags before invoking "project" and that
> seemed
> > to be enough for Fedora. I've tried other things as well that I've
> probably
> > forgotten but one other method I tried was:
> >
> > set(CMAKE_REQUIRED_DEFINITIONS "--specs=nosys.specs")
>
> That's only used by Check* modules.  It does not affect flags in general.
>

Good to know, I can remove that.



> From the ubuntu issue:
>
> > The target system is: Generic - 1 - arm
> > The host system is: Linux - 4.15.0-32-generic - x86_64
>
> You're cross-compiling.  What is your CMAKE_TOOLCHAIN_FILE?
>

Yes, I could have worded it better but I have tried passing the toolchain
file on the command line with the same result. Currently I'm using an
"include" of the toolchain file prior to calling "project" since 100% of
development happens on a PC instead of having to pass the
CMAKE_TOOLCHAIN_FILE option every time.

Here's the contents:

set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_SYSTEM_VERSION 1)


# specify the cross compiler
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(CMAKE_CXX_COMPILER arm-none-eabi-cpp)

set(CMAKE_EXE_LINKER_FLAGS "-T${CMAKE_SOURCE_DIR}/stm32_flash.ld")
set(CMAKE_EXECUTABLE_SUFFIX_C ".elf")
set(CMAKE_EXECUTABLE_SUFFIX_CXX ".elf")
set(CMAKE_EXECUTABLE_SUFFIX_ASM ".elf")

# Macro for elf->bin
macro(elf2bin target)
    add_custom_command(TARGET ${target}
    POST_BUILD COMMAND ${CMAKE_OBJCOPY} -O binary ${target}.elf
${target}.bin
    COMMENT "Creating binary for ${target}")
endmacro()

Thanks,
Richard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180822/16decfa1/attachment.html>


More information about the CMake mailing list