ESP IDF - CMakeList Configuration for Multiple Projects
Posted: Mon Nov 06, 2023 4:40 pm
I've 3 projects and I want to manage them in a single project environment. I've a list of components under folder components and I've 3 lists in my top level CMakeLists.txt file for components to be built for each project. It's something like this
I noticed that CONFIG definitions are available after project() call. But I need this before because I need to update my component list to be built and pass it to CMake build system by calling project(). Therefore, I'm parsing sdkconfig file at top of my CMakeLists.txt file to determine project type which is set via menuconfig.
So far so good it works but my problem is I can't pass PROJECT_TYPE info to my components CMakeLists.txt file. I know that CONFIG_PROJECT_TYPE is available to components but When I called project() I observed following:
It's called twice and only in the second run, PROJECT_TYPE variable is available. This causes compile error because I conditionally change required component list considering selected project type.
How can I fix this problem? Is there any easier way to handle this?
Thanks in advance!
Code: Select all
list(APPEND COMPONENTS_PROJECT_A
comp1
comp2
comp3
)
list(APPEND COMPONENTS_PROJECT_B
comp2
comp3
comp4
)
list(APPEND COMPONENTS_PROJECT_C
comp1
comp3
comp5
)
Code: Select all
..... SDKCONFIG PARSING ....
if(PROJECT_TYPE STREQUAL "PROJECT_A")
set(REQUIRED_COMPONENTS ${COMPONENTS_PROJECT_A})
elseif(PROJECT_TYPE STREQUAL "PROJECT_B")
set(REQUIRED_COMPONENTS ${COMPONENTS_PROJECT_B})
elseif(PROJECT_TYPE STREQUAL "PROJECT_C")
set(REQUIRED_COMPONENTS ${COMPONENTS_PROJECT_C})
else()
message(FATAL_ERROR)
endif()
#Only build required components rather than everything in components directories.
set(COMPONENTS ${REQUIRED_COMPONENTS})
Code: Select all
-- Calling project(XXXXXXX)
-- ccache will be used for faster recompilation
-- Building ESP-IDF components for target esp32
-- Component-level PROJECT_TYPE:
.......
.......
.......
-- Component-level PROJECT_TYPE: PROJECT_A
How can I fix this problem? Is there any easier way to handle this?
Thanks in advance!