CMAKE and compiler defines

dovoto
Posts: 27
Joined: Tue Apr 20, 2021 3:51 pm

CMAKE and compiler defines

Postby dovoto » Wed Jan 26, 2022 8:47 pm

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!

User avatar
gtjoseph
Posts: 92
Joined: Fri Oct 15, 2021 10:55 pm

Re: CMAKE and compiler defines

Postby gtjoseph » Thu Jan 27, 2022 1:08 pm

Things like add_compile_options and add_compile_definitions have to come before the "project" statement.

dovoto
Posts: 27
Joined: Tue Apr 20, 2021 3:51 pm

Re: CMAKE and compiler defines

Postby dovoto » Fri Jan 28, 2022 8:17 pm

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

Who is online

Users browsing this forum: No registered users and 107 guests