Commit 8cd1a00d authored by Mathis Rosenhauer's avatar Mathis Rosenhauer

cmake: fuzzing

parent d5a9a756
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.6) cmake_minimum_required(VERSION 2.8.6)
INCLUDE(CheckIncludeFiles) include(CheckIncludeFiles)
INCLUDE(TestBigEndian) include(TestBigEndian)
INCLUDE(CheckCSourceCompiles) include(CheckCSourceCompiles)
INCLUDE(cmake/macros.cmake) include(cmake/macros.cmake)
PROJECT(libaec) project(libaec)
SET(libaec_VERSION_MAJOR 1) set(libaec_VERSION_MAJOR 1)
SET(libaec_VERSION_MINOR 0) set(libaec_VERSION_MINOR 0)
SET(libaec_VERSION_PATCH 0) set(libaec_VERSION_PATCH 0)
SET(CMAKE_BUILD_TYPE Release) set(CMAKE_BUILD_TYPE Release)
ENABLE_TESTING() 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_CLZLL(HAVE_DECL___BUILTIN_CLZLL) check_clzll(HAVE_DECL___BUILTIN_CLZLL)
IF(NOT HAVE_DECL___BUILTIN_CLZLL) if(NOT HAVE_DECL___BUILTIN_CLZLL)
CHECK_BSR64(HAVE_BSR64) check_bsr64(HAVE_BSR64)
ENDIF(NOT HAVE_DECL___BUILTIN_CLZLL) endif(NOT HAVE_DECL___BUILTIN_CLZLL)
FIND_INLINE_KEYWORD() find_inline_keyword()
FIND_RESTRICT_KEYWORD() find_restrict_keyword()
CONFIGURE_FILE( configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/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")
# Allow the developer to select if Dynamic or Static libraries are built option(BUILD_SHARED_LIBS "Build Shared Libraries" ON)
OPTION(BUILD_SHARED_LIBS "Build Shared Libraries" ON) if(BUILD_SHARED_LIBS)
IF(BUILD_SHARED_LIBS) set (LIB_TYPE SHARED)
SET (LIB_TYPE SHARED) else(BUILD_SHARED_LIBS)
ELSE(BUILD_SHARED_LIBS) if(WIN32)
IF(WIN32) message(WARNING "You will have to modify libaec.h for static libs.")
MESSAGE(WARNING "You will have to modify libaec.h for static libs.") endif(WIN32)
ENDIF(WIN32) set(LIB_TYPE STATIC)
SET(LIB_TYPE STATIC) endif(BUILD_SHARED_LIBS)
ENDIF(BUILD_SHARED_LIBS)
INCLUDE_DIRECTORIES("${PROJECT_BINARY_DIR}") set(libaec_SRCS
INCLUDE_DIRECTORIES("${PROJECT_BINARY_DIR}/src") ${PROJECT_SOURCE_DIR}/src/encode.c
INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/src") ${PROJECT_SOURCE_DIR}/src/encode_accessors.c
${PROJECT_SOURCE_DIR}/src/decode.c)
ADD_SUBDIRECTORY(src) include_directories("${PROJECT_BINARY_DIR}")
# EXCLUDE_FROM_ALL doesn't seem to be working in VS include_directories("${PROJECT_SOURCE_DIR}/src")
ADD_SUBDIRECTORY(tests)
SET(CPACK_PACKAGE_NAME "libaec") add_subdirectory(src)
SET(CPACK_PACKAGE_VENDOR "Deutsches Klimarechenzentrum GmbH") add_subdirectory(tests)
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY
option(AEC_FUZZING "Enable build of fuzzing targets" OFF)
if(AEC_FUZZING)
add_subdirectory(fuzz)
endif()
set(CPACK_PACKAGE_NAME "libaec")
set(CPACK_PACKAGE_VENDOR "Deutsches Klimarechenzentrum GmbH")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
"libaec - Adaptive Entropy Coding library") "libaec - Adaptive Entropy Coding library")
SET(CPACK_PACKAGE_VERSION_MAJOR "${libaec_VERSION_MAJOR}") set(CPACK_PACKAGE_VERSION_MAJOR "${libaec_VERSION_MAJOR}")
SET(CPACK_PACKAGE_VERSION_MINOR "${libaec_VERSION_MINOR}") set(CPACK_PACKAGE_VERSION_MINOR "${libaec_VERSION_MINOR}")
SET(CPACK_PACKAGE_VERSION_PATCH "${libaec_VERSION_PATCH}") set(CPACK_PACKAGE_VERSION_PATCH "${libaec_VERSION_PATCH}")
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "libaec") set(CPACK_PACKAGE_INSTALL_DIRECTORY "libaec")
SET(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/Copyright.txt") set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/Copyright.txt")
IF(WIN32) if(WIN32)
SET(CPACK_GENERATOR "WIX") set(CPACK_GENERATOR "WIX")
SET(CPACK_WIX_UPGRADE_GUID "E58A21F6-BB99-46B5-8AD8-6114E4CCA0A6") set(CPACK_WIX_UPGRADE_GUID "E58A21F6-BB99-46B5-8AD8-6114E4CCA0A6")
IF(CMAKE_CL_64) if(CMAKE_CL_64)
SET(CPACK_INSTALL_DIRECTORY "$PROGRAMFILES64") set(CPACK_INSTALL_DIRECTORY "$PROGRAMFILES64")
SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION} (Win64)") "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION} (Win64)")
ELSE(CMAKE_CL_64) else(CMAKE_CL_64)
SET(CPACK_INSTALL_DIRECTORY "$PROGRAMFILES") set(CPACK_INSTALL_DIRECTORY "$PROGRAMFILES")
SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
ENDIF(CMAKE_CL_64) endif(CMAKE_CL_64)
ENDIF(WIN32) endif(WIN32)
INCLUDE(CPack) include(CPack)
MACRO(CHECK_CLZLL VARIABLE) macro(check_clzll VARIABLE)
CHECK_C_SOURCE_COMPILES( check_c_source_compiles(
"int main(int argc, char *argv[]) "int main(int argc, char *argv[])
{return __builtin_clzll(1LL);}" {return __builtin_clzll(1LL);}"
${VARIABLE} ${VARIABLE}
) )
ENDMACRO() endmacro()
MACRO(CHECK_BSR64 VARIABLE) macro(check_bsr64 VARIABLE)
CHECK_C_SOURCE_COMPILES( check_c_source_compiles(
"int main(int argc, char *argv[]) "int main(int argc, char *argv[])
{unsigned long foo; unsigned __int64 bar=1LL; {unsigned long foo; unsigned __int64 bar=1LL;
return _BitScanReverse64(&foo, bar);}" return _BitScanReverse64(&foo, bar);}"
${VARIABLE} ${VARIABLE}
) )
ENDMACRO() endmacro()
MACRO(FIND_INLINE_KEYWORD) macro(find_inline_keyword)
#Inspired from http://www.cmake.org/Wiki/CMakeTestInline #Inspired from http://www.cmake.org/Wiki/CMakeTestInline
SET(INLINE_TEST_SRC "/* Inspired by autoconf's c.m4 */ set(INLINE_TEST_SRC "/* Inspired by autoconf's c.m4 */
static inline int static_foo(){return 0\;} static inline int static_foo(){return 0\;}
int main(int argc, char *argv[]){return 0\;} int main(int argc, char *argv[]){return 0\;}
") ")
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCInline.c file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCInline.c
${INLINE_TEST_SRC}) ${INLINE_TEST_SRC})
FOREACH(KEYWORD "inline" "__inline__" "__inline") foreach(KEYWORD "inline" "__inline__" "__inline")
IF(NOT DEFINED C_INLINE) if(NOT DEFINED C_INLINE)
TRY_COMPILE(C_HAS_${KEYWORD} try_compile(C_HAS_${KEYWORD}
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCInline.c ${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCInline.c
COMPILE_DEFINITIONS "-Dinline=${KEYWORD}" COMPILE_DEFINITIONS "-Dinline=${KEYWORD}"
) )
IF(C_HAS_${KEYWORD}) if(C_HAS_${KEYWORD})
SET(C_INLINE TRUE) set(C_INLINE TRUE)
ADD_DEFINITIONS("-Dinline=${KEYWORD}") add_definitions("-Dinline=${KEYWORD}")
MESSAGE(STATUS "Inline keyword found - ${KEYWORD}") message(STATUS "Inline keyword found - ${KEYWORD}")
ENDIF(C_HAS_${KEYWORD}) endif(C_HAS_${KEYWORD})
ENDIF(NOT DEFINED C_INLINE) endif(NOT DEFINED C_INLINE)
ENDFOREACH(KEYWORD) endforeach(KEYWORD)
IF(NOT DEFINED C_INLINE) if(NOT DEFINED C_INLINE)
ADD_DEFINITIONS("-Dinline=") add_definitions("-Dinline=")
MESSAGE(STATUS "Inline keyword - not found") message(STATUS "Inline keyword - not found")
ENDIF(NOT DEFINED C_INLINE) endif(NOT DEFINED C_INLINE)
ENDMACRO(FIND_INLINE_KEYWORD) endmacro(find_inline_keyword)
MACRO(FIND_RESTRICT_KEYWORD) macro(find_restrict_keyword)
SET(RESTRICT_TEST_SRC "/* Inspired by autoconf's c.m4 */ set(RESTRICT_TEST_SRC "/* Inspired by autoconf's c.m4 */
int foo (int * restrict ip){return ip[0]\;} int foo (int * restrict ip){return ip[0]\;}
int main(int argc, char *argv[]){int s[1]\; int main(int argc, char *argv[]){int s[1]\;
int * restrict t = s\; t[0] = 0\; return foo(t)\;} int * restrict t = s\; t[0] = 0\; return foo(t)\;}
") ")
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCRestrict.c file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCRestrict.c
${RESTRICT_TEST_SRC}) ${RESTRICT_TEST_SRC})
FOREACH(KEYWORD "restrict" "__restrict" "__restrict__" "_Restrict") foreach(KEYWORD "restrict" "__restrict" "__restrict__" "_Restrict")
IF(NOT DEFINED C_RESTRICT) if(NOT DEFINED C_RESTRICT)
TRY_COMPILE(C_HAS_${KEYWORD} try_compile(C_HAS_${KEYWORD}
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCRestrict.c ${CMAKE_CURRENT_BINARY_DIR}/CMakeTestCRestrict.c
COMPILE_DEFINITIONS "-Drestrict=${KEYWORD}" COMPILE_DEFINITIONS "-Drestrict=${KEYWORD}"
) )
IF(C_HAS_${KEYWORD}) if(C_HAS_${KEYWORD})
SET(C_RESTRICT TRUE) set(C_RESTRICT TRUE)
ADD_DEFINITIONS("-Drestrict=${KEYWORD}") add_definitions("-Drestrict=${KEYWORD}")
MESSAGE(STATUS "Restrict keyword found - ${KEYWORD}") message(STATUS "Restrict keyword found - ${KEYWORD}")
ENDIF(C_HAS_${KEYWORD}) endif(C_HAS_${KEYWORD})
ENDIF(NOT DEFINED C_RESTRICT) endif(NOT DEFINED C_RESTRICT)
ENDFOREACH(KEYWORD) endforeach(KEYWORD)
IF(NOT DEFINED C_RESTRICT) if(NOT DEFINED C_RESTRICT)
ADD_DEFINITIONS("-Drestrict=") add_definitions("-Drestrict=")
MESSAGE(STATUS "Restrict keyword - not found") message(STATUS "Restrict keyword - not found")
ENDIF(NOT DEFINED C_RESTRICT) endif(NOT DEFINED C_RESTRICT)
ENDMACRO(FIND_RESTRICT_KEYWORD) endmacro(find_restrict_keyword)
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message(FATAL_ERROR "You need to build with Clang for fuzzing to work")
endif()
add_library(aec_fuzz STATIC ${libaec_SRCS})
add_executable(fuzz_target fuzz_target.cc)
set(FUZZ_TARGET_LINK_FLAGS "-fsanitize=address")
set(FUZZ_TARGET_COMPILE_FLAGS
"-g"
"-fsanitize=address"
"-fsanitize-coverage=trace-pc-guard,indirect-calls,edge")
set_target_properties(fuzz_target aec_fuzz PROPERTIES
LINK_FLAGS ${FUZZ_TARGET_LINK_FLAGS}
COMPILE_OPTIONS "${FUZZ_TARGET_COMPILE_FLAGS}")
target_link_libraries(fuzz_target aec_fuzz Fuzzer)
SET(libaec_SRCS encode.c encode_accessors.c decode.c) add_library(aec ${LIB_TYPE} ${libaec_SRCS})
ADD_LIBRARY(aec ${LIB_TYPE} ${libaec_SRCS}) set_target_properties(aec PROPERTIES VERSION 0.0.6 SOVERSION 0)
SET_TARGET_PROPERTIES(aec PROPERTIES add_library(sz ${LIB_TYPE} sz_compat.c)
VERSION 0.0.6 SOVERSION 0 set_target_properties(sz PROPERTIES VERSION 2.0.1 SOVERSION 2)
)
ADD_LIBRARY(sz ${LIB_TYPE} sz_compat.c)
SET_TARGET_PROPERTIES(sz PROPERTIES
VERSION 2.0.1 SOVERSION 2
)
TARGET_LINK_LIBRARIES(sz aec) target_link_libraries(sz aec)
IF(WIN32 AND BUILD_SHARED_LIBS) if(WIN32 AND BUILD_SHARED_LIBS)
SET_TARGET_PROPERTIES (aec PROPERTIES DEFINE_SYMBOL "BUILDING_LIBAEC") set_target_properties (aec PROPERTIES DEFINE_SYMBOL "BUILDING_LIBAEC")
SET_TARGET_PROPERTIES (sz PROPERTIES DEFINE_SYMBOL "BUILDING_LIBAEC") set_target_properties (sz PROPERTIES DEFINE_SYMBOL "BUILDING_LIBAEC")
SET_TARGET_PROPERTIES(sz PROPERTIES OUTPUT_NAME "szip") set_target_properties(sz PROPERTIES OUTPUT_NAME "szip")
ENDIF(WIN32 AND BUILD_SHARED_LIBS) endif(WIN32 AND BUILD_SHARED_LIBS)
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)
IF(UNIX) if(UNIX)
ADD_EXECUTABLE(utime EXCLUDE_FROM_ALL utime.c) add_executable(utime EXCLUDE_FROM_ALL utime.c)
ADD_CUSTOM_TARGET(bench add_custom_target(bench
COMMAND ${CMAKE_SOURCE_DIR}/src/benc.sh ${CMAKE_SOURCE_DIR}/data/typical.rz COMMAND ${CMAKE_SOURCE_DIR}/src/benc.sh ${CMAKE_SOURCE_DIR}/data/typical.rz
COMMAND ${CMAKE_SOURCE_DIR}/src/bdec.sh COMMAND ${CMAKE_SOURCE_DIR}/src/bdec.sh
DEPENDS aec_client utime DEPENDS aec_client utime)
) endif(UNIX)
ENDIF(UNIX)
INCLUDE(GNUInstallDirs) include(GNUInstallDirs)
IF(WIN32) if(WIN32)
INSTALL(TARGETS aec sz install(TARGETS aec sz
RUNTIME RUNTIME
DESTINATION bin DESTINATION bin
ARCHIVE ARCHIVE
DESTINATION lib DESTINATION lib
COMPONENT libraries COMPONENT libraries)
) else(WIN32)
ELSE(WIN32) install(TARGETS aec sz
INSTALL(TARGETS aec sz
LIBRARY LIBRARY
DESTINATION ${CMAKE_INSTALL_LIBDIR} DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE ARCHIVE
DESTINATION ${CMAKE_INSTALL_LIBDIR} DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT libraries COMPONENT libraries)
) endif(WIN32)
ENDIF(WIN32) install(FILES libaec.h szlib.h
INSTALL(FILES libaec.h szlib.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
COMPONENT headers COMPONENT headers)
) install(TARGETS aec_client
INSTALL(TARGETS aec_client
RUNTIME RUNTIME
DESTINATION ${CMAKE_INSTALL_BINDIR} DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT applications COMPONENT applications)
)
SET(CPACK_COMPONENTS_ALL applications libraries headers) set(CPACK_COMPONENTS_ALL applications libraries headers)
ADD_LIBRARY(check_aec STATIC check_aec.c) add_library(check_aec STATIC 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_TEST(NAME check_code_options COMMAND check_code_options) add_test(NAME check_code_options COMMAND check_code_options)
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_TEST(NAME check_buffer_sizes COMMAND check_buffer_sizes) add_test(NAME check_buffer_sizes COMMAND check_buffer_sizes)
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(NAME check_long_fs COMMAND check_long_fs) add_test(NAME check_long_fs COMMAND check_long_fs)
ADD_EXECUTABLE(check_szcomp check_szcomp.c) add_executable(check_szcomp check_szcomp.c)
TARGET_LINK_LIBRARIES(check_szcomp check_aec sz) target_link_libraries(check_szcomp check_aec sz)
ADD_TEST(NAME check_szcomp add_test(NAME check_szcomp
COMMAND check_szcomp ${CMAKE_CURRENT_SOURCE_DIR}/../data/121B2TestData/ExtendedParameters/sar32bit.dat) COMMAND check_szcomp ${PROJECT_SOURCE_DIR}/data/121B2TestData/ExtendedParameters/sar32bit.dat)
IF(UNIX) if(UNIX)
ADD_TEST( add_test(
NAME sampledata.sh NAME sampledata.sh
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/sampledata.sh ${CMAKE_CURRENT_SOURCE_DIR} COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/sampledata.sh ${CMAKE_CURRENT_SOURCE_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
) endif(UNIX)
ENDIF(UNIX)
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