snappy/CMakeLists.txt

142 lines
4.1 KiB
CMake
Raw Normal View History

CMAKE_MINIMUM_REQUIRED(VERSION 3.1)
PROJECT(Snappy VERSION 1.1.6 LANGUAGES C CXX)
SET(CMAKE_INCLUDE_CURRENT_DIR ON)
INCLUDE(CheckIncludeFiles)
INCLUDE(CheckLibraryExists)
INCLUDE(CheckCXXSourceCompiles)
INCLUDE(CheckSymbolExists)
INCLUDE(TestBigEndian)
INCLUDE(CMakePackageConfigHelpers)
TEST_BIG_ENDIAN(WORDS_BIG_ENDIAN)
IF (WORDS_BIG_ENDIAN)
MESSAGE(STATUS "Building on big endian system")
ADD_DEFINITIONS(-DWORDS_BIGENDIAN=1)
ENDIF (WORDS_BIG_ENDIAN)
CHECK_INCLUDE_FILES("byteswap.h" HAVE_BYTESWAP_H)
CHECK_INCLUDE_FILES("stddef.h" HAVE_STDDEF_H)
CHECK_INCLUDE_FILES("stdint.h" HAVE_STDINT_H)
CHECK_INCLUDE_FILES("sys/endian.h" HAVE_SYS_ENDIAN_H)
CHECK_INCLUDE_FILES("sys/mman.h" HAVE_SYS_MMAN_H)
CHECK_INCLUDE_FILES("sys/resource.h" HAVE_SYS_RESOURCE_H)
CHECK_INCLUDE_FILES("sys/time.h" HAVE_SYS_TIME_H)
CHECK_INCLUDE_FILES("sys/uio.h" HAVE_SYS_UIO_H)
CHECK_INCLUDE_FILES("windows.h" HAVE_WINDOWS_H)
IF (NOT HAVE_SYS_UIO_H)
SET(HAVE_SYS_UIO_H 0)
ENDIF (NOT HAVE_SYS_UIO_H)
IF (NOT HAVE_STDINT_H)
SET(HAVE_STDINT_H 0)
ENDIF (NOT HAVE_STDINT_H)
IF (NOT HAVE_STDDEF_H)
SET(HAVE_STDDEF_H 0)
ENDIF (NOT HAVE_STDDEF_H)
CHECK_LIBRARY_EXISTS(z zlibVersion "" HAVE_LIBZ)
CHECK_LIBRARY_EXISTS(lzo2 lzo1x_1_15_compress "" HAVE_LIBLZO2)
CHECK_SYMBOL_EXISTS(mmap sys/mman.h HAVE_FUNC_MMAP)
CHECK_CXX_SOURCE_COMPILES("int main(void) { return __builtin_expect(0, 1); }"
HAVE_BUILTIN_EXPECT)
CHECK_CXX_SOURCE_COMPILES("int main(void) { return __builtin_ctzll(0); }"
HAVE_BUILTIN_CTZ)
FIND_PACKAGE(GTest QUIET)
IF(GTEST_FOUND)
SET(HAVE_GTEST 1)
ENDIF()
FIND_PACKAGE(Gflags QUIET)
IF(GFLAGS_FOUND)
SET(HAVE_GFLAGS 1)
ENDIF()
CONFIGURE_FILE(${Snappy_SOURCE_DIR}/cmake/config.h.in config.h)
# Configure snappy-stubs-public.h.in
SET(ac_cv_have_stdint_h ${HAVE_STDINT_H})
SET(ac_cv_have_stddef_h ${HAVE_STDDEF_H})
SET(ac_cv_have_sys_uio_h ${HAVE_SYS_UIO_H})
CONFIGURE_FILE(${Snappy_SOURCE_DIR}/snappy-stubs-public.h.in
snappy-stubs-public.h)
IF (WIN32)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
ENDIF (WIN32)
# Define the main library.
ADD_LIBRARY(snappy SHARED
snappy-c.cc
snappy-c.h
snappy-sinksource.cc
snappy-sinksource.h
snappy-stubs-internal.cc
snappy-stubs-public.h
snappy.cc
snappy.h)
TARGET_COMPILE_DEFINITIONS(snappy PRIVATE -DHAVE_CONFIG_H)
SET_TARGET_PROPERTIES(snappy PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
INSTALL(FILES snappy.h
snappy-c.h
snappy-sinksource.h
${Snappy_BINARY_DIR}/snappy-stubs-public.h
DESTINATION include)
INSTALL(TARGETS snappy
EXPORT SnappyTargets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
INSTALL(EXPORT SnappyTargets NAMESPACE Snappy:: DESTINATION lib/cmake/Snappy)
SET_TARGET_PROPERTIES(snappy PROPERTIES VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR})
SET(INCLUDE_INSTALL_DIR include)
SET(LIBRARY_INSTALL_DIR lib)
SET(BINARY_INSTALL_DIR bin)
CONFIGURE_PACKAGE_CONFIG_FILE(cmake/SnappyConfig.cmake.in
${Snappy_BINARY_DIR}/SnappyConfig.cmake
INSTALL_DESTINATION lib/Snappy/cmake
PATH_VARS INCLUDE_INSTALL_DIR LIBRARY_INSTALL_DIR BINARY_INSTALL_DIR
)
WRITE_BASIC_PACKAGE_VERSION_FILE(${Snappy_BINARY_DIR}/SnappyConfigVersion.cmake
COMPATIBILITY SameMajorVersion)
INSTALL(FILES ${Snappy_BINARY_DIR}/SnappyConfig.cmake
${Snappy_BINARY_DIR}/SnappyConfigVersion.cmake
DESTINATION lib/cmake)
ENABLE_TESTING()
IF (HAVE_LIBZ)
LIST(APPEND COMPRESSION_LIBS z)
ENDIF (HAVE_LIBZ)
IF (HAVE_LIBLZO2)
LIST(APPEND COMPRESSION_LIBS lzo2)
ENDIF (HAVE_LIBLZO2)
ADD_EXECUTABLE(snappy-unittest snappy_unittest.cc snappy-test.cc)
TARGET_COMPILE_DEFINITIONS(snappy-unittest PRIVATE -DHAVE_CONFIG_H)
TARGET_LINK_LIBRARIES(snappy-unittest snappy ${COMPRESSION_LIBS}
${GFLAGS_LIBRARIES})
TARGET_INCLUDE_DIRECTORIES(snappy-unittest BEFORE PRIVATE ${Snappy_SOURCE_DIR}
${GTEST_INCLUDE_DIRS} ${GFLAGS_INCLUDE_DIRS})
ADD_TEST(NAME snappy-unittest
WORKING_DIRECTORY ${Snappy_SOURCE_DIR}
COMMAND ${Snappy_BINARY_DIR}/snappy-unittest)