1PROJECT(LZ4 C)
2set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LZ4 compression library")
3set(CPACK_PACKAGE_VERSION_MAJOR 1)
4set(CPACK_PACKAGE_VERSION_MINOR 5)
5set(CPACK_PACKAGE_VERSION_PATCH r126)
6set(VERSION_STRING	" \"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}\" ")
7include(CPack)
8
9cmake_minimum_required (VERSION 2.6)
10INCLUDE (CheckTypeSize)
11check_type_size("void *" SIZEOF_VOID_P)
12IF( ${SIZEOF_VOID_P} STREQUAL  "8" )
13    set (CMAKE_SYSTEM_PROCESSOR "64bit")
14    MESSAGE( STATUS "64 bit architecture detected size of void * is " ${SIZEOF_VOID_P})
15ENDIF()
16
17option(BUILD_TOOLS "Build the command line tools" ON)
18option(BUILD_LIBS  "Build the libraries in addition to the tools" OFF)
19
20if(UNIX AND BUILD_LIBS)
21    if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
22        add_definitions(-fPIC)
23    endif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
24endif()
25
26set(LZ4_DIR ../lib/)
27set(PRG_DIR ../programs/)
28set(LZ4_SRCS_LIB ${LZ4_DIR}lz4.c ${LZ4_DIR}lz4hc.c ${LZ4_DIR}lz4.h ${LZ4_DIR}lz4hc.h)
29set(LZ4_SRCS ${LZ4_DIR}lz4frame.c ${LZ4_DIR}xxhash.c ${PRG_DIR}bench.c ${PRG_DIR}lz4cli.c ${PRG_DIR}lz4io.c)
30
31if(BUILD_TOOLS AND NOT BUILD_LIBS)
32    set(LZ4_SRCS ${LZ4_SRCS} ${LZ4_SRCS_LIB})
33endif()
34
35if(BUILD_TOOLS)
36    add_executable(lz4 ${LZ4_SRCS})
37    set_target_properties(lz4 PROPERTIES COMPILE_DEFINITIONS DISABLE_LZ4C_LEGACY_OPTIONS)
38    install(TARGETS lz4 RUNTIME DESTINATION "bin/")
39    add_executable(lz4c ${LZ4_SRCS})
40    install(TARGETS lz4c RUNTIME DESTINATION "bin/")
41endif()
42
43if(BUILD_LIBS)
44    add_library(liblz4 ${LZ4_SRCS_LIB})
45
46    set_target_properties(liblz4 PROPERTIES
47    OUTPUT_NAME lz4
48    SOVERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}"
49    )
50
51    install(TARGETS liblz4
52    LIBRARY DESTINATION lib
53    ARCHIVE DESTINATION lib
54    )
55
56    install(FILES
57    ${LZ4_DIR}/lz4.h
58    ${LZ4_DIR}/lz4hc.h
59    DESTINATION include
60    )
61
62    if(BUILD_TOOLS)
63        target_link_libraries(lz4 liblz4)
64        target_link_libraries(lz4c liblz4)
65    endif()
66endif()
67
68
69#warnings
70
71ADD_DEFINITIONS("-Wall")
72ADD_DEFINITIONS("-Wextra")
73ADD_DEFINITIONS("-Wundef")
74ADD_DEFINITIONS("-Wshadow")
75ADD_DEFINITIONS("-Wcast-align")
76ADD_DEFINITIONS("-Wstrict-prototypes")
77ADD_DEFINITIONS("-std=c99")
78ADD_DEFINITIONS("-DLZ4_VERSION=\"${CPACK_PACKAGE_VERSION_PATCH}\"")
79INCLUDE_DIRECTORIES (${LZ4_DIR})
80
81
82
83