Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add C++ language standard menu item #205

Closed
wants to merge 10 commits into from
94 changes: 94 additions & 0 deletions avr/boards.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ menu.LTO=Compiler LTO
menu.variant=Variant
menu.pinout=Pinout
menu.bootloader=Bootloader
menu.LanguageStandard=Language Standard


######################
Expand Down Expand Up @@ -241,6 +242,21 @@ menu.bootloader=Bootloader
1284.menu.clock.1MHz_internal.build.f_cpu=1000000L


# C++ Language Standard
1284.menu.LanguageStandard.Default=Default
1284.menu.LanguageStandard.Default.compiler.cpp.extra_flags=
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler.cpp.extra_flags property is already in use by the LTO board option:

1284.menu.LTO.Os.compiler.cpp.extra_flags=

Although it is possible to do this by using dedicated properties in each of the options and then defining compiler.cpp.extra_flags by referencing each of the dedicated properties (e.g., compiler.cpp.extra_flags={lto_flags} {std_flag}), the platform really shouldn't be using the compiler.cpp.extra_flags property at all, since it is intended to be left for the use of the platform user in order to allow them to customize the compilation command. If the platform authors uses these properties then when the user tries to use them their definition overrides the platform's definition of the property. The platform author has the power to use any arbitrary property name they like so they have no need to monopolize the user's properties.
Some related discussion on that subject here: arduino/arduino-cli#846

Copy link
Contributor Author

@DrItanium DrItanium Jan 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know. I do not use LTO so I did not see the conflict / overwrite. I incorrectly assumed that compiler.cpp.extra_flags was unique to each menu item and was concatenated magically. After typing that previous sentence out, I realize how absurd that assumption was.

Would updating the platform.txt to have a compiler.cpp.languageStandard variable make more sense? While specific to the current problem, it would never run afoul of other places in the build process.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a good approach. The alternative would be to use a single property for all the board level extra flags for each compilation recipe. For example:
boards.txt

...
1284.menu.LTO.Os_flto.compiler.cpp.board_extra_flags.lto=-Wextra -flto -g
...
1284.menu.CppLanguageStandard.Cpp11.compiler.cpp.board_extra_flags.std=-std=gnu++11
...
1284.compiler.cpp.board_extra_flags={compiler.cpp.board_extra_flags.lto} {compiler.cpp.board_extra_flags.std}
...

platform.txt

compiler.cpp.flags=-c -g -Os {compiler.warning_flags} {compiler.cpp.board_extra_flags} -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD

But there's no functional different between the two approaches. It's purely a style choice, which would be for MCUdude to make. I'm only an interested 3rd party in this project.

Note that there is no magic to these particular property names. I just made something up at random for the sake of the example. They could just as well be named foobar. It can be a bit confusing because some property names have special treatment by the build system, but the platform author is also welcome to use arbitrary properties of any name they like as long as they don't collide with the build properties that have special treatment.

I realize how absurd that assumption was.

I don't think so. The platform system is pretty complex and the fact that it uses this custom "properties" data format makes it even more difficult to understand. Fortunately, the documentation has improved a bit since the time I learned it mostly through reverse engineering the existing platforms and a ton of trial and error.

Copy link
Contributor Author

@DrItanium DrItanium Jan 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose compiler.cpp.languageStandard over compiler.cpp.board_extra_flags.std because I have to deal with many compilers at work which do not use -std= to specify the C++ language mode (--c++11, --eecpp, etc). Call it descriptive paranoia.

Regardless of the style chosen by MCUDude, I really want the ability to change the C++ language standard without having to manually modify platform.txt.

Thank you for letting me know that I was clobbering options :).


1284.menu.LanguageStandard.Cpp11=C++11
1284.menu.LanguageStandard.Cpp11.compiler.cpp.extra_flags=-std=gnu++11

1284.menu.LanguageStandard.Cpp14=C++14
1284.menu.LanguageStandard.Cpp14.compiler.cpp.extra_flags=-std=gnu++14

1284.menu.LanguageStandard.Cpp17=C++17
1284.menu.LanguageStandard.Cpp17.compiler.cpp.extra_flags=-std=gnu++17




###########################
#### ATmega644/A/P/PA ####
Expand Down Expand Up @@ -446,6 +462,19 @@ menu.bootloader=Bootloader
644.menu.clock.1MHz_internal.build.clock_speed={build.f_cpu}
644.menu.clock.1MHz_internal.build.f_cpu=1000000L

# C++ Language Standard
644.menu.LanguageStandard.Default=Default
644.menu.LanguageStandard.Default.compiler.cpp.extra_flags=

644.menu.LanguageStandard.Cpp11=C++11
644.menu.LanguageStandard.Cpp11.compiler.cpp.extra_flags=-std=gnu++11

644.menu.LanguageStandard.Cpp14=C++14
644.menu.LanguageStandard.Cpp14.compiler.cpp.extra_flags=-std=gnu++14

