Issue
I have a project each I writing in C++. In this project I also use proto-c to generate header and source files (yes, this is mismatched and I would like it to stay that way it is possible ).
When I have tried compile the project a get error with -fpermissive flag, because some code in generated files it has wirtied in C. I want to deactivate this error using CMakeList, but simply add function add_compile_options(-fpermissive)
to CMakeLists.txt not works.
Below I present for you simplified tree each is part of project. This files is a component
in IDF enviroment and another CMakeLists
.
├── CMakeLists.txt
├── include
│ └── parser.hpp
├── proto
│ ├── configuration.proto
│ ├── timestamp.proto
│ ├── units.proto
├── protobuf-c
│ ├── configuration.pb-c.c
│ ├── timestamp.pb-c.c
│ ├── units.pb-c.c
├── protobuf-h
│ ├── configuration.pb-c.h
│ ├── timestamp.pb-c.h
│ ├── units.pb-c.h
├── parser.cpp
└── README.md
And content of CMakeLists.txt
idf_component_register(SRCS "parser.cpp"
"protobuf-c/timestamp.pb-c.c"
"protobuf-c/units.pb-c.c"
"protobuf-c/configuration.pb-c.c"
INCLUDE_DIRS "." "include" "protobuf-h"
REQUIRES protobuf-c )
add_compile_options(-fpermissive) // not working
Solution
You may set compiler flags and other options via target, which is created by
idf_component_register
command. The name of the target is contained in the COMPONENT_LIB
variable. E.g.:
target_compile_options(${COMPONENT_LIB} PRIVATE -fpermissive)
Make sure to place that line after the call to idf_component_register
.
This method is described in the ESP32 documentation: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/build-system.html#controlling-component-compilation
Answered By - Tsyvarev Answer Checked By - Dawn Plyler (WPSolving Volunteer)