CMakeLists.txt 3.07 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
  )
19 20 21 22 23 24 25 26
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)
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 74 75 76 77 78 79 80 81
#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(
82 83 84
  ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
  ${CMAKE_CURRENT_BINARY_DIR}/config.h
  )
85 86 87 88 89 90 91 92
ADD_DEFINITIONS("-DHAVE_CONFIG_H")

# Allow the developer to select if Dynamic or Static libraries are built
OPTION (BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
IF (BUILD_SHARED_LIBS)
  # User wants to build Dynamic Libraries,
  # so change the LIB_TYPE variable to CMake keyword 'SHARED'
  SET (LIB_TYPE SHARED)
93 94
ELSE(BUILD_SHARED_LIBS)
  SET (LIB_TYPE STATIC)
95
ENDIF (BUILD_SHARED_LIBS)
96

97
INCLUDE_DIRECTORIES("${PROJECT_BINARY_DIR}")
98
INCLUDE_DIRECTORIES("${PROJECT_BINARY_DIR}/src")
99 100
INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/src")

101
ADD_SUBDIRECTORY(src)
102 103 104 105 106
IF(WIN32)
  ADD_SUBDIRECTORY(tests)
ELSE(WIN32)
  ADD_SUBDIRECTORY(tests EXCLUDE_FROM_ALL)
ENDIF(WIN32)