You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

150 lines
4.4 KiB

  1. include(CheckIncludeFile)
  2. include(CheckSymbolExists)
  3. include(CheckFunctionExists)
  4. include(CheckLibraryExists)
  5. include(CheckTypeSize)
  6. include(CheckCXXSourceCompiles)
  7. include(CheckStructHasMember)
  8. include(TestBigEndian)
  9. set(PACKAGE ${APPLICATION_NAME})
  10. set(VERSION ${APPLICATION_VERSION})
  11. set(DATADIR ${DATA_INSTALL_DIR})
  12. set(LIBDIR ${LIB_INSTALL_DIR})
  13. set(PLUGINDIR "${PLUGIN_INSTALL_DIR}-${LIBRARY_SOVERSION}")
  14. set(SYSCONFDIR ${SYSCONF_INSTALL_DIR})
  15. set(BINARYDIR ${CMAKE_BINARY_DIR})
  16. set(SOURCEDIR ${CMAKE_SOURCE_DIR})
  17. function(COMPILER_DUMPVERSION _OUTPUT_VERSION)
  18. # Remove whitespaces from the argument.
  19. # This is needed for CC="ccache gcc" cmake ..
  20. string(REPLACE " " "" _C_COMPILER_ARG "${CMAKE_C_COMPILER_ARG1}")
  21. execute_process(
  22. COMMAND
  23. ${CMAKE_C_COMPILER} ${_C_COMPILER_ARG} -dumpversion
  24. OUTPUT_VARIABLE _COMPILER_VERSION
  25. )
  26. string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
  27. _COMPILER_VERSION ${_COMPILER_VERSION})
  28. set(${_OUTPUT_VERSION} ${_COMPILER_VERSION} PARENT_SCOPE)
  29. endfunction()
  30. if(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW)
  31. compiler_dumpversion(GNUCC_VERSION)
  32. if (NOT GNUCC_VERSION EQUAL 34)
  33. check_c_compiler_flag("-fvisibility=hidden" WITH_VISIBILITY_HIDDEN)
  34. endif (NOT GNUCC_VERSION EQUAL 34)
  35. endif(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW)
  36. # DEFINITIONS
  37. if (SOLARIS)
  38. add_definitions(-D__EXTENSIONS__)
  39. endif (SOLARIS)
  40. # HEADER FILES
  41. check_include_file(assert.h HAVE_ASSERT_H)
  42. check_include_file(inttypes.h HAVE_INTTYPES_H)
  43. check_include_file(io.h HAVE_IO_H)
  44. check_include_file(malloc.h HAVE_MALLOC_H)
  45. check_include_file(memory.h HAVE_MEMORY_H)
  46. check_include_file(setjmp.h HAVE_SETJMP_H)
  47. check_include_file(signal.h HAVE_SIGNAL_H)
  48. check_include_file(stdarg.h HAVE_STDARG_H)
  49. check_include_file(stddef.h HAVE_STDDEF_H)
  50. check_include_file(stdint.h HAVE_STDINT_H)
  51. check_include_file(stdio.h HAVE_STDIO_H)
  52. check_include_file(stdlib.h HAVE_STDLIB_H)
  53. check_include_file(string.h HAVE_STRING_H)
  54. check_include_file(strings.h HAVE_STRINGS_H)
  55. check_include_file(sys/stat.h HAVE_SYS_STAT_H)
  56. check_include_file(sys/types.h HAVE_SYS_TYPES_H)
  57. check_include_file(time.h HAVE_TIME_H)
  58. check_include_file(unistd.h HAVE_UNISTD_H)
  59. if (HAVE_TIME_H)
  60. check_struct_has_member("struct timespec" tv_sec "time.h" HAVE_STRUCT_TIMESPEC)
  61. endif (HAVE_TIME_H)
  62. # FUNCTIONS
  63. check_function_exists(calloc HAVE_CALLOC)
  64. check_function_exists(exit HAVE_EXIT)
  65. check_function_exists(fprintf HAVE_FPRINTF)
  66. check_function_exists(free HAVE_FREE)
  67. check_function_exists(longjmp HAVE_LONGJMP)
  68. check_function_exists(siglongjmp HAVE_SIGLONGJMP)
  69. check_function_exists(malloc HAVE_MALLOC)
  70. check_function_exists(memcpy HAVE_MEMCPY)
  71. check_function_exists(memset HAVE_MEMSET)
  72. check_function_exists(printf HAVE_PRINTF)
  73. check_function_exists(setjmp HAVE_SETJMP)
  74. check_function_exists(signal HAVE_SIGNAL)
  75. check_function_exists(strsignal HAVE_STRSIGNAL)
  76. check_function_exists(strcmp HAVE_STRCMP)
  77. check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
  78. if (WIN32)
  79. check_function_exists(_vsnprintf_s HAVE__VSNPRINTF_S)
  80. check_function_exists(_vsnprintf HAVE__VSNPRINTF)
  81. check_function_exists(_snprintf HAVE__SNPRINTF)
  82. check_function_exists(_snprintf_s HAVE__SNPRINTF_S)
  83. check_symbol_exists(snprintf stdio.h HAVE_SNPRINTF)
  84. check_symbol_exists(vsnprintf stdio.h HAVE_VSNPRINTF)
  85. else (WIN32)
  86. check_function_exists(sprintf HAVE_SNPRINTF)
  87. check_function_exists(vsnprintf HAVE_VSNPRINTF)
  88. endif (WIN32)
  89. find_library(RT_LIBRARY rt)
  90. if (RT_LIBRARY AND NOT LINUX)
  91. set(CMOCKA_REQUIRED_LIBRARIES ${RT_LIBRARY} CACHE INTERNAL "cmocka required system libraries")
  92. endif ()
  93. # OPTIONS
  94. check_c_source_compiles("
  95. __thread int tls;
  96. int main(void) {
  97. return 0;
  98. }" HAVE_GCC_THREAD_LOCAL_STORAGE)
  99. if (WIN32)
  100. check_c_source_compiles("
  101. __declspec(thread) int tls;
  102. int main(void) {
  103. return 0;
  104. }" HAVE_MSVC_THREAD_LOCAL_STORAGE)
  105. endif(WIN32)
  106. if (HAVE_TIME_H AND HAVE_STRUCT_TIMESPEC AND HAVE_CLOCK_GETTIME)
  107. if (RT_LIBRARY)
  108. set(CMAKE_REQUIRED_LIBRARIES ${RT_LIBRARY})
  109. endif()
  110. check_c_source_compiles("
  111. #include <time.h>
  112. int main(void) {
  113. struct timespec ts;
  114. clock_gettime(CLOCK_REALTIME, &ts);
  115. return 0;
  116. }" HAVE_CLOCK_REALTIME)
  117. # reset cmake requirements
  118. set(CMAKE_REQUIRED_INCLUDES)
  119. set(CMAKE_REQUIRED_LIBRARIES)
  120. endif ()
  121. # ENDIAN
  122. if (NOT WIN32)
  123. set(WORDS_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
  124. test_big_endian(WORDS_BIGENDIAN)
  125. endif (NOT WIN32)