郜喜逢
郜喜逢

Reputation: 73

What is meaning of 'set(CMAKE_REQUIRED_LIBRARIES "m")' in CMake Tutorial?

I am learning CMake with CMake Tutorial and found something which is not clear for me:

include(CheckSymbolExists)
set(CMAKE_REQUIRED_LIBRARIES "m")

So what is the CheckSymbolExists? Is it a function or a lib? What's meaning of the "m"? Does it mean a lib name or some flag?

I had tried to read through cmake documents, but I just don't understand. Please somebody help me to understand these.

Upvotes: 5

Views: 3411

Answers (2)

Scriabin
Scriabin

Reputation: 21

The document said, if my understanding is correct, this module will check if a symbol can be correctly linked when it saw a symbol that is not a enum, type or intrinsic.

So in that snippet, when the first runs of check_symbol_exists didn't define the two cache variable, it will check if it had missed an required lib, and retry.

Upvotes: 0

Sonic
Sonic

Reputation: 324

First, set(CMAKE_REQUIRED_LIBRARIES "m") includes the math library. You do the same on the command-line like this: gcc test.c -lm which includes the library libm.so/.dll

CheckSymbolExists is a CMake Module which provides more functionality. You can include it with include(CheckSymbolExists) After this you can use the function check_symbol_exists(...) in CMake to check the availability of symbols in header files.

The exact example from the tutorial: check_symbol_exists(log "math.h" HAVE_LOG) checks if the header file math.h has a symbol (can be a function, constant or whatever) which is called log. If there is one, the CMake Variable HAVE_LOG is set to 1, otherwise set to 0.

Upvotes: 9

Related Questions