Allow overwriting default c++ standard for a group of files
Right now, setting the standard doesn't work using compilerflag:
<xml>
<files id="main">
<file name="main.cpp" />
<compilerflag value="-std=c++17" />
</files>
<target id="default" output="Main${DBG}" tool="linker" toolid="exe">
<files id="main" />
</target>
</xml>
#include <filesystem>
#include <iostream>
int main() {
std::cout << std::filesystem::absolute("Build.xml") << std::endl;
}
This is because of the order of the generated compiler flags:
g++ -std=c++17 [...] -std=c++11 [...] ./main.cpp
Hxcpp's default -std=c++11 comes last, so it takes priority. It would be nice to override the default just for a specific set of files, without having to use something like HXCPP_NO_CPP11 which disables c++11 globally.
Moving all user compiler flags after the toolchain's ones isn't possible because it would break include and define flag priority. Perhaps this is something that should be handled by adding a new xml tag, which would also allow compatibility with msvc where -std=c++17 is not a valid flag.
This is somewhat related to #1124.
Yes, this sounds good and is what I had in mind as part of #1124. Maybe an extra element on the files tag?
<files id="main" cxx_standard="17">
<file name="main.cpp" />
</files>
Maybe an extra element on the files tag?
Something like this is probably the best bet, since it provides compiler agnostic abstraction over the raw flags. It would require refactoring the current system though.
It might also be useful to be able to set a different standard for an individual file within a group.
In general the issue with toolchain flags taking priority over user flags seems to cause problems: #647 #737.