hxcpp icon indicating copy to clipboard operation
hxcpp copied to clipboard

Allow overwriting default c++ standard for a group of files

Open tobil4sk opened this issue 9 months ago • 2 comments

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.

tobil4sk avatar Mar 13 '25 15:03 tobil4sk

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>

Aidan63 avatar Mar 14 '25 19:03 Aidan63

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.

tobil4sk avatar Sep 30 '25 09:09 tobil4sk