question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cmakelists.txt suggestions for multiple components

See original GitHub issue

I was able to get it included by adding this to my CMakeLists at the top level:

set(EXTRA_COMPONENT_DIRS "components/cpp_utils")

and then in the cpp_utils folder, I added this:

# Edit following two lines to set component requirements (see docs)
set(COMPONENT_REQUIRES
  "console"
  "fatfs"
  "json"
  "mdns"
  "nvs_flash"
)
set(COMPONENT_PRIV_REQUIRES )

file(GLOB COMPONENT_SRCS
  LIST_DIRECTORIES false
  "*.h"
  "*.cpp"
  "*.c"
  "*.S"
)
set(COMPONENT_ADD_INCLUDEDIRS ".")

register_component()

My question is, if I have a 2nd Library next to cpp_utils in the components folder, how does it know about cpp_utils. I tried adding it in the COMPONENT_REQUIRES , but that doesn’t seem to work…

thoughts?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:18 (6 by maintainers)

github_iconTop GitHub Comments

6reactions
valeroscommented, May 7, 2020

Hi @wegunterjr ! Thanks for the report. First thing, you shouldn’t override EXTRA_COMPONENT_DIRS variable as PlatformIO also relies on it so you should append new components to this variable instead. I use the following configuration:

Top level CMakeLists.txt:


cmake_minimum_required(VERSION 3.5)
list(APPEND EXTRA_COMPONENT_DIRS "components/hello" "components/world")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(hello-world)

CMakeLists.txt for hello component:

idf_component_register(SRCS "hello.c" INCLUDE_DIRS ".")

CMakeLists.txt for world component that depends on hello:

idf_component_register(
  SRCS "world.c"
  INCLUDE_DIRS "."
  PRIV_REQUIRES hello
)
2reactions
valeroscommented, May 15, 2020

This is my top level folder CMakeLists.txt

SET(EXTRA_COMPONENT_DIRS  "components/cpp_utils")

should be

list(APPEND EXTRA_COMPONENT_DIRS "components/cpp_utils")

and must be placed above the line

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
cmake_minimum_required(VERSION 3.16.0)
list(APPEND EXTRA_COMPONENT_DIRS "components/cpp_utils")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(connect-esp32)
Read more comments on GitHub >

github_iconTop Results From Across the Web

basic project setup with multiple components - cmake
My project does not have a top-level CMakeLists file, it consists of multiple components. Some of them can be built independently, while some ......
Read more >
CMakeLists.txt | CLion Documentation - JetBrains
txt files to describe the build, contents, and target rules for a subdirectory. Type of a target added by a subdirectory CMakeLists. txt...
Read more >
[cmake-developers] [CMake] Support for multiple components ...
Here's my test case >> ===== >> file(WRITE file.txt.in "hi") ... Its still multiple files with their component specific names.
Read more >
How to setup CMAKE to compile with more than one ...
The main idea of components is that you declare include directories at component level and then specify dependencies between components. If you ...
Read more >
Build System - ESP32 - — ESP-IDF Programming Guide latest ...
See writing pure CMake components for some information about writing more ... The IDE will want to know the path to the project's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found