首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在windows上没有使用cmake代码的compile_commands.json文件

在windows上没有使用cmake代码的compile_commands.json文件
EN

Stack Overflow用户
提问于 2021-01-02 21:07:02
回答 1查看 6.7K关注 0票数 2

我正在尝试将Clang静态分析工具集成到我的构建系统中。我的设置有几个问题。

步骤cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..没有生成compile_commands.json文件。因此,clang给出了以下错误.

>cmake --build .结果

代码语言:javascript
运行
复制
Could not auto-detect compilation database from directory "C:/dev/my-project/build/compile_commands.json"
  No compilation database found in C:\dev\my-project\build\compile_commands.json or any parent directory
  fixed-compilation-database: Error while opening fixed database: no such file or directory
  json-compilation-database: Error while opening JSON database: no such file or directory
  Running without flags.
  Error while processing C:\dev\my-project\src\.
CUSTOMBUILD : error : unable to handle compilation, expected exactly one compiler job in '' [clang-diagnostic-error] [C:\dev\my-project\build\analyze_clang_tidy.vcxproj]
  Suppressed 1 warnings (1 in non-user code).
  Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.

Clang-tidy.cmake文件

代码语言:javascript
运行
复制
set(CLANG_TIDY_CHECKS "-checks='${CLANG_TIDY_CHECKS}'")

            add_custom_target(analyze_clang_tidy ALL
                COMMAND ${CLANG_TIDY}
                -p ${CMAKE_BINARY_DIR}/compile_commands.json
                ${CLANG_TIDY_CHECKS}
                -header-filter='.*'
                ${CMAKE_CURRENT_SOURCE_DIR}/src/
                WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
                COMMENT "Static code analysis with Clang-Tidy"
            )

也请找到配置结果。

代码语言:javascript
运行
复制
-- Building for: Visual Studio 14 2015
-- Selecting Windows SDK version  to target Windows 10.0.17763.
-- The CXX compiler identification is MSVC 19.0.24215.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Default build type: Debug
iD MSVC
-- ccache found and enabled
-- Configuring done
-- Generating done
-- Build files have been written to: C:/dev/my-project/build

我的../src/文件夹中有一个简单的hello ../src/

请给我建议如何生成compile_commands.json文件使用CMake与VS代码在窗口上。谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-02 21:28:50

请参阅COMMANDS.html

具体而言,本说明:

注释这个选项仅由Makefile生成器和忍者实现。它在其他发电机上被忽略。

相反,您可以编写一个python脚本,它将为您生成该格式,类似于以下工具:https://github.com/nickdiego/compiledb

或者,实际上,你不需要compile_commands.json。您可以定义CMAKE_<LANG>_CLANG_TIDY变量来自动触发clang:TIDY.html

看看我是如何为我的项目1 2 3.这么做的。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65544093

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档