【发布时间】:2021-09-06 18:58:27
【问题描述】:
我正在使用 Eclipse CDT、CMake 和 cmake4eclipse 插件在 Windows 上设置 C/C++ 构建环境。除了生成 compile_commands.json 之外,一切正常。 cmake4eclipse 插件需要此文件,以便使用两个 CMAKE_EXPORT_COMPILE_COMMANDS 提供程序进行自动包含检测等(据我理解正确)。
我正在使用 CMake (3.20) 和 ninja 的 Windows 版本以及 gcc 的 MSYS2 版本。所有工具都可以通过 PATH 变量访问(正如我已经提到的,编译工作正常)。
我的 cmake 命令大致如下:
cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON -G Ninja "C:\\path\\to\\source"
在配置过程中我总是收到警告
CMake Warning:
Manually-specified variables were not used by the project:
CMAKE_EXPORT_COMPILE_COMMANDS
并且构建目录中没有生成compile_commands.json。
我知道,当尝试为不受支持的生成器导出编译命令时,这通常是一个问题,例如视觉工作室。但由于我使用的是 ninja,我希望 JSON 文件能够成功生成。
有没有人遇到过类似的问题或有什么想法?
谢谢!
编辑:
这是message(STATUS "gen = ${CMAKE_GENERATOR}") 的输出:
cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON -G Ninja "C:\\path\\to\\source"
-- The C compiler identification is GNU 10.2.0
-- The CXX compiler identification is GNU 10.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/usr/bin/cc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/msys64/usr/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- gen = Ninja
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
CMAKE_EXPORT_COMPILE_COMMANDS
-- Build files have been written to: C:/path/to/build
10:52:57 Buildscript generation finished (took 9351 ms)
很遗憾,我无法发布我的整个 CMakeLists.txt,因为它属于我们公司的一个项目。顶层 CMakeLists.txt 没有定义任何目标,而是添加了几个 ExternalProjects 来支持交叉编译。
【问题讨论】:
-
我尝试使用最小的 CMakeLists.txt 重现此问题,但未能成功。您能否使用基本的 CMakeLists.txt 尝试相同的工作流程,看看问题是否仍然存在?
-
最小的意思是“cmake_minimum_required + project + add_executable”在源文件中带有
int main() {return 0;}。 -
尝试
message(STATUS "gen = ${CMAKE_GENERATOR}")以确保生成器设置正确。 -
你能发布完整的输出和你的 CMakeLists.txt 吗?
-
感谢您的 cmets。在我的原始帖子中发布了完整的输出,包括
message(STATUS "gen = ${CMAKE_GENERATOR}")。
标签: eclipse cmake eclipse-cdt