1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 19:08:07 +08:00

Makefiles: Fix CMAKE_EXPORT_COMPILE_COMMANDS crash with custom compile rule

Fixes: #21471
This commit is contained in:
Brad King
2020-11-20 09:45:14 -05:00
parent 1d1d78bbe1
commit 67e2130c96
3 changed files with 16 additions and 6 deletions

View File

@@ -838,13 +838,17 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
compileCommand.replace(compileCommand.find(langFlags), langFlags.size(),
this->GetFlags(lang, this->GetConfigName()));
std::string langDefines = std::string("$(") + lang + "_DEFINES)";
compileCommand.replace(compileCommand.find(langDefines),
langDefines.size(),
this->GetDefines(lang, this->GetConfigName()));
std::string::size_type ldPos = compileCommand.find(langDefines);
if (ldPos != std::string::npos) {
compileCommand.replace(ldPos, langDefines.size(),
this->GetDefines(lang, this->GetConfigName()));
}
std::string langIncludes = std::string("$(") + lang + "_INCLUDES)";
compileCommand.replace(compileCommand.find(langIncludes),
langIncludes.size(),
this->GetIncludes(lang, this->GetConfigName()));
std::string::size_type liPos = compileCommand.find(langIncludes);
if (liPos != std::string::npos) {
compileCommand.replace(liPos, langIncludes.size(),
this->GetIncludes(lang, this->GetConfigName()));
}
cmProp eliminate[] = {
this->Makefile->GetDefinition("CMAKE_START_TEMP_FILE"),

View File

@@ -0,0 +1,5 @@
enable_language(C)
add_library(empty STATIC empty.c)
string(REPLACE "<DEFINES>" "" CMAKE_C_COMPILE_OBJECT "${CMAKE_C_COMPILE_OBJECT}")
string(REPLACE "<INCLUDES>" "" CMAKE_C_COMPILE_OBJECT "${CMAKE_C_COMPILE_OBJECT}")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

View File

@@ -1,3 +1,4 @@
include(RunCMake)
run_cmake_with_options(BeforeProject -DCMAKE_PROJECT_INCLUDE_BEFORE=BeforeProjectBEFORE.cmake)
run_cmake(CustomCompileRule)