Commit 627426f1 authored by Mathis Rosenhauer's avatar Mathis Rosenhauer

CMake checks for inline and restrict. Toupper.

parent 7d528864
cmake_minimum_required(VERSION 2.6) CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
include(CheckIncludeFiles) INCLUDE(CheckIncludeFiles)
include(TestBigEndian) INCLUDE(TestBigEndian)
include(CheckCSourceCompiles) INCLUDE(CheckCSourceCompiles)
project(libaec) PROJECT(libaec)
set(libaec_VERSION_MAJOR 0) SET(libaec_VERSION_MAJOR 0)
set(libaec_VERSION_MINOR 2) SET(libaec_VERSION_MINOR 2)
set(CMAKE_BUILD_TYPE Release) SET(CMAKE_BUILD_TYPE Release)
enable_testing() ENABLE_TESTING()
if(CMAKE_COMPILER_IS_GNUCC) CHECK_INCLUDE_FILES(malloc.h HAVE_MALLOC_H)
set(CMAKE_C_FLAGS "-Wall -std=gnu99 ${CMAKE_C_FLAGS}") CHECK_INCLUDE_FILES(stdint.h HAVE_STDINT_H)
endif(CMAKE_COMPILER_IS_GNUCC) TEST_BIG_ENDIAN(WORDS_BIGENDIAN)
CHECK_C_SOURCE_COMPILES(
check_include_files(malloc.h HAVE_MALLOC_H) "int main(int argc, char *argv[])
check_include_files(stdint.h HAVE_STDINT_H) {return __builtin_clzll(1LL)\;}"
test_big_endian(WORDS_BIGENDIAN)
check_c_source_compiles(
"int main(void) { return __builtin_clzll(1LL); }"
HAVE_DECL___BUILTIN_CLZLL HAVE_DECL___BUILTIN_CLZLL
) )
configure_file( #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(
${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
${CMAKE_CURRENT_BINARY_DIR}/config.h ${CMAKE_CURRENT_BINARY_DIR}/config.h
) )
include_directories("${PROJECT_BINARY_DIR}") INCLUDE_DIRECTORIES("${PROJECT_BINARY_DIR}")
ADD_SUBDIRECTORY(src)
add_subdirectory(src) ADD_SUBDIRECTORY(tests EXCLUDE_FROM_ALL)
add_subdirectory(tests EXCLUDE_FROM_ALL)
set(libaec_SRCS encode.c encode_accessors.c decode.c) SET(libaec_SRCS encode.c encode_accessors.c decode.c)
add_library(aec SHARED ${libaec_SRCS}) ADD_LIBRARY(aec SHARED ${libaec_SRCS})
set_target_properties(aec PROPERTIES SET_TARGET_PROPERTIES(aec PROPERTIES
VERSION 0 VERSION 0
SOVERSION 0.0 SOVERSION 0.0
) )
add_library(sz SHARED sz_compat.c) ADD_LIBRARY(sz SHARED sz_compat.c)
set_target_properties(sz PROPERTIES SET_TARGET_PROPERTIES(sz PROPERTIES
VERSION 0 VERSION 0
SOVERSION 0.0 SOVERSION 0.0
) )
target_link_libraries(sz aec) TARGET_LINK_LIBRARIES(sz aec)
add_executable(aec_client aec.c) ADD_EXECUTABLE(aec_client aec.c)
set_target_properties(aec_client PROPERTIES OUTPUT_NAME "aec") SET_TARGET_PROPERTIES(aec_client PROPERTIES OUTPUT_NAME "aec")
target_link_libraries(aec_client aec) TARGET_LINK_LIBRARIES(aec_client aec)
add_executable(utime EXCLUDE_FROM_ALL utime.c) ADD_EXECUTABLE(utime EXCLUDE_FROM_ALL utime.c)
install(FILES libaec.h szlib.h DESTINATION include) INSTALL(FILES libaec.h szlib.h DESTINATION include)
install(TARGETS aec sz INSTALL(TARGETS aec sz
RUNTIME DESTINATION bin RUNTIME DESTINATION bin
LIBRARY DESTINATION lib LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib ARCHIVE DESTINATION lib
) )
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/aec DESTINATION bin) INSTALL(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/aec DESTINATION bin)
add_library(check_aec check_aec.c) ADD_LIBRARY(check_aec check_aec.c)
add_executable(check_code_options check_code_options.c) ADD_EXECUTABLE(check_code_options check_code_options.c)
target_link_libraries(check_code_options check_aec aec) TARGET_LINK_LIBRARIES(check_code_options check_aec aec)
add_executable(check_buffer_sizes check_buffer_sizes.c) ADD_EXECUTABLE(check_buffer_sizes check_buffer_sizes.c)
target_link_libraries(check_buffer_sizes check_aec aec) TARGET_LINK_LIBRARIES(check_buffer_sizes check_aec aec)
add_executable(check_long_fs check_long_fs.c) ADD_EXECUTABLE(check_long_fs check_long_fs.c)
target_link_libraries(check_long_fs check_aec aec) TARGET_LINK_LIBRARIES(check_long_fs check_aec aec)
add_test(check_code_options check_code_options) ADD_TEST(check_code_options check_code_options)
add_test(check_buffer_sizes check_buffer_sizes) ADD_TEST(check_buffer_sizes check_buffer_sizes)
add_test(check_long_fs check_long_fs) ADD_TEST(check_long_fs check_long_fs)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}) ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND})
add_dependencies(check ADD_DEPENDENCIES(check
check_code_options check_code_options
check_buffer_sizes check_buffer_sizes
check_long_fs) check_long_fs)
add_custom_target(bench ADD_CUSTOM_TARGET(bench
COMMAND ${CMAKE_SOURCE_DIR}/tests/benc.sh COMMAND ${CMAKE_SOURCE_DIR}/tests/benc.sh
COMMAND ${CMAKE_SOURCE_DIR}/tests/bdec.sh COMMAND ${CMAKE_SOURCE_DIR}/tests/bdec.sh
DEPENDS aec_client utime DEPENDS aec_client utime
......
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