CMake : Detect functions and libraries.

This commit is contained in:
Erik de Castro Lopo 2014-07-13 12:48:02 +10:00
parent e693055680
commit e2d39c7b69
3 changed files with 95 additions and 13 deletions

View File

@ -1,4 +1,6 @@
include (CheckFunctionExists)
include (CheckIncludeFile)
include (CheckLibraryExists)
include (CheckTypeSize)
include (TestBigEndian)
@ -41,7 +43,49 @@ function (mn_check_type_size TYPE_NAME RESULT_SIZE)
set (${RESULT_SIZE} 0 PARENT_SCOPE)
endif (SIZE_${TYPE_NAME})
set (TMP1)
set (TMP1) # Clear temp variables.
set (TMP2)
set (SIZE_${TMP2})
endfunction ()
function (mn_check_function_exists FUNC_NAME RESULT_NAME)
check_function_exists (${FUNC_NAME} FUNC_${RESULT_NAME})
if (FUNC_${RESULT_NAME})
set (${RESULT_NAME} 1 PARENT_SCOPE)
else (FUNC_${RESULT_NAME})
set (${RESULT_NAME} 0 PARENT_SCOPE)
endif (FUNC_${RESULT_NAME})
set (FUNC_${RESULT_NAME}) # Clear the variable.
endfunction ()
# Unix does not link libm by default while windows does. We therefore have
# a special function for testing math functions.
function (mn_check_math_function_exists FUNC_NAME RESULT_NAME)
if (${UNIX})
check_library_exists (m ${FUNC_NAME} "" FUNC_${RESULT_NAME})
else (${UNIX})
check_function_exists (${FUNC_NAME} FUNC_${RESULT_NAME})
endif (${UNIX})
if (FUNC_${RESULT_NAME})
set (${RESULT_NAME} 1 PARENT_SCOPE)
else (FUNC_${RESULT_NAME})
set (${RESULT_NAME} 0 PARENT_SCOPE)
endif (FUNC_${RESULT_NAME})
set (FUNC_${RESULT_NAME}) # Clear the variable.
endfunction ()
function (mn_check_library_exists LIB_NAME LIB_FUNC LOCATION RESULT_NAME)
check_library_exists (${LIB_NAME} ${LIB_FUNC} "${LOCATION}" LIB_${RESULT_NAME})
if (LIB_${RESULT_NAME})
set (${RESULT_NAME} 1 PARENT_SCOPE)
else (LIB_${RESULT_NAME})
set (${RESULT_NAME} 0 PARENT_SCOPE)
endif (LIB_${RESULT_NAME})
set (LIB_${RESULT_NAME}) # Clear the variable.
endfunction ()

View File

@ -39,6 +39,8 @@ mn_check_type_size (xxwchar_t SIZEOF_WCHAR_T)
set (SIZEOF_SF_COUNT_T ${SIZEOF_INT64_T})
set (TYPEOF_SF_COUNT_T int64_t)
# Can't figure out how to make CMAKE_COMPILER_IS_GNUCC set something to either
# 1 or 0 so we do this:
mn_try_compile_c_result (CMake/compiler_is_gcc.c COMPILER_IS_GCC 1 0)
TEST_BIG_ENDIAN (BIGENDIAN)
@ -51,3 +53,46 @@ else (${BIGENDIAN})
set (CPU_IS_LITTLE_ENDIAN 1)
set (CPU_IS_BIG_ENDIAN 0)
endif (${BIGENDIAN})
if (${WINDOWS})
set (OS_IS_WIN32 1)
else (${WINDOWS})
set (OS_IS_WIN32 0)
endif (${WINDOWS})
mn_check_library_exists (m floor "" HAVE_LIBM)
mn_check_library_exists (sqlite3 sqlite3_close "" HAVE_SQLITE3)
mn_check_function_exists (calloc HAVE_CALLOC)
mn_check_function_exists (free HAVE_FREE)
mn_check_function_exists (fstat HAVE_FSTAT)
mn_check_function_exists (fstat64 HAVE_FSTAT64)
mn_check_function_exists (fsync HAVE_FSYNC)
mn_check_function_exists (ftruncate HAVE_FTRUNCATE)
mn_check_function_exists (getpagesize HAVE_GETPAGESIZE)
mn_check_function_exists (gettimeofday HAVE_GETTIMEOFDAY)
mn_check_function_exists (gmtime HAVE_GMTIME)
mn_check_function_exists (gmtime_r HAVE_GMTIME_R)
mn_check_function_exists (localtime HAVE_LOCALTIME)
mn_check_function_exists (localtime_r HAVE_LOCALTIME_R)
mn_check_function_exists (lseek HAVE_LSEEK)
mn_check_function_exists (lseek64 HAVE_LSEEK64)
mn_check_function_exists (malloc HAVE_MALLOC)
mn_check_function_exists (mmap HAVE_MMAP)
mn_check_function_exists (open HAVE_OPEN)
mn_check_function_exists (pipe HAVE_PIPE)
mn_check_function_exists (read HAVE_READ)
mn_check_function_exists (realloc HAVE_REALLOC)
mn_check_function_exists (setlocale HAVE_SETLOCALE)
mn_check_function_exists (snprintf HAVE_SNPRINTF)
mn_check_function_exists (vsnprintf HAVE_VSNPRINTF)
mn_check_function_exists (waitpid HAVE_WAITPID)
mn_check_function_exists (write HAVE_WRITE)
mn_check_math_function_exists (ceil HAVE_CEIL)
mn_check_math_function_exists (floor HAVE_FLOOR)
mn_check_math_function_exists (fmod HAVE_FMOD)
mn_check_math_function_exists (lrint HAVE_LRINT)
mn_check_math_function_exists (lrintf HAVE_LRINTF)
mn_check_math_function_exists (lround HAVE_LROUND)

View File

@ -16,30 +16,23 @@ if (MSVC)
set (CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} /wd4244 /wd4996")
add_definitions ("/wd4244 /wd4996")
set (HAVE_BYTESWAP_H 0)
set (HAVE_INTTYPES_H 1)
set (HAVE_STDINT_H 0)
set (SIZEOF_LONG 4)
set (COMPILER_IS_GCC 0)
set (HAVE_EXTERNAL_LIBS 0)
set (OS_IS_WIN32 1)
set (OSX_DARWIN_VERSION 0)
set (USE_WINDOWS_API 1)
else (MSVC)
# Assume this is Linux or some other POSIX-like system (including OS X).
set (OS_IS_WIN32 0)
set (USE_WINDOWS_API 0)
set (COMPILER_IS_GCC ${COMPILER_IS_GCC})
set (HAVE_EXTERNAL_LIBS 0)
set (OSX_DARWIN_VERSION 0)
set (USE_WINDOWS_API 0)
set (CPU_CLIPS_NEGATIVE 0)
set (CPU_CLIPS_POSITIVE 0)
set (HAVE_GETTIMEOFDAY 1)
set (_POSIX_SOURCE 1)
set (SF_COUNT_MAX 0x7fffffffffffffffll)
set (ENABLE_EXPERIMENTAL_CODE 0)
set (HAVE_DECL_S_IRGRP 1)
set (HAVE_FSTAT64 1)
set (HAVE_FSYNC 1)
set (OSX_DARWIN_VERSION 0)
endif (MSVC)