本文介绍了附加到CMAKE_C_FLAGS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将CMake用于一个有两个版本的项目,其中一个版本需要-lglapi,而另一个版本则不需要-lglapi.

I'm using CMake for a project that comes in two versions, one of which requires -lglapi and the other does not.

到目前为止,我们使用的代码如下:

So far the lines we used look like that:

SET(CMAKE_C_FLAGS "-O3 -xSSE3 -restrict -lpthread -lX11 -ldrm")
SET(CMAKE_CXX_FLAGS "-O3 -xSSE3 -restrict -lpthread -lX11 -ldrm")

我在这些行之后的CMakeList.txt中添加了一条if语句:

I added an if statement in my CMakeList.txt exactly after those lines:

if(SINGLE_MODE)
    SET(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} " -lglapi")
    SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} " -lglapi")
endif(SINGLE_MODE)

定义SINGLE_MODE变量有点.当我使用message命令显示标志变量的内容时,它看起来还不错:

The SINGLE_MODE variable is defined a little up. When I use the message command to display the content of the flag variables it looks alright:

-O3 -xSSE3 -restrict -lpthread -lX11 -ldrm -lglapi

但是当我开始编译时,我遇到了编译错误.使用详细模式时,我意识到在编译器调用中,它看起来像这样:

But when I start compiling I am running into a compile error. Using the verbose mode I realized that in the compiler call it looks like that:

-O3 -xSSE3 -restrict -lpthread -lX11 -ldrm; -lglapi

即在将-lglapi添加到列表之前,以某种方式添加了分号.

I.e. somehow a semicolon got added before adding the -lglapi to the list.

这里有人遇到过类似的问题,并且知道解决此问题的方法吗?我已经搜索了很长时间,研究了CMake手册,但在这里看不到我做错了什么.

Did anyone here encounter a similar issue and knows a way to fix this issue? I've googled quite a while and studied the CMake manual but couldn't see what I did wrong here.

谢谢,托比亚斯

推荐答案

尝试改为执行此操作:

if(SINGLE_MODE)
    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lglapi")
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lglapi")
endif(SINGLE_MODE)

然后,确定将-lglapi附加到现有的${CMAKE_CXX_FLAGS}字符串中.否则,看起来就像正在创建CMake列表.

Then, you are sure you append -lglapi to the existing ${CMAKE_CXX_FLAGS} string. Else, looks like something like a CMake list is being created.

这篇关于附加到CMAKE_C_FLAGS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 16:20