CMakeLists.txt 2.32 KB
Newer Older
1
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.6)
2 3 4 5 6 7 8 9 10 11 12 13 14 15
INCLUDE(CheckIncludeFiles)
INCLUDE(TestBigEndian)
INCLUDE(CheckCSourceCompiles)
PROJECT(libaec)
SET(libaec_VERSION_MAJOR 0)
SET(libaec_VERSION_MINOR 2)
SET(CMAKE_BUILD_TYPE Release)
ENABLE_TESTING()

CHECK_INCLUDE_FILES(malloc.h HAVE_MALLOC_H)
CHECK_INCLUDE_FILES(stdint.h HAVE_STDINT_H)
TEST_BIG_ENDIAN(WORDS_BIGENDIAN)
CHECK_C_SOURCE_COMPILES(
  "int main(int argc, char *argv[])
16
{return __builtin_clzll(1LL);}"
17 18
  HAVE_DECL___BUILTIN_CLZLL
  )
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
19

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
#Inspired from http://www.cmake.org/Wiki/CMakeTestInline
SET(INLINE_TEST_SRC "/* Inspired by autoconf's c.m4 */
static inline int static_foo(){return 0\;}
int main(int argc, char *argv[]){return 0\;}
")
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCInline.c
  ${INLINE_TEST_SRC})

FOREACH(KEYWORD "inline" "__inline__" "__inline")
   IF(NOT DEFINED C_INLINE)
     TRY_COMPILE(C_HAS_${KEYWORD}
       ${CMAKE_CURRENT_BINARY_DIR}
       ${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCInline.c
       COMPILE_DEFINITIONS "-Dinline=${KEYWORD}"
       )
     IF(C_HAS_${KEYWORD})
       SET(C_INLINE TRUE)
       ADD_DEFINITIONS("-Dinline=${KEYWORD}")
     ENDIF(C_HAS_${KEYWORD})
   ENDIF(NOT DEFINED C_INLINE)
ENDFOREACH(KEYWORD)

IF(NOT DEFINED C_INLINE)
   ADD_DEFINITIONS("-Dinline=")
ENDIF(NOT DEFINED C_INLINE)

SET(RESTRICT_TEST_SRC "/* Inspired by autoconf's c.m4 */
int foo (int * restrict ip){return ip[0]\;}
int main(int argc, char *argv[]){int s[1]\;
int * restrict t = s\; t[0] = 0\; return foo(t)\;}
")

FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCRestrict.c
  ${RESTRICT_TEST_SRC})

FOREACH(KEYWORD "restrict" "__restrict" "__restrict__" "_Restrict")
   IF(NOT DEFINED C_RESTRICT)
     TRY_COMPILE(C_HAS_${KEYWORD}
       ${CMAKE_CURRENT_BINARY_DIR}
       ${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCRestrict.c
       COMPILE_DEFINITIONS "-Drestrict=${KEYWORD}"
       )
     IF(C_HAS_${KEYWORD})
       SET(C_RESTRICT TRUE)
       ADD_DEFINITIONS("-Drestrict=${KEYWORD}")
     ENDIF(C_HAS_${KEYWORD})
   ENDIF(NOT DEFINED C_RESTRICT)
ENDFOREACH(KEYWORD)

IF(NOT DEFINED C_RESTRICT)
   ADD_DEFINITIONS("-Drestrict=")
ENDIF(NOT DEFINED C_RESTRICT)

CONFIGURE_FILE(
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
74 75 76 77
  ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
  ${CMAKE_CURRENT_BINARY_DIR}/config.h
  )

78
SET(BUILD_SHARED_LIBS TRUE)
79 80 81
INCLUDE_DIRECTORIES("${PROJECT_BINARY_DIR}")
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(tests EXCLUDE_FROM_ALL)