Page 1 of 1

CMAKE and compiler defines

Posted: Wed Jan 26, 2022 8:47 pm
by dovoto
I think I have a concept error and I could use some knowledge...

I have an idf project with the following structure (ish):

components
--component_1
----CMakeLists.txt
----sourc.cpp
--component_2
----CMakeLists.txt
----sourc.cpp
main
--main.cpp
--CMakeLists.txt
CMakeLists.txt
sdkcofig

My components require some processor defines and so in the top level CMakeLists.txt I do something like this:

Code: Select all

cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(my_amazing_project)

add_compile_definitions(
  "DO_THING_A"
  "ENABLE_AWESOMENESS"
)

message(STATUS "Building: root")
Now, if i check the build.ninja file the DEFINES variable in the
#############################################
# Order-only phony target for my_amazing_project.elf

has the correct defines...but these defines dont seem to be making it to the components (the compile command line output only has the -DESP_PLATFORM and version define set)

Do I need to set these defines some other way or at some other level in the cmake lists?

Thanks!

Re: CMAKE and compiler defines

Posted: Thu Jan 27, 2022 1:08 pm
by gtjoseph
Things like add_compile_options and add_compile_definitions have to come before the "project" statement.

Re: CMAKE and compiler defines

Posted: Fri Jan 28, 2022 8:17 pm
by dovoto
gtjoseph wrote:
Thu Jan 27, 2022 1:08 pm
Things like add_compile_options and add_compile_definitions have to come before the "project" statement.

Thanks!

Code: Select all

cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)

add_compile_definitions(
  "DO_THING_A"
  "ENABLE_AWESOMENESS"
)

project(my_amazing_project)



message(STATUS "Building: root")
did the trick