kusano 7d535a
PROJECT(LZ4 C)
kusano 7d535a
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LZ4 compression library")
kusano 7d535a
set(CPACK_PACKAGE_VERSION_MAJOR 1)
kusano 7d535a
set(CPACK_PACKAGE_VERSION_MINOR 5)
kusano 7d535a
set(CPACK_PACKAGE_VERSION_PATCH r128)
kusano 7d535a
set(VERSION_STRING	" \"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}\" ")
kusano 7d535a
include(CPack)
kusano 7d535a
kusano 7d535a
cmake_minimum_required (VERSION 2.6)
kusano 7d535a
INCLUDE (CheckTypeSize)
kusano 7d535a
check_type_size("void *" SIZEOF_VOID_P)
kusano 7d535a
IF( ${SIZEOF_VOID_P} STREQUAL  "8" )
kusano 7d535a
    set (CMAKE_SYSTEM_PROCESSOR "64bit")
kusano 7d535a
    MESSAGE( STATUS "64 bit architecture detected size of void * is " ${SIZEOF_VOID_P})
kusano 7d535a
ENDIF()
kusano 7d535a
kusano 7d535a
option(BUILD_TOOLS "Build the command line tools" ON)
kusano 7d535a
option(BUILD_LIBS  "Build the libraries in addition to the tools" ON)
kusano 7d535a
kusano 7d535a
IF("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR
kusano 7d535a
   "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
kusano 7d535a
  SET(GNU_COMPATIBLE_COMPILER 1)
kusano 7d535a
ENDIF()
kusano 7d535a
kusano 7d535a
if(GNU_COMPATIBLE_COMPILER)
kusano 7d535a
if(UNIX AND BUILD_LIBS)
kusano 7d535a
    add_definitions(-fPIC)
kusano 7d535a
endif()
kusano 7d535a
endif()
kusano 7d535a
kusano 7d535a
set(LZ4_DIR ../lib/)
kusano 7d535a
set(PRG_DIR ../programs/)
kusano 7d535a
set(LZ4_SRCS_LIB ${LZ4_DIR}lz4.c ${LZ4_DIR}lz4hc.c ${LZ4_DIR}lz4.h ${LZ4_DIR}lz4hc.h ${LZ4_DIR}lz4frame.c ${LZ4_DIR}lz4frame.h ${LZ4_DIR}xxhash.c)
kusano 7d535a
set(LZ4_SRCS ${LZ4_DIR}lz4frame.c ${LZ4_DIR}xxhash.c ${PRG_DIR}bench.c ${PRG_DIR}lz4cli.c ${PRG_DIR}lz4io.c)
kusano 7d535a
kusano 7d535a
if(BUILD_TOOLS AND NOT BUILD_LIBS)
kusano 7d535a
    set(LZ4_SRCS ${LZ4_SRCS} ${LZ4_SRCS_LIB})
kusano 7d535a
endif()
kusano 7d535a
kusano 7d535a
if(BUILD_TOOLS)
kusano 7d535a
    add_executable(lz4 ${LZ4_SRCS})
kusano 7d535a
    install(TARGETS lz4 RUNTIME DESTINATION "bin/")
kusano 7d535a
endif()
kusano 7d535a
kusano 7d535a
if(BUILD_LIBS)    
kusano 7d535a
    add_library(liblz4 ${LZ4_SRCS_LIB})
kusano 7d535a
    
kusano 7d535a
    set_target_properties(liblz4 PROPERTIES
kusano 7d535a
    OUTPUT_NAME lz4
kusano 7d535a
    SOVERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}"
kusano 7d535a
    )
kusano 7d535a
        
kusano 7d535a
    install(TARGETS liblz4
kusano 7d535a
    LIBRARY DESTINATION lib
kusano 7d535a
    ARCHIVE DESTINATION lib
kusano 7d535a
    )
kusano 7d535a
kusano 7d535a
    install(FILES
kusano 7d535a
    ${LZ4_DIR}/lz4.h
kusano 7d535a
    ${LZ4_DIR}/lz4hc.h
kusano 7d535a
    ${LZ4_DIR}/lz4frame.h
kusano 7d535a
    DESTINATION include
kusano 7d535a
    )
kusano 7d535a
    
kusano 7d535a
    if(BUILD_TOOLS)
kusano 7d535a
        target_link_libraries(lz4 liblz4)
kusano 7d535a
    endif()
kusano 7d535a
endif()
kusano 7d535a
kusano 7d535a
kusano 7d535a
#warnings
kusano 7d535a
kusano 7d535a
if(MSVC)
kusano 7d535a
ADD_DEFINITIONS("-W4")
kusano 7d535a
endif()
kusano 7d535a
if(GNU_COMPATIBLE_COMPILER)
kusano 7d535a
ADD_DEFINITIONS("-Wall")
kusano 7d535a
endif()
kusano 7d535a
if(CMAKE_COMPILER_IS_GNUCXX)
kusano 7d535a
ADD_DEFINITIONS("-Wextra")
kusano 7d535a
ADD_DEFINITIONS("-Wundef")
kusano 7d535a
ADD_DEFINITIONS("-Wshadow")
kusano 7d535a
ADD_DEFINITIONS("-Wcast-align")
kusano 7d535a
ADD_DEFINITIONS("-Wstrict-prototypes")
kusano 7d535a
endif(CMAKE_COMPILER_IS_GNUCXX)
kusano 7d535a
if(GNU_COMPATIBLE_COMPILER AND
kusano 7d535a
   (NOT CMAKE_SYSTEM_NAME MATCHES "SunOS"))
kusano 7d535a
ADD_DEFINITIONS("-std=c99")
kusano 7d535a
endif()
kusano 7d535a
ADD_DEFINITIONS("-DLZ4_VERSION=\"${CPACK_PACKAGE_VERSION_PATCH}\"")
kusano 7d535a
INCLUDE_DIRECTORIES (${LZ4_DIR})
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a