0

I am working on a CMAKE build system that cross compile ARM CortexM4 using Keil ARMCC toolset in Windows

I set the c compiler flags as the following

set(CMAKE_C_FLAGS  "-c --c99 --cpu=Cortex-M4.fp.sp --apcs=interwork --split_sections")

However, ARMCC compiler has options that requires to input a destination path and a file name. For instance, for each c source file, besides the object file output, I need to also output the source browser information and source dependence by adding the compiler options with the follow format:

--omf_browse=my_output_path/the_current_source_file.crf and --depend my_output_path/the_current_source_file.d

How can i add the above options to the CMAKE_C_FLAGS?

thanks

大陸北方網友
  • 3,696
  • 3
  • 12
  • 37
Chen
  • 326
  • 3
  • 12
  • Look at https://github.com/vpetrigo/arm-cmake-toolchains – Dmitry Sokolov Sep 03 '20 at 16:09
  • gcc compiler doesn't have options that requires to input a file name or path. as you can see from the example, the gcc compiler flags simply set as "-g3 -Og -Wall -pedantic -DDEBUG" – Chen Sep 06 '20 at 09:50
  • Basically, This is question is equivalent to "how to set the compiler flags for one input source file that produce multiple output files" In armcc compiler, besides the object output file the --omf_browse and --depend options also output browse information file and depend file, but the syntax requires to give a file name followed by the options. It's similar to visual studio c++ compiler pdb file, The CMAKE already have built-in mechanism to automatically give a name (which is the same as the source file name which different suffix). I wonder how to do the same in armcc compiler. – Chen Sep 06 '20 at 10:04

1 Answers1

0

The simple method is to set the property COMPILE_OPTIONS for each needed source file.

Here is the test CMakeLists.txt

project(TestSourceProp)

set(SOURCE_FILES
    main.c
    file.c
)

add_executable(${PROJECT_NAME} ${SOURCE_FILES})

foreach(SRC_ IN LISTS SOURCE_FILES)
    get_filename_component(SRC_BASENAME_ ${SRC_} NAME_WE)
    set_source_files_properties(${SRC_} PROPERTIES COMPILE_OPTIONS "--omf_browse=${SRC_BASENAME_}.crf;--depend=${SRC_BASENAME_}.d")
    get_source_file_property(SRC_PROP_ ${SRC_} COMPILE_OPTIONS)
    message(STATUS "${SRC_}: ${SRC_PROP_}")
endforeach()

The output:

...
-- main.c: --omf_browse=main.crf;--depend=main.d
-- file.c: --omf_browse=file.crf;--depend=file.d
-- Configuring done

Makefile:

CMakeFiles/TestSourceProp.dir/main.c.obj: ../main.c
    @$(CMAKE_COMMAND) -E cmake_echo_color ...
    gcc $(C_DEFINES) $(C_INCLUDES) $(C_FLAGS) --omf_browse=main.crf --depend=main.d -o CMakeFiles/TestSourceProp.dir/main.c.obj -c ...

Another way, I think, is to create a custom CMake-toolchain file.

Dmitry Sokolov
  • 3,118
  • 1
  • 30
  • 35
  • Thanks @Dmirty, That's was feasible workaround, not so elegant but doable. I don't know why CMAKE make it so difficult while other build systems such as Scons, Make can easily do this. – Chen Sep 09 '20 at 05:52