Generate compilation database (compile_command.json) using `qmake` (not GUI) - Stack Overflow

There was a self-answered question, How to generate compile_commands.json with QT project?, where the a

There was a self-answered question, How to generate compile_commands.json with QT project?, where the asker however was satisfied with the generation through Qt Creator.

Sadly, that's not an option for me; this needs to work in a CLI workflow on Linux.

Using bear to generate a compilation database from a make is unsatisfactory (and slow).

Since Qt Creator seems to have the functionality, it does exist in FOSS on Linux. (it's in a plugin, unless demonstrated otherwise, I'll assume the plugin environment necessary to run the conversion cannot be replicated without running the GUI.)

How do I create a compile_commands.json from a qmake-targetting .pro file without going through bear, compiledb (and doing a flaky build) or GUI?

Aiming at qmake-qt5, so far.

There was a self-answered question, How to generate compile_commands.json with QT project?, where the asker however was satisfied with the generation through Qt Creator.

Sadly, that's not an option for me; this needs to work in a CLI workflow on Linux.

Using bear to generate a compilation database from a make is unsatisfactory (and slow).

Since Qt Creator seems to have the functionality, it does exist in FOSS on Linux. (it's in a plugin, unless demonstrated otherwise, I'll assume the plugin environment necessary to run the conversion cannot be replicated without running the GUI.)

How do I create a compile_commands.json from a qmake-targetting .pro file without going through bear, compiledb (and doing a flaky build) or GUI?

Aiming at qmake-qt5, so far.

Share Improve this question edited Mar 14 at 8:49 Marcus Müller asked Mar 8 at 17:07 Marcus MüllerMarcus Müller 36.5k4 gold badges58 silver badges103 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

In the qmake man page, there's no such option.

If we have a look at the source of Qt Creator, the logic is in src/plugins/cppeditor/compilationdb.cpp. They use their own implementation to genreate compile_commands.json. It would be possible to create a standalone CLI program from it with some effort.

const QString fileName = "compile_commands.json";
//...
    QFile compileCommandsFile(baseDir.pathAppended(fileName).toFSPathString());
    const bool fileOpened = compileCommandsFile.open(QIODevice::WriteOnly | QIODevice::Truncate);
//...
    compileCommandsFile.write("[");
    const QJsonArray jsonProjectOptions = QJsonArray::fromStringList(projectOptions);
    // More logic to write the file
    compileCommandsFile.write("]");
    compileCommandsFile.close();

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744890551a4599385.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信