Merge branch 'master' of github.com:reverbrain/eblob
[eblob.git] / CMakeLists.txt
blobcbb6c1b8068a17761d3230d3e64da74b21d313c2
1 cmake_minimum_required (VERSION 2.6 FATAL_ERROR)
2 cmake_policy (VERSION 2.6.0)
4 set(CMAKE_SKIP_RPATH FALSE)
5 set(CMAKE_SKIP_BUILD_RPATH  FALSE)
7 project (eblob)
8 FILE (READ "${CMAKE_CURRENT_SOURCE_DIR}/debian/changelog" DEBCHANGELOG)
10 string(REGEX MATCH "([0-9]+\\.[0-9]+\\.[0-9]+)" DEBFULLVERSION "${DEBCHANGELOG}")
11 STRING (REGEX MATCH "([0-9]+\\.[0-9]+)" EBLOB_VERSION_ABI "${DEBFULLVERSION}")
12 STRING (REGEX MATCH "([0-9]+$)" EBLOB_VERSION_MINOR "${DEBFULLVERSION}")
14 set(EBLOB_VERSION "${EBLOB_VERSION_ABI}.${EBLOB_VERSION_MINOR}")
16 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
18 option(WITH_PYTHON "Build python bindings" ON)
19 option(WITH_EXAMPLES "Build examples" ON)
20 option(WITH_SNAPPY "Enable Snappy support" ON)
22 include(CheckAtomic)
23 include(TestBigEndian)
25 include_directories(${CMAKE_BINARY_DIR}/include/)
27 # Test endianess
28 test_big_endian(HAVE_BIG_ENDIAN)
29 if(HAVE_BIG_ENDIAN)
30     add_definitions(-DBYTEORDER=4321)
31     add_definitions(-DWORDS_BIGENDIAN=1)
32 else()
33     add_definitions(-DBYTEORDER=1234)
34 endif()
36 if (UNIX OR MINGW)
37     add_definitions(-W -Wall -Wextra -fstack-protector-all -fno-strict-aliasing)
38 endif()
39 if (${CMAKE_SYSTEM_NAME} MATCHES BSD)
40     add_definitions(-D__BSD_VISIBLE=1)
41 endif()
43 # Check for threads
44 if (UNIX AND BSD)
45     set(CMAKE_THREAD_LIBS -pthread)
46     set(CMAKE_USE_PTHREADS ON)
47     set(CMAKE_EXE_LINKER_FLAGS -pthread)
48 endif()
50 set(CMAKE_THREAD_PREFER_PTHREAD ON)
51 find_package(Threads REQUIRED)
52 include(CheckThreadSpinlock)
54 # Check for boost
55 #set(Boost_USE_STATIC_LIBS ON)
56 #set(Boost_USE_STLPORT ON)
57 find_package(Boost REQUIRED COMPONENTS iostreams thread system regex python)
58 message(STATUS "Boost information:")
59 message(STATUS "  Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
60 message(STATUS "  Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}")
61 message(STATUS "  Boost_LIBRARIES: ${Boost_LIBRARIES}")
62 include_directories(${Boost_INCLUDE_DIRS})
63 link_directories(${Boost_LIBRARY_DIRS})
65 # Check for snappy - unusual dependency, it doesn't use pkgconfig
66 if (WITH_SNAPPY)
67     find_package(SNAPPY REQUIRED)
68     include_directories(${SNAPPY_INCLUDE_DIR})
69     add_definitions(-DHAVE_SNAPPY_SUPPORT)
70 endif()
72 # Check for python
73 if(WITH_PYTHON)
74     find_package(PythonLibs REQUIRED)
75     message(STATUS "Python includes are situated in (${PYTHON_INCLUDE_PATH}, ${PYTHON_INCLUDE_DIRS})")
76     include_directories(${PYTHON_INCLUDE_PATH})
77     include_directories(${PYTHON_INCLUDE_DIRS})
78 endif()
81 # Collect all libraries together
82 set(EBLOB_LIBRARIES ${CMAKE_THREAD_LIBS_INIT} ${SNAPPY_LIBRARIES})
83 set(EBLOB_CPP_LIBRARIES ${CMAKE_THREAD_LIBS_INIT} ${Boost_IOSTREAMS_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_REGEX_LIBRARY})
84 set(EBLOB_PYTHON_LIBRARIES ${Boost_PYTHON_LIBRARY} ${PYTHON_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
86 # Build parts
87 add_subdirectory(library)
88 if (WITH_EXAMPLES)
89     add_subdirectory(example)
90 endif()
91 add_subdirectory(bindings)
93 install(FILES
94     include/eblob/eblob.hpp
95     include/eblob/blob.h
96     DESTINATION include/eblob/
97     )