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

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

问题描述

我有Mingw64 GCC 6.3.0(始终在 PATH 中)和Visual Studio 2017 RTM的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等)。我使用自己的批处理脚本来设置 PATH INCLUDE LIB (工作正常)。

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将

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.

所以我的问题是,如何告诉CMake我想要当两者都在 PATH 中时,使用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?

推荐答案

您还可以使用倒置方法,并使用<排除所有不需要的编译器a href = https://cmake.org/cmake/help/latest/variable/CMAKE_IGNORE_PATH.html rel = noreferrer> 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天全站免登陆