c++ - 如何跳过 CMake 编译器识别?

标签 c++ cmake

我正在我的软件环境中运行一些测试。这会对 CMake 进行数百次调用以配置许多项目,始终使用相同的编译器。

对于每次调用 CMake,它都会检查编译器:

-- Selecting Windows SDK version  to target Windows 10.0.16299.
-- The C compiler identification is MSVC 19.0.24215.1
-- The CXX compiler identification is MSVC 19.0.24215.1
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done

这需要一段时间,而且做很多次也没用,因为它在运行这些测试的机器上总是以相同的结果结束。

有没有办法“缓存”编译器检查结果并且只做一次?

最佳答案

fdan 建议(在评论中)添加顶级 CMake 项目,使用 add_subdirectory 添加所有子项目。我没有尝试过,但它看起来像是可以炒锅的东西。

与此同时,我发现另一种方法是:

  • 创建一个空的 CMakeLists.txt 文件
  • 在其上运行 CMake,它会检查编译器。这会生成一些文件,包括 CMakeCache.txtCMakeFiles 文件夹。
  • 对于下一个项目,您将在其上运行 CMake
    • 复制您对空项目执行的第一次运行的输出(包括 CMakeCache.txt 和一个 CMakeFiles 文件夹)
    • 修改 CMakeCache.txt 内容以引用新项目文件夹而不是旧项目文件夹(否则 Cmake 将报告 CMake Error: The current CMakeCache.txt directory ... is different than the目录 ... 创建 CMakeCache.txt 的位置)
    • 然后在配置下一个项目时将不处理编译器检查

关于c++ - 如何跳过 CMake 编译器识别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57818544/

相关文章:

c++ - 在类中初始化空数组

c++ - 运算符 = 不明确 (C++)

c++ - 如何确保 `waitpid(-1, &stat, WNOHANG)` 收集所有子进程

c++ - 链接到使用 boost 库的静态库会导致 cmake 中出现链接错误

c++ - 使用 CMake 编译具有多配置的 Boost

cmake - 从子作用域中检索变量

c++ - 窗口 HTTP IO 完成端口

c++ - 如何仅通过标准库引用二维数组来使用动态创建的一维数组?

c++ - CMake 测试在测试失败时导致错误

c++ - CMake 子文件夹结构?