| 2894 | } |
| 2895 | |
| 2896 | void cmLocalGenerator::CopyPchCompilePdb( |
| 2897 | std::string const& config, std::string const& language, |
| 2898 | cmGeneratorTarget* target, cmGeneratorTarget* reuseTarget, |
| 2899 | std::vector<std::string> const& extensions) |
| 2900 | { |
| 2901 | std::string const copy_script = cmStrCat(target->GetSupportDirectory(), |
| 2902 | "/copy_idb_pdb_", config, ".cmake"); |
| 2903 | cmGeneratedFileStream file(copy_script); |
| 2904 | file.SetCopyIfDifferent(true); |
| 2905 | |
| 2906 | file << "# CMake generated file\n"; |
| 2907 | |
| 2908 | file << "# The compiler generated pdb file needs to be written to disk\n" |
| 2909 | << "# by mspdbsrv. The foreach retry loop is needed to make sure\n" |
| 2910 | << "# the pdb file is ready to be copied.\n\n"; |
| 2911 | |
| 2912 | auto configGenex = [&](cm::string_view expr) -> std::string { |
| 2913 | if (this->GetGlobalGenerator()->IsMultiConfig()) { |
| 2914 | return cmStrCat("$<$<CONFIG:", config, ">:", expr, '>'); |
| 2915 | } |
| 2916 | return std::string(expr); |
| 2917 | }; |
| 2918 | |
| 2919 | std::vector<std::string> outputs; |
| 2920 | auto replaceExtension = [](std::string const& path, |
| 2921 | std::string const& ext) -> std::string { |
| 2922 | auto const dir = cmSystemTools::GetFilenamePath(path); |
| 2923 | auto const base = cmSystemTools::GetFilenameWithoutLastExtension(path); |
| 2924 | if (dir.empty()) { |
| 2925 | return cmStrCat(base, ext); |
| 2926 | } |
| 2927 | return cmStrCat(dir, '/', base, ext); |
| 2928 | }; |
| 2929 | for (auto const& extension : extensions) { |
| 2930 | std::string const from_file = |
| 2931 | replaceExtension(reuseTarget->GetCompilePDBPath(config), extension); |
| 2932 | std::string const to_dir = target->GetCompilePDBDirectory(config); |
| 2933 | std::string const to_file = |
| 2934 | replaceExtension(reuseTarget->GetCompilePDBName(config), extension); |
| 2935 | std::string const dest_file = cmStrCat(to_dir, '/', to_file); |
| 2936 | |
| 2937 | file << "foreach(retry RANGE 1 30)\n"; |
| 2938 | file << " if (EXISTS \"" << from_file << "\" AND (NOT EXISTS \"" |
| 2939 | << dest_file << "\" OR NOT \"" << dest_file << "\" IS_NEWER_THAN \"" |
| 2940 | << from_file << "\"))\n"; |
| 2941 | file << " file(MAKE_DIRECTORY \"" << to_dir << "\")\n"; |
| 2942 | file << " execute_process(COMMAND ${CMAKE_COMMAND} -E copy"; |
| 2943 | file << " \"" << from_file << "\"" << " \"" << to_dir |
| 2944 | << "\" RESULT_VARIABLE result " << " ERROR_QUIET)\n"; |
| 2945 | file << " if (NOT result EQUAL 0)\n" |
| 2946 | << " execute_process(COMMAND ${CMAKE_COMMAND}" |
| 2947 | << " -E sleep 1)\n" |
| 2948 | << " else()\n"; |
| 2949 | file << " break()\n" |
| 2950 | << " endif()\n"; |
| 2951 | file << " elseif(NOT EXISTS \"" << from_file << "\")\n" |
| 2952 | << " execute_process(COMMAND ${CMAKE_COMMAND}" << " -E sleep 1)\n" |
| 2953 | << " endif()\n"; |
no test coverage detected