CMake:在启用语言之前,如何测试编译器 [英] CMake: Howto test for compiler, before enable a language

查看:52
本文介绍了CMake:在启用语言之前,如何测试编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,可以使用其他语言(nasm& fortran)来可选地编译某些代码,但是也可以在不安装这些编译器的情况下编译项目.例如.在Windows上.

In my project some code can be optional compiled in a different language (nasm & fortran), but it's also fine to compile the project without having these compiler installed. E.g. on Windows.

在使用enable_language启用语言之前,我想检查是否已安装编译器

I would like to check if the the compiler are installed, before enabling the languages with enable_language

enable_language(ASM_NASM)
enable_language(Fortran)

如果我使用 enable_language 而不进行其他检查,则CMake将停止并显示一条错误消息.

If I use enable_language without an additional check, CMake stops with an error message.

(目前我正在检查 if(MSVC)作为解决方法.)

(At the moment I check for if (MSVC) as workaround.)

顺便说一句.我对Qt的检查也有类似的问题.检查不会因错误而停止,但会产生很多嘈杂的警告.

Btw. I have a similar problem with the check for Qt. The check don't stop with an error, but generate a lot of noisy warnings.

推荐答案

所以请使用检查语言以检查是否可以启用一种语言.

So use check_language to check if a language can be enabled.

这篇关于CMake:在启用语言之前,如何测试编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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