MCPcopy Create free account
hub / github.com/Kitware/CMake / WriteUnitySourceInclude

Method WriteUnitySourceInclude

Source/cmLocalGenerator.cxx:3094–3154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3092}
3093
3094void cmLocalGenerator::WriteUnitySourceInclude(
3095 std::ostream& unity_file, cm::optional<std::string> const& cond,
3096 std::string const& sf_full_path, cmValue beforeInclude, cmValue afterInclude,
3097 cmValue uniqueIdName, UnityPathMode pathMode,
3098 std::string const& unityFileDirectory) const
3099{
3100 if (cond) {
3101 unity_file << "#if " << *cond << "\n";
3102 }
3103
3104 std::string pathToHash;
3105 std::string relocatableIncludePath;
3106 auto PathEqOrSubDir = [](std::string const& a, std::string const& b) {
3107 return (cmSystemTools::ComparePath(a, b) ||
3108 cmSystemTools::IsSubDirectory(a, b));
3109 };
3110 auto const path = cmSystemTools::GetFilenamePath(sf_full_path);
3111 if (PathEqOrSubDir(path, this->GetBinaryDirectory())) {
3112 relocatableIncludePath =
3113 cmSystemTools::RelativePath(unityFileDirectory, sf_full_path);
3114 pathToHash = "BLD_" +
3115 cmSystemTools::RelativePath(this->GetBinaryDirectory(), sf_full_path);
3116 } else if (PathEqOrSubDir(path, this->GetSourceDirectory())) {
3117 relocatableIncludePath =
3118 cmSystemTools::RelativePath(this->GetSourceDirectory(), sf_full_path);
3119 pathToHash = "SRC_" + relocatableIncludePath;
3120 } else {
3121 relocatableIncludePath = sf_full_path;
3122 pathToHash = "ABS_" + sf_full_path;
3123 }
3124
3125 if (cmNonempty(uniqueIdName)) {
3126 cmCryptoHash hasher(cmCryptoHash::AlgoMD5);
3127 unity_file << "/* " << pathToHash << " */\n"
3128 << "#undef " << *uniqueIdName << "\n"
3129 << "#define " << *uniqueIdName << " unity_"
3130 << hasher.HashString(pathToHash) << "\n";
3131 }
3132
3133 if (beforeInclude) {
3134 unity_file << *beforeInclude << "\n";
3135 }
3136
3137 // clang-tidy-17 has new include checks that needs NOLINT too.
3138 unity_file
3139 << "/* NOLINTNEXTLINE(bugprone-suspicious-include,misc-include-cleaner) "
3140 "*/\n";
3141 if (pathMode == UnityPathMode::Relative) {
3142 unity_file << "#include \"" << relocatableIncludePath << "\"\n";
3143 } else {
3144 unity_file << "#include \"" << sf_full_path << "\"\n";
3145 }
3146
3147 if (afterInclude) {
3148 unity_file << *afterInclude << "\n";
3149 }
3150 if (cond) {
3151 unity_file << "#endif\n";

Callers

nothing calls this directly

Calls 3

PathEqOrSubDirFunction · 0.85
cmNonemptyFunction · 0.85
HashStringMethod · 0.80

Tested by

no test coverage detected