简体   繁体   English

如何跳过 CMake 编译器识别?

[英]How can I skip CMake compiler identification?

I'm running some tests on my software environment.我正在我的软件环境上运行一些测试。 This does hundreds of calls to CMake to configure many projects, always using the same compiler.这会对 CMake 进行数百次调用以配置许多项目,并且始终使用相同的编译器。

For every call to CMake, it checks the compiler:对于每次调用 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

This takes a while and is useless to be done many time as it will always end with the same result on the machine running those tests.这需要一段时间,并且多次完成是无用的,因为在运行这些测试的机器上它总是以相同的结果结束。

Is there no way to "cache" compiler check result and have it be done once only?有没有办法“缓存”编译器检查结果并且只执行一次?

fdan recommended (in a comment) to add a top level CMake projects adding all sub-projects using add_subdirectory . fdan 建议(在评论中)添加顶级CMake项目,使用add_subdirectory添加所有子项目。 I did not try that but it looks like something that would wok.我没有尝试过,但它看起来像是可以炒的东西。

In the mean time, I found an alternative is to:与此同时,我发现另一种选择是:

  • Create an empty CMakeLists.txt file创建一个空的CMakeLists.txt文件
  • Run CMake on it, it checks the compiler.在其上运行CMake ,它会检查编译器。 This produces some files including a CMakeCache.txt and a CMakeFiles folder.这会生成一些文件,包括CMakeCache.txtCMakeFiles文件夹。
  • For every next project you will run CMake on对于下一个项目,您将在其上运行CMake
    • Copy the output of the first run you did with the empty project (including CMakeCache.txt and a CMakeFiles folder)复制您对空项目执行的第一次运行的输出(包括CMakeCache.txtCMakeFiles文件夹)
    • Modify CMakeCache.txt content to reference the new project folder instead of the old one (else Cmake will report CMake Error: The current CMakeCache.txt directory ... is different than the directory ... where CMakeCache.txt was created) .修改CMakeCache.txt内容以引用新项目文件夹而不是旧文件夹(否则 Cmake 将报告CMake Error: The current CMakeCache.txt directory ... is different than the directory ... where CMakeCache.txt was created)
    • Then compiler check will not be processed when you'll configure the next project然后在配置下一个项目时将不会进行编译器检查

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM