1
votes

I am using CMake to cross compile a C project for an embedded (heterogeneous) multi-core system. The compiler takes an mandatory argument (-t<type>, the target type). This flag has to be set to pass CMake's compiler test. I am adding this flag in a toolchain file as follows:

add_compile_options(-tMYPLATFORMTYPE)

The problem with this approach is, all project files will be compiled with this flag. Is there a way to configure compile flags for the test compilation only, without affecting the main project configuration? (Note: Within the project different files shall have different values for this flag.)

What I am looking for is something like:

set(CMAKE_TRY_COMPILE_COMPILE_OPTIONS "-tMYPLATFORMTYPE")

I could disabled the compile test, but I would prefer to keep it.

1
all project files will be compiled with this flag - do you compile other files for a different platform?KamilCuk
@KamilCuk Kind of, it is a multi core system.sergej

1 Answers

0
votes

You can check the IN_TRY_COMPILE property and set the flag for try-compile configurations only:

get_property(IS_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE)
if(IS_IN_TRY_COMPILE)
    add_compile_options(-tMYPLATFORMTYPE)
endif()