Provide a CMakeLists.txt.

This lands https://github.com/google/snappy/pull/29
This commit is contained in:
vrabaud 2017-04-26 04:24:58 -07:00 committed by Victor Costan
parent ed3b7b242b
commit c8131680d0
5 changed files with 295 additions and 11 deletions

View File

@ -1,12 +1,16 @@
language: cpp language: generic
compiler: matrix:
- clang include:
- gcc - os: linux
os: dist: trusty # For Docker.
- linux sudo: required # For Docker.
sudo: false script:
- echo "Testing branch $TRAVIS_BRANCH of $REPOSITORY_NAME"
- docker run --rm -i -v $CI_SOURCE_PATH:$CI_SOURCE_PATH -e "CI_SOURCE_PATH=$CI_SOURCE_PATH" -e "HOME=$HOME" -t ubuntu:xenial sh -c "cd $CI_SOURCE_PATH; apt-get -qq update && apt-get -qq install build-essential cmake libgtest-dev; mkdir build && cd build && cmake ../ && make all && make test"
- os: osx
script:
- echo "Testing branch $TRAVIS_BRANCH of $REPOSITORY_NAME"
- mkdir build && cd build && cmake ../ && make all && make test
before_install: before_install:
- echo $LANG - export CI_SOURCE_PATH=$(pwd)
- echo $LC_ALL - export REPOSITORY_NAME=${PWD##*/}
script:
- ./autogen.sh && ./configure && make -j 4 check

162
CMakeLists.txt Normal file
View File

@ -0,0 +1,162 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.4)
PROJECT(Snappy VERSION 1.1.4 LANGUAGES C CXX)
SET(CMAKE_INCLUDE_CURRENT_DIR ON)
INCLUDE(CheckIncludeFiles)
INCLUDE(CheckLibraryExists)
INCLUDE(CheckCXXSourceCompiles)
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("dlfcn.h" HAVE_DLFCN_H)
CHECK_INCLUDE_FILES("inttypes.h" HAVE_INTTYPES_H)
CHECK_INCLUDE_FILES("memory.h" HAVE_MEMORY_H)
CHECK_INCLUDE_FILES("stddef.h" HAVE_STDDEF_H)
CHECK_INCLUDE_FILES("stdint.h" HAVE_STDINT_H)
CHECK_INCLUDE_FILES("stdlib.h" HAVE_STDLIB_H)
CHECK_INCLUDE_FILES("strings.h" HAVE_STRINGS_H)
CHECK_INCLUDE_FILES("string.h" HAVE_STRING_H)
CHECK_INCLUDE_FILES("sys/byteswap.h" HAVE_SYS_BYTESWAP_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/stat.h" HAVE_SYS_STAT_H)
CHECK_INCLUDE_FILES("sys/time.h" HAVE_SYS_TIME_H)
CHECK_INCLUDE_FILES("sys/types.h" HAVE_SYS_TYPES_H)
CHECK_INCLUDE_FILES("sys/uio.h" HAVE_SYS_UIO_H)
CHECK_INCLUDE_FILES("unistd.h" HAVE_UNISTD_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_LIBRARY_EXISTS(lzf lzf_compress "" HAVE_LIBLZF)
CHECK_LIBRARY_EXISTS(fastlz fastlz_compress "" HAVE_LIBFASTLZ)
CHECK_LIBRARY_EXISTS(quicklz qlz_compress "" HAVE_LIBQUICKLZ)
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 SOVERSION ${PROJECT_VERSION})
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)
IF (HAVE_LIBLZF)
LIST(APPEND COMPRESSION_LIBS lzf)
ENDIF (HAVE_LIBLZF)
IF (HAVE_LIBFASTLZ)
LIST(APPEND COMPRESSION_LIBS fastlz)
ENDIF (HAVE_LIBFASTLZ)
IF (HAVE_LIBQUICKLZ)
LIST(APPEND COMPRESSION_LIBS quicklz)
ENDIF (HAVE_LIBQUICKLZ)
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)

View File

@ -62,6 +62,16 @@ Performance optimizations, whether for 64-bit x86 or other platforms,
are of course most welcome; see "Contact", below. are of course most welcome; see "Contact", below.
Building
========
CMake is supported and autotools will soon be deprecated.
You need CMake 3.4 or above to build:
mkdir build
cd build && cmake ../ && make
Usage Usage
===== =====

View File

