Specifying C++ Compiler Flags

SparkyNZ
Posts: 48
Joined: Thu Jan 04, 2024 9:01 pm

Specifying C++ Compiler Flags

Postby SparkyNZ » Sat Jan 06, 2024 4:01 am

I would like to suppress a compiler warning by passing in -Wdeprecated-copy compiler option.

I'm not sure how I can do this with the IDF environment. I tried this first in my top-level CMakeLists.txt:

Code: Select all

cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(paul_fabgl)
list (APPEND CFLAGS "-Wdeprecated-copy")
That didn't work so I tried old-school setting of CMAKE_CXX_FLAGS and CMAKE_C_FLAGS instead in both top-level and component level CMakeLists.txt:

Code: Select all

set(CMAKE_CXX_FLAGS
    "-Wdeprecated-copy")

set(CMAKE_C_FLAGS
    "-Wdeprecated-copy")
I still get the compiler warning:

Code: Select all

[build] C:\esp32\projects\paul_fabgl\components\fabgl\fabui.cpp: In member function void fabgl::uiCustomListBox::paintListBox()':
[build] C:\esp32\projects\paul_fabgl\components\fabgl\fabui.cpp:4189:61:warning: implicitly-declared 'constexpr fabgl::Rect& fabgl::Rect::operator=(const fabgl::Rect&)' is deprecated [-Wdeprecated-copy]
What am I doing wrong?

User avatar
ok-home
Posts: 78
Joined: Sun May 02, 2021 7:23 pm
Location: Russia Novosibirsk
Contact:

Re: Specifying C++ Compiler Flags

Postby ok-home » Sat Jan 06, 2024 4:23 am

Hey, watch this.
https://docs.espressif.com/projects/esp ... ystem.html
Overriding Default Build Specifications
The build sets some global build specifications (compile flags, definitions, etc.) that gets used in compiling all sources from all components.

For example, one of the default build specifications set is the compile option -Wextra. Suppose a user wants to use override this with -Wno-extra, it should be done after project():

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

idf_build_set_property(COMPILE_OPTIONS "-Wno-error" APPEND)
This ensures that the compile options set by the user won't be overridden by the default build specifications, since the latter are set inside project().

SparkyNZ
Posts: 48
Joined: Thu Jan 04, 2024 9:01 pm

Re: Specifying C++ Compiler Flags

Postby SparkyNZ » Sat Jan 06, 2024 6:17 am

Yes that kinda worked but its setting flags for C was well and I just need the C++ flags to be set.

Code: Select all

[build] cc1.exe:warning: command-line option -Wdeprecated-copy' is valid for C++/ObjC++ but not for C
Looking in the same area of the docs, I thought this is what I needed:

Code: Select all

target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-unused-variable)
Unfortunately that is complaining about my $[COMPONENT_LIB] (fabgl) not being built by this project:

CMakeLists.txt (top level):

Code: Select all

target_compile_options(fabgl PRIVATE -Wno-unused-variable)
Output:

Code: Select all

[cmake] CMake Error at CMakeLists.txt:22 (target_compile_options):
[cmake]   Cannot specify compile options for target "fabgl" which is not built by
[cmake]   this project.
So getting closer.. but not quite there yet. :-)

SparkyNZ
Posts: 48
Joined: Thu Jan 04, 2024 9:01 pm

Re: Specifying C++ Compiler Flags

Postby SparkyNZ » Sat Jan 06, 2024 6:18 am

Aha!

C_COMPILE_OPTIONS - compile options applied to all components' C source files

COMPILE_OPTIONS - compile options applied to all components' source files, regardless of it being C or C++

COMPILE_DEFINITIONS - compile definitions applied to all component source files

CXX_COMPILE_OPTIONS - compile options applied to all components' C++ source files

SparkyNZ
Posts: 48
Joined: Thu Jan 04, 2024 9:01 pm

Re: Specifying C++ Compiler Flags

Postby SparkyNZ » Sat Jan 06, 2024 6:37 am

Hmm. I thought the below line would do the trick but I don't think it's applying to the building of my fabgl component.

Code: Select all

idf_build_set_property(CXX_COMPILE_OPTIONS "-Wdeprecated-copy" APPEND) 


I've tried adding the same line to the CMakeLists.txt for my component and it's still not taking effect.

Code: Select all

[build] C:\esp32\projects\paul_fabgl\components\fabgl\canvas.cpp:71:29:warning: implicitly-declared 'constexpr fabgl::Rect& fabgl::Rect::operator=(const fabgl::Rect&)' is deprecated [-Wdeprecated-copy]
Is there a way to output the actually compiler command line (a verbose mode) so I can see what compiler flags are being passed into the compiler??

MicroController
Posts: 1708
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Specifying C++ Compiler Flags

Postby MicroController » Sat Jan 06, 2024 11:53 am

SparkyNZ wrote:
Sat Jan 06, 2024 6:37 am
Hmm. I thought the below line would do the trick but I don't think it's applying to the building of my fabgl component.

Code: Select all

idf_build_set_property(CXX_COMPILE_OPTIONS "-Wdeprecated-copy" APPEND)

Check out https://cmake.org/cmake/help/latest/com ... l#see-also
Is there a way to output the actually compiler command line (a verbose mode) so I can see what compiler flags are being passed into the compiler??
-> myproject/build/compile_commands.json

SparkyNZ
Posts: 48
Joined: Thu Jan 04, 2024 9:01 pm

Re: Specifying C++ Compiler Flags

Postby SparkyNZ » Sun Jan 07, 2024 2:53 am

Sorry I don't understand what I'm reading in the "See Also" section:
Image

I don't know what it means by "use the COMPILE_LANGUAGE generator" or:

To set per-language options, use the $<COMPILE_LANGUAGE> or $<COMPILE_LANGUAGE:languages> generator expressions.

Do I use add_compile_options() with $<COMPILE_LANGUAGE:cxx> somehow to specify C++ compiler options?

I had a look at C:\esp32\projects\paul_fabgl\build\compile_commands.json. The -Wdeprecated-copy is definitely there.

The option needed to be -Wno-deprecated-copy. That's why I was getting the warnings.

So the below command is doing the job for me now:

Code: Select all

idf_build_set_property(CXX_COMPILE_OPTIONS "-Wno-deprecated-copy" APPEND)

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot] and 123 guests