In Unreal Engine, the .target.cs files are part of the project or plugin build configuration. They define various settings regarding how the engine should build your project or the specific target within the project (for example, game, editor, server). However, logging specific settings directly from .target.cs files like CppStandard is not supported natively because these files are meant for defining settings, not for runtime or compile-time logging.
If you want to verify the C++ standard used in your build by checking the setting programmatically, you typically can't do it directly through the Unreal Engine scripting or build configuration files. Instead, you would inspect this configuration manually or configure it to ensure it uses the standard you desire.
Manual Configuration:
Here’s how you can ensure and set the C++ standard in your Unreal Engine project:
-
Modify Target Configuration:
- Open your project's
.target.cs file. It might be named similarly to MyProject.Target.cs or MyProjectEditor.Target.cs if it's specifically for the editor build of your project.
- Add or modify the
CppStandard property of the TargetRules derived class inside this file. Set it to target C++20 or whichever version of the C++ standard you are interested in.
Example:
using UnrealBuildTool;
using System.Collections.Generic;
public class MyProjectTarget : TargetRules
{
public MyProjectTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Game;
DefaultBuildSettings = BuildSettingsVersion.V2;
// Set C++ Standard to C++20
CppStandard = CppStandardVersion.Cpp20;
}
}
-
Check Compilation Arguments:
- After setting this, you could look at the actual compilation commands issued by UnrealBuildTool (UBT) by building your project with verbose logging. This can sometimes be done using the build output window in Unreal Editor or a command-line build using UnrealBuildTool with verbose flags.
Verifying with Compiler-specific Methods:
If you want to check programmatically within your C++ code which C++ standard is being used, you can rely on predefined macros:
#include <iostream>
void CheckCppStandard() {
#if __cplusplus == 201703L
std::cout << "C++17\n";
#elif __cplusplus == 202002L
std::cout << "C++20\n";
#else
std::cout << "Unknown or older C++ standard\n";
#endif
}
int main() {
CheckCppStandard();
return 0;
}
This piece of code checks the value of __cplusplus, which is a macro defined by the C++ standard to indicate the version of the C++ standard the compiler adheres to.
Conclusion:
While you can set and ensure the usage of a specific C++ standard in your Unreal Engine project's .target.cs file, checking this setting programmatically isn't straightforwardly supported within those configuration files. For verification, you typically review the build settings or use C++ macros to determine the standard currently in use by examining the compilation process or within the C++ code itself.