Skip to content

Instantly share code, notes, and snippets.

@KindDragon
Created May 5, 2017 07:49
Show Gist options
  • Save KindDragon/b8752d22541a6d9d488e066b6a93a853 to your computer and use it in GitHub Desktop.
Save KindDragon/b8752d22541a6d9d488e066b6a93a853 to your computer and use it in GitHub Desktop.
# https://github.com/google/snappy/pull/29
CMAKE_MINIMUM_REQUIRED(VERSION 3.4)
PROJECT(snappy VERSION 1.1.4 LANGUAGES C CXX)
option(SNAPPY_BUILD_TESTS "Build snappy tests" OFF)
SET(CMAKE_INCLUDE_CURRENT_DIR ON)
INCLUDE(CheckIncludeFiles)
INCLUDE(CheckLibraryExists)
INCLUDE(CheckCXXSourceCompiles)
INCLUDE(CMakePackageConfigHelpers)
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_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)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/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(${CMAKE_CURRENT_SOURCE_DIR}/snappy-stubs-public.h.in
snappy-stubs-public.h)
IF (MSVC AND (CMAKE_SIZEOF_VOID_P EQUAL 8))
ADD_DEFINITIONS(-D__SSE2__)
ENDIF (MSVC AND (CMAKE_SIZEOF_VOID_P EQUAL 8))
IF (WIN32)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
ENDIF (WIN32)
# Define the main library.
ADD_LIBRARY(snappy
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
${CMAKE_CURRENT_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 share/snappy)
SET(INCLUDE_INSTALL_DIR include)
SET(LIBRARY_INSTALL_DIR lib)
SET(BINARY_INSTALL_DIR bin)
WRITE_BASIC_PACKAGE_VERSION_FILE(${CMAKE_CURRENT_BINARY_DIR}/SnappyConfigVersion.cmake
COMPATIBILITY SameMajorVersion)
CONFIGURE_PACKAGE_CONFIG_FILE(SnappyConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/SnappyConfig.cmake
INSTALL_DESTINATION share/snappy
PATH_VARS INCLUDE_INSTALL_DIR LIBRARY_INSTALL_DIR BINARY_INSTALL_DIR
)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/SnappyConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/SnappyConfigVersion.cmake
DESTINATION share/snappy)
if (SNAPPY_BUILD_TESTS)
FIND_PACKAGE(zlib QUIET)
if (NOT ZLIB_FOUND)
CHECK_LIBRARY_EXISTS(zlib zlibVersion "" HAVE_LIBZ)
ENDIF (NOT ZLIB_FOUND)
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)
FIND_PACKAGE(GTest REQUIRED)
SET(HAVE_GTEST 1)
FIND_PACKAGE(Gflags REQUIRED)
SET(HAVE_GFLAGS 1)
ENABLE_TESTING()
IF (ZLIB_FOUND)
set(HAVE_LIBZ 1)
LIST(APPEND COMPRESSION_LIBS ${ZLIB_LIBRARIES})
ELSE()
LIST(APPEND COMPRESSION_LIBS zlib)
ENDIF (ZLIB_FOUND)
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 ${CMAKE_CURRENT_SOURCE_DIR}
${GTEST_INCLUDE_DIRS} ${GFLAGS_INCLUDE_DIRS})
ADD_TEST(NAME snappy-unittest
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/snappy-unittest)
endif (SNAPPY_BUILD_TESTS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment