include(CheckIncludeFile) include(CheckSymbolExists) include(CheckTypeSize) include(CheckFunctionKeywords) include(CheckLFS) ## Checks for header files ## check_include_file("inttypes.h" HAVE_INTTYPES_H) check_include_file("stdlib.h" HAVE_STDLIB_H) check_include_file("stdint.h" HAVE_STDINT_H) check_include_file("sys/int_types.h" HAVE_SYS_INT_TYPES_H) if(BUILD_SAMPLES) ## Checks for header files ## check_include_file("stddef.h" HAVE_STDDEF_H) check_include_file("memory.h" HAVE_MEMORY_H) check_include_file("string.h" HAVE_STRING_H) check_include_file("strings.h" HAVE_STRINGS_H) check_include_file("sys/types.h" HAVE_SYS_TYPES_H) ## Checks for WinIO ## if(WIN32) check_include_file("io.h" HAVE_IO_H) check_include_file("fcntl.h" HAVE_FCNTL_H) check_symbol_exists("_setmode" "io.h;fcntl.h" HAVE__SETMODE) if(NOT HAVE__SETMODE) check_symbol_exists("setmode" "io.h;fcntl.h" HAVE_SETMODE) endif(NOT HAVE__SETMODE) check_symbol_exists("_fileno" "stdio.h" HAVE__FILENO) check_symbol_exists("fopen_s" "stdio.h" HAVE_FOPEN_S) check_symbol_exists("_O_BINARY" "fcntl.h" HAVE__O_BINARY) endif(WIN32) ## Checks for large file support ## check_lfs(WITH_LFS) ## generate sample_config.h ## configure_file("${CMAKE_CURRENT_SOURCE_DIR}/sample_config.h.cmake" "${CMAKE_CURRENT_BINARY_DIR}/sample_config.h" @ONLY) endif(BUILD_SAMPLES) ## Checks for inline ## check_function_keywords("inline;__inline;__inline__") if(HAVE_INLINE) set(INLINE "inline") elseif(HAVE___INLINE) set(INLINE "__inline") elseif(HAVE___INLINE__) set(INLINE "__inline__") else(HAVE_INLINE) set(INLINE "") endif(HAVE_INLINE) ## Checks for types ## # 32-bit integer check_type_size("int32_t" INT32_T) if(HAVE_INT32_T) set(INT32_TYPE "int32_t") check_symbol_exists("PRId32" "inttypes.h" HAVE_PRID32) if(HAVE_PRID32) set(INT32_PRId "PRId32") else(HAVE_PRID32) set(INT32_PRId "\"d\"") endif(HAVE_PRID32) else(HAVE_INT32_T) check_type_size("int" SIZEOF_INT) check_type_size("long" SIZEOF_LONG) check_type_size("short" SIZEOF_SHORT) check_type_size("__int32" SIZEOF___INT32) if("${SIZEOF_INT}" STREQUAL "4") set(INT32_TYPE "int") set(INT32_PRId "\"d\"") elseif("${SIZEOF_LONG}" STREQUAL "4") set(INT32_TYPE "long") set(INT32_PRId "\"ld\"") elseif("${SIZEOF_SHORT}" STREQUAL "4") set(INT32_TYPE "short") set(INT32_PRId "\"d\"") elseif("${SIZEOF___INT32}" STREQUAL "4") set(INT32_TYPE "__int32") set(INT32_PRId "\"d\"") else("${SIZEOF_INT}" STREQUAL "4") message(FATAL_ERROR "Could not determine 32-bit integer type.") endif("${SIZEOF_INT}" STREQUAL "4") endif(HAVE_INT32_T) # 32-bit unsigned integer check_type_size("uint32_t" UINT32_T) if(HAVE_UINT32_T) set(UINT32_TYPE "uint32_t") else(HAVE_UINT32_T) check_type_size("unsigned int" SIZEOF_UNSIGNED_INT) check_type_size("unsigned long" SIZEOF_UNSIGNED_LONG) check_type_size("unsigned short" SIZEOF_UNSIGNED_SHORT) check_type_size("unsigned __int32" SIZEOF_UNSIGNED___INT32) if("${SIZEOF_UNSIGNED_INT}" STREQUAL "4") set(UINT32_TYPE "unsigned int") elseif("${SIZEOF_UNSIGNED_LONG}" STREQUAL "4") set(UINT32_TYPE "unsigned long") elseif("${SIZEOF_UNSIGNED_SHORT}" STREQUAL "4") set(UINT32_TYPE "unsigned short") elseif("${SIZEOF_UNSIGNED___INT32}" STREQUAL "4") set(UINT32_TYPE "unsigned __int32") else("${SIZEOF_UNSIGNED_INT}" STREQUAL "4") message(FATAL_ERROR "Could not determine 32-bit unsigned integer type.") endif("${SIZEOF_UNSIGNED_INT}" STREQUAL "4") endif(HAVE_UINT32_T) # 64-bit integer check_type_size("int64_t" INT64_T) if(HAVE_INT64_T) set(INT64_TYPE "int64_t") check_symbol_exists("PRId64" "inttypes.h" HAVE_PRID64) if(HAVE_PRID64) set(INT64_PRId "PRId64") else(HAVE_PRID64) set(INT64_PRId "\"lld\"") endif(HAVE_PRID64) else(HAVE_INT64_T) set(SIZEOF_LONG_LONG "0") check_type_size("int" SIZEOF_INT) check_type_size("long" SIZEOF_LONG) check_type_size("__int64" SIZEOF___INT64) check_type_size("long long" SIZEOF_LONG_LONG) if("${SIZEOF_INT}" STREQUAL "8") set(INT64_TYPE "int") set(INT64_PRId "\"d\"") elseif("${SIZEOF_LONG}" STREQUAL "8") set(INT64_TYPE "long") set(INT64_PRId "\"ld\"") elseif("${SIZEOF___INT64}" STREQUAL "8") set(INT64_TYPE "__int64") set(INT64_PRId "\"I64d\"") elseif("${SIZEOF_LONG_LONG}" STREQUAL "8") set(INT64_TYPE "long long") set(INT64_PRId "\"lld\"") else("${SIZEOF_INT}" STREQUAL "8") if(ENABLE_BWTWT64) message(SEND_ERROR "Could not determine 64-bit integer type.") set(ENABLE_BWTWT64 OFF) set(INT64_PRId "\"ld\"") set(INT64_TYPE "long") endif(ENABLE_BWTWT64) endif("${SIZEOF_INT}" STREQUAL "8") endif(HAVE_INT64_T) # 64-bit unsigned integer check_type_size("uint64_t" UINT64_T) if(HAVE_UINT64_T) set(UINT64_TYPE "uint64_t") else(HAVE_UINT64_T) check_type_size("unsigned int" SIZEOF_UNSIGNED_INT) check_type_size("unsigned long" SIZEOF_UNSIGNED_LONG) check_type_size("unsigned __int64" SIZEOF_UNSIGNED___INT64) check_type_size("unsigned long long" SIZEOF_UNSIGNED_LONG_LONG) if("${SIZEOF_UNSIGNED_INT}" STREQUAL "8") set(UINT64_TYPE "unsigned int") elseif("${SIZEOF_UNSIGNED_LONG}" STREQUAL "8") set(UINT64_TYPE "unsigned long") elseif("${SIZEOF_UNSIGNED___INT64}" STREQUAL "8") set(UINT64_TYPE "unsigned __int64") elseif("${SIZEOF_UNSIGNED_LONG_LONG}" STREQUAL "8") set(UINT64_TYPE "unsigned long long") else("${SIZEOF_UNSIGNED_INT}" STREQUAL "8") if(ENABLE_BWTWT64) message(SEND_ERROR "Could not determine 64-bit unsigned integer type.") set(ENABLE_BWTWT64 OFF) set(UINT64_TYPE "unsigned long") endif(ENABLE_BWTWT64) endif("${SIZEOF_UNSIGNED_INT}" STREQUAL "8") endif(HAVE_UINT64_T) ## Checks for import and export ## check_function_keywords("__declspec(dllexport);__declspec(dllimport)") set(OPENBWT_IMPORT "") set(OPENBWT_EXPORT "") if(BUILD_SHARED_LIBS) if(HAVE___DECLSPEC_DLLIMPORT_) set(OPENBWT_IMPORT "__declspec(dllimport)") endif(HAVE___DECLSPEC_DLLIMPORT_) if(HAVE___DECLSPEC_DLLEXPORT_) set(OPENBWT_EXPORT "__declspec(dllexport)") endif(HAVE___DECLSPEC_DLLEXPORT_) endif(BUILD_SHARED_LIBS) ## generate openbwt_config.h ## configure_file("${CMAKE_CURRENT_SOURCE_DIR}/openbwt_config.h.cmake" "${CMAKE_CURRENT_BINARY_DIR}/openbwt_config.h") install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/bwtwt.h" "${CMAKE_CURRENT_SOURCE_DIR}/openbwt.h" "${CMAKE_CURRENT_BINARY_DIR}/openbwt_config.h" DESTINATION include)