Blame ConfigureChecks.cmake

Packit 79ec17
include(CheckIncludeFile)
Packit 79ec17
include(CheckSymbolExists)
Packit 79ec17
include(CheckFunctionExists)
Packit 79ec17
include(CheckLibraryExists)
Packit 79ec17
include(CheckTypeSize)
Packit 79ec17
include(CheckCXXSourceCompiles)
Packit 79ec17
include(CheckStructHasMember)
Packit 79ec17
include(TestBigEndian)
Packit 79ec17
Packit 79ec17
set(PACKAGE ${PROJECT_NAME})
Packit 79ec17
set(VERSION ${PROJECT_VERSION})
Packit 79ec17
set(DATADIR ${DATA_INSTALL_DIR})
Packit 79ec17
set(LIBDIR ${CMAKE_INSTALL_LIBDIR})
Packit 79ec17
set(PLUGINDIR "${PLUGIN_INSTALL_DIR}-${LIBRARY_SOVERSION}")
Packit 79ec17
set(SYSCONFDIR ${SYSCONF_INSTALL_DIR})
Packit 79ec17
Packit 79ec17
set(BINARYDIR ${CMAKE_BINARY_DIR})
Packit 79ec17
set(SOURCEDIR ${CMAKE_SOURCE_DIR})
Packit 79ec17
Packit 79ec17
function(COMPILER_DUMPVERSION _OUTPUT_VERSION)
Packit 79ec17
    # Remove whitespaces from the argument.
Packit 79ec17
    # This is needed for CC="ccache gcc" cmake ..
Packit 79ec17
    string(REPLACE " " "" _C_COMPILER_ARG "${CMAKE_C_COMPILER_ARG1}")
Packit 79ec17
Packit 79ec17
    execute_process(
Packit 79ec17
        COMMAND
Packit 79ec17
            ${CMAKE_C_COMPILER} ${_C_COMPILER_ARG} -dumpversion
Packit 79ec17
        OUTPUT_VARIABLE _COMPILER_VERSION
Packit 79ec17
    )
Packit 79ec17
Packit 79ec17
    string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
Packit 79ec17
        _COMPILER_VERSION ${_COMPILER_VERSION})
Packit 79ec17
Packit 79ec17
    set(${_OUTPUT_VERSION} ${_COMPILER_VERSION} PARENT_SCOPE)
Packit 79ec17
endfunction()
Packit 79ec17
Packit 79ec17
if(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW)
Packit 79ec17
    compiler_dumpversion(GNUCC_VERSION)
Packit 79ec17
    if (NOT GNUCC_VERSION EQUAL 34)
Packit 79ec17
        check_c_compiler_flag("-fvisibility=hidden" WITH_VISIBILITY_HIDDEN)
Packit 79ec17
    endif (NOT GNUCC_VERSION EQUAL 34)
Packit 79ec17
endif(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW)
Packit 79ec17
Packit 79ec17
# DEFINITIONS
Packit 79ec17
if (SOLARIS)
Packit 79ec17
    add_definitions(-D__EXTENSIONS__)
Packit 79ec17
endif (SOLARIS)
Packit 79ec17
Packit 79ec17
# HEADER FILES
Packit 79ec17
check_include_file(assert.h HAVE_ASSERT_H)
Packit 79ec17
check_include_file(inttypes.h HAVE_INTTYPES_H)
Packit 79ec17
check_include_file(io.h HAVE_IO_H)
Packit 79ec17
check_include_file(malloc.h HAVE_MALLOC_H)
Packit 79ec17
check_include_file(memory.h HAVE_MEMORY_H)
Packit 79ec17
check_include_file(setjmp.h HAVE_SETJMP_H)
Packit 79ec17
check_include_file(signal.h HAVE_SIGNAL_H)
Packit 79ec17
check_include_file(stdarg.h HAVE_STDARG_H)
Packit 79ec17
check_include_file(stddef.h HAVE_STDDEF_H)
Packit 79ec17
check_include_file(stdint.h HAVE_STDINT_H)
Packit 79ec17
check_include_file(stdio.h HAVE_STDIO_H)
Packit 79ec17
check_include_file(stdlib.h HAVE_STDLIB_H)
Packit 79ec17
check_include_file(string.h HAVE_STRING_H)
Packit 79ec17
check_include_file(strings.h HAVE_STRINGS_H)
Packit 79ec17
check_include_file(sys/stat.h HAVE_SYS_STAT_H)
Packit 79ec17
check_include_file(sys/types.h HAVE_SYS_TYPES_H)
Packit 79ec17
check_include_file(time.h HAVE_TIME_H)
Packit 79ec17
check_include_file(unistd.h HAVE_UNISTD_H)
Packit 79ec17
Packit 79ec17
if (HAVE_TIME_H)
Packit 79ec17
    check_struct_has_member("struct timespec" tv_sec "time.h" HAVE_STRUCT_TIMESPEC)
