CMakeLists.txt 2.7 KB
Newer Older
1
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.6)
2 3 4
INCLUDE(CheckIncludeFiles)
INCLUDE(TestBigEndian)
INCLUDE(CheckCSourceCompiles)
5
INCLUDE(GenerateExportHeader)
6 7 8 9 10 11 12 13 14 15 16
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[])
17
{return __builtin_clzll(1LL);}"
18 19
  HAVE_DECL___BUILTIN_CLZLL
  )
20 21 22 23 24 25 26 27
IF (NOT HAVE_DECL___BUILTIN_CLZLL)
  CHECK_C_SOURCE_COMPILES(
    "int main(int argc, char *argv[])
{unsigned long foo; unsigned __int64 bar=1LL;
return _BitScanReverse64(&foo, bar);}"
    HAVE_BSR64
  )
ENDIF (NOT HAVE_DECL___BUILTIN_CLZLL)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
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 74 75 76 77 78 79 80 81 82
#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
83 84 85 86
  ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
  ${CMAKE_CURRENT_BINARY_DIR}/config.h
  )

87
SET(BUILD_SHARED_LIBS FALSE)
88
INCLUDE_DIRECTORIES("${PROJECT_BINARY_DIR}")
89 90
INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/src")

91
ADD_SUBDIRECTORY(src)
92 93 94 95 96
IF(WIN32)
  ADD_SUBDIRECTORY(tests)
ELSE(WIN32)
  ADD_SUBDIRECTORY(tests EXCLUDE_FROM_ALL)
ENDIF(WIN32)