CMake 用于检测 Ninja 的 Visual C++ 编译器工具的环境变量 [英] Environment variable used by CMake to detect Visual C++ compiler tools for Ninja

查看:30
本文介绍了CMake 用于检测 Ninja 的 Visual C++ 编译器工具的环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有来自 Visual Studio 2017 RTM 的 Mingw64 GCC 6.3.0(总是在 PATH 中)和 Visual C++ 编译器工具(不在 PATH 中).

I have Mingw64 GCC 6.3.0 (always in PATH) and Visual C++ compiler tools from Visual Studio 2017 RTM (not in PATH).

如果我运行 cmake .-G "MinGW Makefiles",将选择 GCC 6.3.0.

If I run cmake . -G "MinGW Makefiles", GCC 6.3.0 will be selected.

如果我运行 cmake .-G "Ninja",将选择 GCC 6.3.0.

If I run cmake . -G "Ninja", GCC 6.3.0 will be selected.

我的 Visual C++ 编译器工具不是标准的,我只保留我需要的部分并删除其余部分(如 MSBuild、IDE 等).我使用我自己的批处理脚本来设置 PATHINCLUDELIB(工作得很好).

My Visual C++ compiler tools is none standard, I only keep the parts I need and delete the rest (like MSBuild, IDE etc.). I use my own batch script to set up PATH, INCLUDE and LIB (works just fine).

如果我运行此批处理脚本并运行 cmake .,将选择 MSVC 并使用 NMake 构建.

If I run this batch script and run cmake ., MSVC will be selected and build with NMake.

在相同的环境下,cmake .-G "Ninja",选择 GCC 6.3.0 而不是 MSVC.

With the same environment, cmake . -G "Ninja", GCC 6.3.0 is selected instead of MSVC.

所以我的问题是,当两者都在 PATH 中时,如何告诉 CMake 我想使用 MSVC + Ninja 而不是 GCC + Ninja?我应该设置任何环境变量吗?

So my question is, how to tell CMake I want to use MSVC + Ninja rather than GCC + Ninja when both are in PATH? Any environment variable I should set?

推荐答案

您还可以使用反向方法并使用 CMAKE_IGNORE_PATH.它需要一个要忽略的路径列表,但请注意它需要是一个精确的字符串匹配.优点是您可以直接从命令行声明它们.

You can also use the inverted approach and exclude all compilers you don't want with CMAKE_IGNORE_PATH. It takes a list of paths to ignore, but be aware that it needs to be an exact string match. The advantage would be that you can declare those directly from the command line.

所以我所做的是从编译器找到但不被采用"的路径到CMAKE_IGNORE_PATH.

So what I did is to take the path from the compiler found but "not to be taken" into CMAKE_IGNORE_PATH.

在我的系统上,我的 PATH 中实际上有三个 GCC 编译器(只需确保每次尝试从一个空的二进制输出目录开始):

And on my system there were actually three GCC compilers in my PATH (just make sure to start from an empty binary output directory with each try):

> cmake -G"Ninja" ..
...
-- Check for working C compiler: C:/MinGW/bin/cc.exe
...

<小时>

> cmake -DCMAKE_IGNORE_PATH="C:/MinGW/bin" -G"Ninja" ..
...
-- Check for working C compiler: C:/Strawberry/c/bin/gcc.exe
...

<小时>

> cmake -DCMAKE_IGNORE_PATH="C:/MinGW/bin;C:/Strawberry/c/bin" -G"Ninja" ..
...
-- Check for working C compiler: C:/Program Files (x86)/LLVM/bin/clang.exe
...

<小时>

> cmake -DCMAKE_IGNORE_PATH="C:/MinGW/bin;C:/Strawberry/c/bin;C:/Program Files (x86)/LLVM/bin" -G"Ninja" ..
...
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe
...

这篇关于CMake 用于检测 Ninja 的 Visual C++ 编译器工具的环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