How to add definitions with CMake?

vyo2003
Posts: 19
Joined: Fri Dec 22, 2017 8:36 am

How to add definitions with CMake?

Postby vyo2003 » Sat Jan 26, 2019 6:01 pm

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?

vyo2003
Posts: 19
Joined: Fri Dec 22, 2017 8:36 am

Re: How to add definitions with CMake?

Postby vyo2003 » Sat Jan 26, 2019 6:37 pm

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".

Who is online

Users browsing this forum: No registered users and 135 guests