Skip to content

Commit 37cda77

Browse files
bradkingkwrobot
authored andcommitted
Merge topic 'fix-compile-db-crash'
316cbbe Makefiles: Fix CMAKE_EXPORT_COMPILE_COMMANDS crash with custom compile rule Acked-by: Kitware Robot <[email protected]> Merge-request: !6173
2 parents 7676e11 + 316cbbe commit 37cda77

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Source/cmMakefileTargetGenerator.cxx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -909,8 +909,11 @@ void cmMakefileTargetGenerator::WriteObjectRuleFiles(
909909
compileCommand, vars);
910910
std::string workingDirectory =
911911
this->LocalGenerator->GetCurrentBinaryDirectory();
912-
compileCommand.replace(compileCommand.find(langFlags), langFlags.size(),
913-
this->GetFlags(lang, this->GetConfigName()));
912+
std::string::size_type lfPos = compileCommand.find(langFlags);
913+
if (lfPos != std::string::npos) {
914+
compileCommand.replace(lfPos, langFlags.size(),
915+
this->GetFlags(lang, this->GetConfigName()));
916+
}
914917
std::string langDefines = std::string("$(") + lang + "_DEFINES)";
915918
std::string::size_type ldPos = compileCommand.find(langDefines);
916919
if (ldPos != std::string::npos) {
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
enable_language(C)
2+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
23
add_library(empty STATIC empty.c)
34
string(REPLACE "<DEFINES>" "" CMAKE_C_COMPILE_OBJECT "${CMAKE_C_COMPILE_OBJECT}")
45
string(REPLACE "<INCLUDES>" "" CMAKE_C_COMPILE_OBJECT "${CMAKE_C_COMPILE_OBJECT}")
5-
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
6+
string(REPLACE "<FLAGS>" "" CMAKE_C_COMPILE_OBJECT "${CMAKE_C_COMPILE_OBJECT}")

0 commit comments

Comments
 (0)