我正在我的软件环境中运行一些测试。这会对 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.txt
和CMakeFiles
文件夹。 - 对于下一个项目,您将在其上运行
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/