Skip to content
Snippets Groups Projects
Commit 316cbbe8 authored by Brad King's avatar Brad King
Browse files

Makefiles: Fix CMAKE_EXPORT_COMPILE_COMMANDS crash with custom compile rule

Extend the fix from commit 67e2130c (Makefiles: Fix
CMAKE_EXPORT_COMPILE_COMMANDS crash with custom compile rule,
2020-11-20, v3.19.1~8^2) to work for the `<FLAGS>` placeholder too.
Also fix the test case to actually enable `EXPORT_COMPILE_COMMANDS`
on the test target.

Fixes: #22261
parent f4f80cfe
No related branches found
No related tags found
No related merge requests found
......@@ -926,8 +926,11 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
compileCommand, vars);
std::string workingDirectory =
this->LocalGenerator->GetCurrentBinaryDirectory();
compileCommand.replace(compileCommand.find(langFlags), langFlags.size(),
this->GetFlags(lang, this->GetConfigName()));
std::string::size_type lfPos = compileCommand.find(langFlags);
if (lfPos != std::string::npos) {
compileCommand.replace(lfPos, langFlags.size(),
this->GetFlags(lang, this->GetConfigName()));
}
std::string langDefines = std::string("$(") + lang + "_DEFINES)";
std::string::size_type ldPos = compileCommand.find(langDefines);
if (ldPos != std::string::npos) {
......
enable_language(C)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
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)
string(REPLACE "<FLAGS>" "" CMAKE_C_COMPILE_OBJECT "${CMAKE_C_COMPILE_OBJECT}")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment