[CMake] Math lib with CMAKE_REQUIRED_LIBRARIES

Brad King brad.king at kitware.com
Tue May 3 15:29:26 EDT 2005


Moreland, Kenneth wrote:
> I'm setting CMAKE_REQUIRED_LIBRARIES and using CHECK_FUNCTION_EXISTS to
> test the existence of a function in a library.  However, sometimes the
> library in question relies on the math library, which is not
> automatically added to the link that CHECK_FUNCTION_EXISTS is using.
> How do you ensure that the math library is added to the link in a
> platform independent way?

We've seen this problem many times.  Windows runtime libraries always 
seem to have all the math functions, so we just do

IF(UNIX)
   SET(MY_MATH_LIB -lm)
ELSE(UNIX)
   SET(MY_MATH_LIB)
ENDIF(UNIX)

and then reference ${MY_MATH_LIB}.

-Brad


More information about the CMake mailing list