Commit 6e67b01c authored by Mathis Rosenhauer's avatar Mathis Rosenhauer

Move some CMake chunks as macros in separate file

parent 07c75449
...@@ -16,6 +16,4 @@ libtool ...@@ -16,6 +16,4 @@ libtool
autom4te.cache autom4te.cache
.DS_Store .DS_Store
data data
*.cmake build*
CMakeFiles
build
...@@ -2,6 +2,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8.6) ...@@ -2,6 +2,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8.6)
INCLUDE(CheckIncludeFiles) INCLUDE(CheckIncludeFiles)
INCLUDE(TestBigEndian) INCLUDE(TestBigEndian)
INCLUDE(CheckCSourceCompiles) INCLUDE(CheckCSourceCompiles)
INCLUDE(cmake/macros.cmake)
PROJECT(libaec) PROJECT(libaec)
SET(libaec_VERSION_MAJOR 0) SET(libaec_VERSION_MAJOR 0)
SET(libaec_VERSION_MINOR 2) SET(libaec_VERSION_MINOR 2)
...@@ -11,75 +12,15 @@ ENABLE_TESTING() ...@@ -11,75 +12,15 @@ ENABLE_TESTING()
CHECK_INCLUDE_FILES(malloc.h HAVE_MALLOC_H) CHECK_INCLUDE_FILES(malloc.h HAVE_MALLOC_H)
CHECK_INCLUDE_FILES(stdint.h HAVE_STDINT_H) CHECK_INCLUDE_FILES(stdint.h HAVE_STDINT_H)
TEST_BIG_ENDIAN(WORDS_BIGENDIAN) TEST_BIG_ENDIAN(WORDS_BIGENDIAN)
CHECK_C_SOURCE_COMPILES( CHECK_CLZLL(HAVE_DECL___BUILTIN_CLZLL)
"int main(int argc, char *argv[]) IF(NOT HAVE_DECL___BUILTIN_CLZLL)
{return __builtin_clzll(1LL);}" CHECK_BSR64(HAVE_BSR64)
HAVE_DECL___BUILTIN_CLZLL ENDIF(NOT HAVE_DECL___BUILTIN_CLZLL)
) FIND_INLINE_KEYWORD()
IF (NOT HAVE_DECL___BUILTIN_CLZLL) FIND_RESTRICT_KEYWORD()
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)
#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( CONFIGURE_FILE(
${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.in
${CMAKE_CURRENT_BINARY_DIR}/config.h ${CMAKE_CURRENT_BINARY_DIR}/config.h
) )
ADD_DEFINITIONS("-DHAVE_CONFIG_H") ADD_DEFINITIONS("-DHAVE_CONFIG_H")
......
MACRO(CHECK_CLZLL VARIABLE)
CHECK_C_SOURCE_COMPILES(
"int main(int argc, char *argv[])
{return __builtin_clzll(1LL);}"
${VARIABLE}
)
ENDMACRO()
MACRO(CHECK_BSR64 VARIABLE)
CHECK_C_SOURCE_COMPILES(
"int main(int argc, char *argv[])
{unsigned long foo; unsigned __int64 bar=1LL;
return _BitScanReverse64(&foo, bar);}"
${VARIABLE}
)
ENDMACRO()
MACRO(FIND_INLINE_KEYWORD)
#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}")
MESSAGE(STATUS "Inline keyword found - ${KEYWORD}")
ENDIF(C_HAS_${KEYWORD})
ENDIF(NOT DEFINED C_INLINE)
ENDFOREACH(KEYWORD)
IF(NOT DEFINED C_INLINE)
ADD_DEFINITIONS("-Dinline=")
MESSAGE(STATUS "Inline keyword - not found")
ENDIF(NOT DEFINED C_INLINE)
ENDMACRO(FIND_INLINE_KEYWORD)
MACRO(FIND_RESTRICT_KEYWORD)
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}")
MESSAGE(STATUS "Restrict keyword found - ${KEYWORD}")
ENDIF(C_HAS_${KEYWORD})
ENDIF(NOT DEFINED C_RESTRICT)
ENDFOREACH(KEYWORD)
IF(NOT DEFINED C_RESTRICT)
ADD_DEFINITIONS("-Drestrict=")
MESSAGE(STATUS "Restrict keyword - not found")
ENDIF(NOT DEFINED C_RESTRICT)
ENDMACRO(FIND_RESTRICT_KEYWORD)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment