| 3010 | } |
| 3011 | |
| 3012 | std::string cmGeneratorTarget::GetPchHeader(std::string const& config, |
| 3013 | std::string const& language, |
| 3014 | std::string const& arch) const |
| 3015 | { |
| 3016 | if (language != "C" && language != "CXX" && language != "OBJC" && |
| 3017 | language != "OBJCXX") { |
| 3018 | return std::string(); |
| 3019 | } |
| 3020 | |
| 3021 | if (this->GetPropertyAsBool("DISABLE_PRECOMPILE_HEADERS")) { |
| 3022 | return std::string(); |
| 3023 | } |
| 3024 | cmGeneratorTarget const* generatorTarget = this; |
| 3025 | cmGeneratorTarget const* reuseTarget = this->GetPchReuseTarget(); |
| 3026 | bool const haveReuseTarget = reuseTarget && reuseTarget != this; |
| 3027 | if (reuseTarget) { |
| 3028 | generatorTarget = reuseTarget; |
| 3029 | } |
| 3030 | |
| 3031 | auto const inserted = |
| 3032 | this->PchHeaders.insert(std::make_pair(language + config + arch, "")); |
| 3033 | if (inserted.second) { |
| 3034 | std::vector<BT<std::string>> const headers = |
| 3035 | this->GetPrecompileHeaders(config, language); |
| 3036 | if (headers.empty() && !haveReuseTarget) { |
| 3037 | return std::string(); |
| 3038 | } |
| 3039 | std::string& filename = inserted.first->second; |
| 3040 | |
| 3041 | std::map<std::string, std::string> const languageToExtension = { |
| 3042 | { "C", ".h" }, |
| 3043 | { "CXX", ".hxx" }, |
| 3044 | { "OBJC", ".objc.h" }, |
| 3045 | { "OBJCXX", ".objcxx.hxx" } |
| 3046 | }; |
| 3047 | |
| 3048 | filename = generatorTarget->GetCMFSupportDirectory(); |
| 3049 | |
| 3050 | if (this->GetGlobalGenerator()->IsMultiConfig()) { |
| 3051 | filename = cmStrCat(filename, '/', config); |
| 3052 | } |
| 3053 | |
| 3054 | // This is acceptable as its the source file, won't have a rename/hash |
| 3055 | filename = |
| 3056 | cmStrCat(filename, "/cmake_pch", arch.empty() ? "" : cmStrCat('_', arch), |
| 3057 | languageToExtension.at(language)); |
| 3058 | |
| 3059 | std::string const filename_tmp = cmStrCat(filename, ".tmp"); |
| 3060 | if (!haveReuseTarget) { |
| 3061 | cmValue pchPrologue = |
| 3062 | this->Makefile->GetDefinition("CMAKE_PCH_PROLOGUE"); |
| 3063 | cmValue pchEpilogue = |
| 3064 | this->Makefile->GetDefinition("CMAKE_PCH_EPILOGUE"); |
| 3065 | |
| 3066 | std::string firstHeaderOnDisk; |
| 3067 | { |
| 3068 | cmGeneratedFileStream file( |
| 3069 | filename_tmp, false, |
no test coverage detected