Reputation: 1844
I'm working through the CMake Tutorial and cross-checking with the associated project files and I'm stuck on Step 4.
The instructions add these lines to the top-level CMakeLists.txt file:
# does this system provide the log and exp functions?
include (CheckFunctionExists)
check_function_exists (log HAVE_LOG)
check_function_exists (exp HAVE_EXP)
As noted, this is a trivial test as just about every system on the planet has log
and exp
. But it fails. When generating the Makefiles, I see
-- Looking for log
-- Looking for log - not found
-- Looking for exp
-- Looking for exp - not found
If I dig deeper, running cmake --trace
, I see the following lines:
.../tutorial/src/CMakeLists.txt(19): include( CheckFunctionExists )
/usr/share/cmake/Modules/CheckFunctionExists.cmake(32): macro(CHECK_FUNCTION_EXISTS FUNCTION VARIABLE )
.../tutorial/src/CMakeLists.txt(20): check_function_exists(log HAVE_LOG )
/usr/share/cmake/Modules/CheckFunctionExists.cmake(33): if(HAVE_LOG MATCHES ^HAVE_LOG$ )
.../tutorial/src/CMakeLists.txt(21): check_function_exists(exp HAVE_EXP )
/usr/share/cmake/Modules/CheckFunctionExists.cmake(33): if(HAVE_EXP MATCHES ^HAVE_EXP$ )
In the CheckFunctionExists.cmake
file, there is no else
condition for that test. I'm new to cmake, but the tests appear true to my eye. What am I missing?
CentOS 7, cmake 2.8.12.2
Upvotes: 3
Views: 3312
Reputation: 1845
CheckFunctionExists
is known to have severe drawbacks. See documentation.
In your case you likely run into the first pitfall. The functions log
and exp
are intrinsic inline functions on many platforms. They cannot be detected at link time.
The recommended replacement is CheckSymbolExists
. Unfortunately this is not supported by your cmake version. You will need to upgrade at least to 3.0.2 for this to work.
Upvotes: 7