Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
276 views
in Technique[技术] by (71.8m points)

c++ - Appending to CMAKE_C_FLAGS

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")

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)

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

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

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.

Thanks, Tobias

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try to do this instead:

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...