@ -0,0 +1,9 @@
set(SNAPPY_VERSION @SNAPPY_MAJOR@.@SNAPPY_MINOR@.@SNAPPY_PATCHLEVEL@)
@PACKAGE_INIT@
set_and_check(SNAPPY_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
set_and_check(SNAPPY_LIBRARY_DIR "@PACKAGE_LIBRARY_INSTALL_DIR@")
set_and_check(SNAPPY_BINARY_DIR "@PACKAGE_BINARY_INSTALL_DIR@")
check_required_components(SNAPPY)

99
cmake/config.h.in Normal file
View File

@ -0,0 +1,99 @@
#ifndef SNAPPY_CONFIG_H
#define SNAPPY_CONFIG_H 1
/* Define to 1 if the compiler supports __builtin_ctz and friends. */
#cmakedefine HAVE_BUILTIN_CTZ ${HAVE_BUILTIN_CTZ}
/* Define to 1 if the compiler supports __builtin_expect. */
#cmakedefine HAVE_BUILTIN_EXPECT ${HAVE_BUILTIN_EXPECT}
/* Define to 1 if you have the <byteswap.h> header file. */
#cmakedefine HAVE_BYTESWAP_H ${HAVE_BYTESWAP_H}
/* Define to 1 if you have the <dlfcn.h> header file. */
#cmakedefine HAVE_DLFCN_H ${HAVE_DLFCN_H}
/* Use the gflags package for command-line parsing. */
#cmakedefine HAVE_GFLAGS ${HAVE_GFLAGS}
/* Defined when Google Test is available. */
#cmakedefine HAVE_GTEST ${HAVE_GTEST}
/* Define to 1 if you have the <inttypes.h> header file. */
#cmakedefine HAVE_INTTYPES_H ${HAVE_INTTYPES_H}
/* Define to 1 if you have the `fastlz' library (-lfastlz). */
#cmakedefine HAVE_LIBFASTLZ ${HAVE_LIBFASTLZ}
/* Define to 1 if you have the `lzf' library (-llzf). */
#cmakedefine HAVE_LIBLZF ${HAVE_LIBLZF}
/* Define to 1 if you have the `lzo2' library (-llzo2). */
#cmakedefine HAVE_LIBLZO2 ${HAVE_LIBLZO2}
/* Define to 1 if you have the `quicklz' library (-lquicklz). */
#cmakedefine HAVE_LIBQUICKLZ ${HAVE_LIBQUICKLZ}
/* Define to 1 if you have the `z' library (-lz). */
#cmakedefine HAVE_LIBZ ${HAVE_LIBZ}
/* Define to 1 if you have the <sys/uio.h> header file. */
#cmakedefine HAVE_SYS_UIO_H ${HAVE_SYS_UIO_H}
/* Define to 1 if you have the <memory.h> header file. */
#cmakedefine HAVE_MEMORY_H ${HAVE_MEMORY_H}
/* Define to 1 if you have the <stddef.h> header file. */
#cmakedefine HAVE_STDDEF_H ${HAVE_STDDEF_H}
/* Define to 1 if you have the <stdint.h> header file. */
#cmakedefine HAVE_STDINT_H ${HAVE_STDINT_H}
/* Define to 1 if you have the <stdlib.h> header file. */
#cmakedefine HAVE_STDLIB_H ${HAVE_STDLIB_H}
/* Define to 1 if you have the <strings.h> header file. */
#cmakedefine HAVE_STRINGS_H ${HAVE_STRINGS_H}
/* Define to 1 if you have the <string.h> header file. */
#cmakedefine HAVE_STRING_H ${HAVE_STRING_H}
/* Define to 1 if you have the <sys/byteswap.h> header file. */
#cmakedefine HAVE_SYS_BYTESWAP_H ${HAVE_SYS_BYTESWAP_H}
/* Define to 1 if you have the <sys/endian.h> header file. */
#cmakedefine HAVE_SYS_ENDIAN_H ${HAVE_SYS_ENDIAN_H}
/* Define to 1 if you have the <sys/mman.h> header file. */
#cmakedefine HAVE_SYS_MMAN_H ${HAVE_SYS_MMAN_H}
/* Define to 1 if you have the <sys/resource.h> header file. */
#cmakedefine HAVE_SYS_RESOURCE_H ${HAVE_SYS_RESOURCE_H}
/* Define to 1 if you have the <sys/stat.h> header file. */
#cmakedefine HAVE_SYS_STAT_H ${HAVE_SYS_STAT_H}
/* Define to 1 if you have the <sys/time.h> header file. */
#cmakedefine HAVE_SYS_TIME_H ${HAVE_SYS_TIME_H}
/* Define to 1 if you have the <sys/types.h> header file. */
#cmakedefine HAVE_SYS_TYPES_H ${HAVE_SYS_TYPES}
/* Define to 1 if you have the <unistd.h> header file. */
#cmakedefine HAVE_UNISTD_H ${HAVE_UNISTD_H}
/* Define to 1 if you have the <windows.h> header file. */
#cmakedefine HAVE_WINDOWS_H ${HAVE_WINDOWS_H}
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
significant byte first (like Motorola and SPARC, unlike Intel and VAX). */
#cmakedefine WORDS_BIGENDIAN
#if defined(_MSC_VER) && (_MSC_VER <= 1900)
typedef __int64 ssize_t;
#endif
#endif