| 1991 | } |
| 1992 | |
| 1993 | bool cmGlobalNinjaGenerator::WriteTargetCleanAdditional(std::ostream& os) |
| 1994 | { |
| 1995 | auto const& lgr = this->LocalGenerators.at(0); |
| 1996 | std::string cleanScriptRel = "CMakeFiles/clean_additional.cmake"; |
| 1997 | std::string cleanScriptAbs = |
| 1998 | cmStrCat(lgr->GetBinaryDirectory(), '/', cleanScriptRel); |
| 1999 | std::vector<std::string> const& configs = this->GetConfigNames(); |
| 2000 | |
| 2001 | // Check if there are additional files to clean |
| 2002 | bool empty = true; |
| 2003 | for (auto const& config : configs) { |
| 2004 | auto const it = this->Configs.find(config); |
| 2005 | if (it != this->Configs.end() && |
| 2006 | !it->second.AdditionalCleanFiles.empty()) { |
| 2007 | empty = false; |
| 2008 | break; |
| 2009 | } |
| 2010 | } |
| 2011 | if (empty) { |
| 2012 | // Remove cmake clean script file if it exists |
| 2013 | cmSystemTools::RemoveFile(cleanScriptAbs); |
| 2014 | return false; |
| 2015 | } |
| 2016 | |
| 2017 | // Write cmake clean script file |
| 2018 | { |
| 2019 | cmGeneratedFileStream fout(cleanScriptAbs); |
| 2020 | if (!fout) { |
| 2021 | return false; |
| 2022 | } |
| 2023 | fout << "# Additional clean files\ncmake_minimum_required(VERSION 3.16)\n"; |
| 2024 | for (auto const& config : configs) { |
| 2025 | auto const it = this->Configs.find(config); |
| 2026 | if (it != this->Configs.end() && |
| 2027 | !it->second.AdditionalCleanFiles.empty()) { |
| 2028 | fout << "\nif(\"${CONFIG}\" STREQUAL \"\" OR \"${CONFIG}\" STREQUAL \"" |
| 2029 | << config << "\")\n"; |
| 2030 | fout << " file(REMOVE_RECURSE\n"; |
| 2031 | for (std::string const& acf : it->second.AdditionalCleanFiles) { |
| 2032 | fout << " " |
| 2033 | << cmOutputConverter::EscapeForCMake( |
| 2034 | this->ConvertToNinjaPath(acf)) |
| 2035 | << '\n'; |
| 2036 | } |
| 2037 | fout << " )\n"; |
| 2038 | fout << "endif()\n"; |
| 2039 | } |
| 2040 | } |
| 2041 | } |
| 2042 | // Register clean script file |
| 2043 | lgr->GetMakefile()->AddCMakeOutputFile(cleanScriptAbs); |
| 2044 | |
| 2045 | // Write rule |
| 2046 | { |
| 2047 | cmNinjaRule rule("CLEAN_ADDITIONAL"); |
| 2048 | rule.Command = cmStrCat( |
| 2049 | this->CMakeCmd(), " -DCONFIG=$CONFIG -P ", |
| 2050 | lgr->ConvertToOutputFormat(this->NinjaOutputPath(cleanScriptRel), |
no test coverage detected