Page 1 of 1

How to add definitions with CMake?

Posted: Sat Jan 26, 2019 6:01 pm
by vyo2003
Hello. I want to add some preprocessor flags to both my sources and other project components.

For make I create

Code: Select all

Makefile.projbuild
with

Code: Select all

CPPFLAGS += -DMY_LOVELY_DEFINITION
How can I do that with CMake?

Re: How to add definitions with CMake?

Posted: Sat Jan 26, 2019 6:37 pm
by vyo2003
Ok, got it by myself :D.

Solution: add

Code: Select all

target_compile_options(${COMPONENT_TARGET} PUBLIC -DYOUR_LOVELY_DEFINITIONS)
somwhere after

Code: Select all

register_component()
in your component's CMakeLists.txt.
Hope that it will help somebody!
P.S.: it is probably also a good idea to warp it into fuction like "project_compile_options" or "global_compile_options".