[CMake] Add compile flags or defines without adding to ASM_ settings

Richard A. Smith smith at whoop.com
Mon Sep 10 15:06:06 EDT 2018


I'm having a tough time figuring out how to get some compile flags added 
to one of my targets without it breaking the ASM source file compile.

I currently have a build with a C_CLAGS setting that looks like below:

set(CMAKE_C_FLAGS          "${GCC_PROCESSOR_FLAGS} 
${GCC_OPTIMIZATION_FLAGS} ${GCC_WARNING_FLAGS} ${GCC_DEBUG_FLAGS} 
${GCC_C_FLAGS} ")

The only important part of the above is the GCC_DEBUG_FLAGS which looks 
like this:

set(GCC_DEBUG_FLAGS "-g3 -ggdb -DDEBUG -DMXC_ASSERT_ENABLE")

I'm in the process of creating a "release" build.  I'd prefer to make a 
release target instead of generating with 'cmake -D RELEASE'

For my release build.  I'd like to have the same options as above except 
for  ${GCC_DEBUG_FLAGS}.  Those should be omitted.  However, I'd still 
like them included for all the other targets.

So I changed CMAKE_C_FLAGS to the following:

set(CMAKE_C_FLAGS          "${GCC_PROCESSOR_FLAGS} 
${GCC_OPTIMIZATION_FLAGS} ${GCC_WARNING_FLAGS} ${GCC_C_FLAGS} ")

Essentially removing setting the debug flags by default.

Now my release target works fine.  No debug settings.

The problem comes when I try to add those debug options back into the 
other builds using the per target config methods.

Doesn't matter if I use target_compile_options() or 
set_target_properties() and change the COMPILE_FLAGS or COMPILE_OPTIONS 
property the result is the same.

What happens is that all the options that I specify also get added to 
the ASM_FLAGS setting.

In my sources list what looks similar to the following:

set(PROJ_SOURCES
         ${PROJ_DIRECTORY}/file1.c
         ${PROJ_DIRECTORY}/file2.c
         ${PROJ_DIRECTORY}/asm_file.S )

When -DDEBUG -DMXC_ASSERT_ENABLE get added to ASM_FLAGS then the 
assembler chokes on -DDEBUG

/usr/bin/arm-none-eabi-as: unrecognized option '-EBUG'

I've also tried breaking the options apart so that the -D options are on 
their own and I used target_compile_definitions() to set just the defines.

The result is still the same but instead of getting added to ASM_FLAGS 
they get added to ASM_DEFINES but the assembler still chokes.

How can I add compile options to my targets that only get added to 
C_FLAGS and not to my ASM_FLAGS?

Thanks.

-- 
Richard A. Smith
smith at whoop.com


More information about the CMake mailing list