Set #define value from command line when compiling

Hi everybody,

I need to set the value of a C #define from the command line when I compile the Firmware.
I’m able to properly set a cache variable in the CMakeLists.txt, with set(TEST_DEF "0" CACHE STRING "Testing define"), and add the -D define flags to the compilation of source files with add_definitions(-DTEST_DEF=${TEST_DEF}). Now I just miss how to set it from the command line. I’ve tried something like:

make px4fmu-v4_default --cmake-args -DTEST_DEF=2

and all the other possible orders ( make --cmake-args -DTEST_DEF=2 px4fmu-v4_default), etc, but I always get the error:

make: unrecognized option '--cmake-args'
make: invalid option -- 'D'
make: invalid option -- 'K'
make: invalid option -- 'Y'
make: invalid option -- 'E'
make: invalid option -- '_'
make: invalid option -- 'P'
Usage: make [options] [target] ...
Options: ...

Should I add something in the makefile as well?
If you could give me some tips about it that’d be great :slight_smile:

Thanks,
Marco.

I also wonder about this. Did you figure it out?