644.menu.LanguageStandard.Cpp17=C++17
644.menu.LanguageStandard.Cpp17.compiler.cpp.extra_flags=-std=gnu++17



##########################
Expand Down Expand Up @@ -672,6 +701,19 @@ menu.bootloader=Bootloader
324.menu.clock.1MHz_internal.build.clock_speed={build.f_cpu}
324.menu.clock.1MHz_internal.build.f_cpu=1000000L

# C++ Language Standard
324.menu.LanguageStandard.Default=Default
324.menu.LanguageStandard.Default.compiler.cpp.extra_flags=

324.menu.LanguageStandard.Cpp11=C++11
324.menu.LanguageStandard.Cpp11.compiler.cpp.extra_flags=-std=gnu++11

324.menu.LanguageStandard.Cpp14=C++14
324.menu.LanguageStandard.Cpp14.compiler.cpp.extra_flags=-std=gnu++14

324.menu.LanguageStandard.Cpp17=C++17
324.menu.LanguageStandard.Cpp17.compiler.cpp.extra_flags=-std=gnu++17



##########################
Expand Down Expand Up @@ -878,6 +920,19 @@ menu.bootloader=Bootloader
164.menu.clock.1MHz_internal.build.clock_speed={build.f_cpu}
164.menu.clock.1MHz_internal.build.f_cpu=1000000L

# C++ Language Standard
164.menu.LanguageStandard.Default=Default
164.menu.LanguageStandard.Default.compiler.cpp.extra_flags=

164.menu.LanguageStandard.Cpp11=C++11
164.menu.LanguageStandard.Cpp11.compiler.cpp.extra_flags=-std=gnu++11

164.menu.LanguageStandard.Cpp14=C++14
164.menu.LanguageStandard.Cpp14.compiler.cpp.extra_flags=-std=gnu++14

164.menu.LanguageStandard.Cpp17=C++17
164.menu.LanguageStandard.Cpp17.compiler.cpp.extra_flags=-std=gnu++17



#####################
Expand Down Expand Up @@ -1053,6 +1108,19 @@ menu.bootloader=Bootloader
32.menu.clock.1MHz_internal.bootloader.ckopt_bit=1
32.menu.clock.1MHz_internal.build.f_cpu=1000000L

# C++ Language Standard
32.menu.LanguageStandard.Default=Default
32.menu.LanguageStandard.Default.compiler.cpp.extra_flags=

32.menu.LanguageStandard.Cpp11=C++11
32.menu.LanguageStandard.Cpp11.compiler.cpp.extra_flags=-std=gnu++11

32.menu.LanguageStandard.Cpp14=C++14
32.menu.LanguageStandard.Cpp14.compiler.cpp.extra_flags=-std=gnu++14

32.menu.LanguageStandard.Cpp17=C++17
32.menu.LanguageStandard.Cpp17.compiler.cpp.extra_flags=-std=gnu++17



#####################
Expand Down Expand Up @@ -1228,6 +1296,19 @@ menu.bootloader=Bootloader
16.menu.clock.1MHz_internal.bootloader.ckopt_bit=1
16.menu.clock.1MHz_internal.build.f_cpu=1000000L

# C++ Language Standard
16.menu.LanguageStandard.Default=Default
16.menu.LanguageStandard.Default.compiler.cpp.extra_flags=

16.menu.LanguageStandard.Cpp11=C++11
16.menu.LanguageStandard.Cpp11.compiler.cpp.extra_flags=-std=gnu++11

16.menu.LanguageStandard.Cpp14=C++14
16.menu.LanguageStandard.Cpp14.compiler.cpp.extra_flags=-std=gnu++14

16.menu.LanguageStandard.Cpp17=C++17
16.menu.LanguageStandard.Cpp17.compiler.cpp.extra_flags=-std=gnu++17



#####################
Expand Down Expand Up @@ -1402,3 +1483,16 @@ menu.bootloader=Bootloader
8535.menu.clock.1MHz_internal.bootloader.sut_cksel_bits=100001
8535.menu.clock.1MHz_internal.bootloader.ckopt_bit=1
8535.menu.clock.1MHz_internal.build.f_cpu=1000000L

# C++ Language Standard
8535.menu.LanguageStandard.Default=Default
8535.menu.LanguageStandard.Default.compiler.cpp.extra_flags=

8535.menu.LanguageStandard.Cpp11=C++11
8535.menu.LanguageStandard.Cpp11.compiler.cpp.extra_flags=-std=gnu++11

8535.menu.LanguageStandard.Cpp14=C++14
8535.menu.LanguageStandard.Cpp14.compiler.cpp.extra_flags=-std=gnu++14

8535.menu.LanguageStandard.Cpp17=C++17
8535.menu.LanguageStandard.Cpp17.compiler.cpp.extra_flags=-std=gnu++17