CppCompile: set options on file basis

Hey there!

I decided to invest my time into Gradle and try to use it for my C++ project.
Everything seems fine and dandy; also the documentation and samples are quite helpful.

However, I found a use case, that is not covered by the samples:

Few files inside my project needs to be compiled with slightly different compiler settings. Is there a way to set compiler options on a per file basis?

old_unmaintained_but_working_file.cpp → requires flag ‘-std=c++11’ to be passed
new_file.cpp → requires flag ‘-std=c++17’

I cannot use ‘-std=c++17’ for both files, because certain features are used within the ‘old_unmaintained_but_working_file.cpp’ that were removed in C++17 and no longer work.

After a bit of investigation, I came to the conclusion, that only one “CppCompile” task is generated per target, which makes things harder.

It would require me to spawn additional “CppCompile” tasks, which however seems not to be intended by the authors.

You have the right conclusion Julian. It’s a use case that was unfortunately never addressed since the beginning of the native support in Gradle. We hope to solve this issue at some point in Nokee (https://nokee.dev). The source set feature coming soon in Nokee sort of help solve such issue by allowing multiple source sets to be created where each source set can have different compile flags. However, we are still grouping the files by “set”. It’s not a very good solution when working on an embedded system and only wants/can turn off optimization on a single file, for example.