| 3115 | } |
| 3116 | |
| 3117 | std::string cmGeneratorTarget::GetPchSource(std::string const& config, |
| 3118 | std::string const& language, |
| 3119 | std::string const& arch) const |
| 3120 | { |
| 3121 | if (language != "C" && language != "CXX" && language != "OBJC" && |
| 3122 | language != "OBJCXX") { |
| 3123 | return std::string(); |
| 3124 | } |
| 3125 | auto const inserted = |
| 3126 | this->PchSources.insert(std::make_pair(language + config + arch, "")); |
| 3127 | if (inserted.second) { |
| 3128 | std::string const pchHeader = this->GetPchHeader(config, language, arch); |
| 3129 | if (pchHeader.empty()) { |
| 3130 | return std::string(); |
| 3131 | } |
| 3132 | std::string& filename = inserted.first->second; |
| 3133 | |
| 3134 | cmGeneratorTarget const* generatorTarget = this; |
| 3135 | cmGeneratorTarget const* reuseTarget = this->GetPchReuseTarget(); |
| 3136 | bool const haveReuseTarget = reuseTarget && reuseTarget != this; |
| 3137 | if (reuseTarget) { |
| 3138 | generatorTarget = reuseTarget; |
| 3139 | } |
| 3140 | |
| 3141 | filename = |
| 3142 | cmStrCat(generatorTarget->GetCMFSupportDirectory(), "/cmake_pch"); |
| 3143 | |
| 3144 | // For GCC the source extension will be transformed into .h[xx].gch |
| 3145 | if (!this->Makefile->IsOn("CMAKE_LINK_PCH")) { |
| 3146 | std::map<std::string, std::string> const languageToExtension = { |
| 3147 | { "C", ".h.c" }, |
| 3148 | { "CXX", ".hxx.cxx" }, |
| 3149 | { "OBJC", ".objc.h.m" }, |
| 3150 | { "OBJCXX", ".objcxx.hxx.mm" } |
| 3151 | }; |
| 3152 | |
| 3153 | filename = cmStrCat(filename, arch.empty() ? "" : cmStrCat('_', arch), |
| 3154 | languageToExtension.at(language)); |
| 3155 | } else { |
| 3156 | std::map<std::string, std::string> const languageToExtension = { |
| 3157 | { "C", ".c" }, { "CXX", ".cxx" }, { "OBJC", ".m" }, { "OBJCXX", ".mm" } |
| 3158 | }; |
| 3159 | |
| 3160 | filename = cmStrCat(filename, arch.empty() ? "" : cmStrCat('_', arch), |
| 3161 | languageToExtension.at(language)); |
| 3162 | } |
| 3163 | |
| 3164 | std::string const filename_tmp = cmStrCat(filename, ".tmp"); |
| 3165 | if (!haveReuseTarget) { |
| 3166 | { |
| 3167 | cmGeneratedFileStream file(filename_tmp); |
| 3168 | file << "/* generated by CMake */\n"; |
| 3169 | } |
| 3170 | cmFileTimes::Copy(pchHeader, filename_tmp); |
| 3171 | cmSystemTools::MoveFileIfDifferent(filename_tmp, filename); |
| 3172 | } |
| 3173 | } |
| 3174 | return inserted.first->second; |
no test coverage detected