Packit 79ec17
endif (HAVE_TIME_H)
Packit 79ec17
Packit 79ec17
# FUNCTIONS
Packit 79ec17
check_function_exists(calloc HAVE_CALLOC)
Packit 79ec17
check_function_exists(exit HAVE_EXIT)
Packit 79ec17
check_function_exists(fprintf HAVE_FPRINTF)
Packit 79ec17
check_function_exists(free HAVE_FREE)
Packit 79ec17
check_function_exists(longjmp HAVE_LONGJMP)
Packit 79ec17
check_function_exists(siglongjmp HAVE_SIGLONGJMP)
Packit 79ec17
check_function_exists(malloc HAVE_MALLOC)
Packit 79ec17
check_function_exists(memcpy HAVE_MEMCPY)
Packit 79ec17
check_function_exists(memset HAVE_MEMSET)
Packit 79ec17
check_function_exists(printf HAVE_PRINTF)
Packit 79ec17
check_function_exists(setjmp HAVE_SETJMP)
Packit 79ec17
check_function_exists(signal HAVE_SIGNAL)
Packit 79ec17
check_function_exists(strsignal HAVE_STRSIGNAL)
Packit 79ec17
check_function_exists(strcmp HAVE_STRCMP)
Packit 79ec17
check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
Packit 79ec17
Packit 79ec17
if (WIN32)
Packit 79ec17
    check_function_exists(_vsnprintf_s HAVE__VSNPRINTF_S)
Packit 79ec17
    check_function_exists(_vsnprintf HAVE__VSNPRINTF)
Packit 79ec17
    check_function_exists(_snprintf HAVE__SNPRINTF)
Packit 79ec17
    check_function_exists(_snprintf_s HAVE__SNPRINTF_S)
Packit 79ec17
    check_symbol_exists(snprintf stdio.h HAVE_SNPRINTF)
Packit 79ec17
    check_symbol_exists(vsnprintf stdio.h HAVE_VSNPRINTF)
Packit 79ec17
else (WIN32)
Packit 79ec17
    check_function_exists(sprintf HAVE_SNPRINTF)
Packit 79ec17
    check_function_exists(vsnprintf HAVE_VSNPRINTF)
Packit 79ec17
endif (WIN32)
Packit 79ec17
Packit 79ec17
find_library(RT_LIBRARY rt)
Packit 79ec17
if (RT_LIBRARY AND NOT LINUX AND NOT ANDROID)
Packit 79ec17
    set(CMOCKA_REQUIRED_LIBRARIES ${RT_LIBRARY} CACHE INTERNAL "cmocka required system libraries")
Packit 79ec17
endif ()
Packit 79ec17
Packit 79ec17
# OPTIONS
Packit 79ec17
check_c_source_compiles("
Packit 79ec17
__thread int tls;
Packit 79ec17
Packit 79ec17
int main(void) {
Packit 79ec17
    return 0;
Packit 79ec17
}" HAVE_GCC_THREAD_LOCAL_STORAGE)
Packit 79ec17
Packit 79ec17
if (WIN32)
Packit 79ec17
check_c_source_compiles("
Packit 79ec17
__declspec(thread) int tls;
Packit 79ec17
Packit 79ec17
int main(void) {
Packit 79ec17
    return 0;
Packit 79ec17
}" HAVE_MSVC_THREAD_LOCAL_STORAGE)
Packit 79ec17
endif(WIN32)
Packit 79ec17
Packit 79ec17
if (HAVE_TIME_H AND HAVE_STRUCT_TIMESPEC AND HAVE_CLOCK_GETTIME)
Packit 79ec17
    if (RT_LIBRARY)
Packit 79ec17
        set(CMAKE_REQUIRED_LIBRARIES ${RT_LIBRARY})
Packit 79ec17
    endif()
Packit 79ec17
Packit 79ec17
    check_c_source_compiles("
Packit 79ec17
#include <time.h>
Packit 79ec17
Packit 79ec17
int main(void) {
Packit 79ec17
    struct timespec ts;
Packit 79ec17
Packit 79ec17
    clock_gettime(CLOCK_REALTIME, &ts);
Packit 79ec17
Packit 79ec17
    return 0;
Packit 79ec17
}" HAVE_CLOCK_REALTIME)
Packit 79ec17
Packit 79ec17
    # reset cmake requirements
Packit 79ec17
    set(CMAKE_REQUIRED_INCLUDES)
Packit 79ec17
    set(CMAKE_REQUIRED_LIBRARIES)
Packit 79ec17
endif ()
Packit 79ec17
Packit 79ec17
# ENDIAN
Packit 79ec17
if (NOT WIN32)
Packit 79ec17
    set(WORDS_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
Packit 79ec17
    test_big_endian(WORDS_BIGENDIAN)
Packit 79ec17
endif (NOT WIN32)