removed trailing whitespaces
[umurmur.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8)
2
3 project(umurmurd C)
4
5 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
6 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH true)
7
8 option(USE_POLARSSL_TESTCERT "Link to the PolarSSL test certificate and key." OFF)
9 option(USE_POLARSSL_HAVEGE "Use the PolarSSL HAVEGE random generator key." OFF)
10
11 if(USE_POLARSSL_TESTCERT OR USE_POLARSSL_HAVEGE)
12   if(SSL MATCHES "openssl")
13     message(FATAL_ERROR "Selecting USE_POLARSSL_TESTCERT or USE_POLARSSL_HAVEGE implies SSL=polarssl")
14   endif(SSL MATCHES "openssl")
15 endif(USE_POLARSSL_TESTCERT OR USE_POLARSSL_HAVEGE)
16
17 find_package(Libconfig REQUIRED)
18 find_package(ProtobufC REQUIRED)
19 include(CheckFunctionExists)
20 include(CheckLibraryExists)
21
22 if(SSL MATCHES "openssl")
23   find_package(OpenSSL REQUIRED)
24   if(OPENSSL_FOUND)
25     set(SSLIMP_LIBRARIES ${OPENSSL_LIBRARIES})
26     set(SSLIMP_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR})
27     set(SSLIMP_LIBRARY_DIR ${OPENSSL_LIB_DIR})
28   endif(OPENSSL_FOUND)
29 else(SSL MATCHES "openssl")
30   find_package(PolarSSL REQUIRED)
31   if(POLARSSL_FOUND)
32     set(USE_POLARSSL ON)
33     set(SSLIMP_LIBRARIES ${POLARSSL_LIBRARIES})
34     set(SSLIMP_INCLUDE_DIR ${POLARSSL_INCLUDE_DIR})
35     set(SSLIMP_LIBRARY_DIR ${POLARSSL_LIB_DIR})
36   endif(POLARSSL_FOUND)
37 endif(SSL MATCHES "openssl")
38
39 check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
40
41 if(NOT HAVE_CLOCK_GETTIME)
42   check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME_RT)
43   if(NOT HAVE_CLOCK_GETTIME_RT)
44     check_library_exists(c clock_get_time "mach/time.h" HAVE_CLOCK_GET_TIME)
45     if(NOT HAVE_CLOCK_GET_TIME)
46       message(FATAL_ERROR "Didn't find clock_gettime() or clock_get_time!")
47     endif()
48   else()
49     set(LIBRT rt)
50   endif()
51 endif()
52
53 set(SOURCE "")
54 add_subdirectory(src)
55
56 configure_file(src/config.h.in ${CMAKE_SOURCE_DIR}/src/config.h)
57
58 include_directories(${LIBCONFIG_INCLUDE_DIR} ${PROTOBUFC_INCLUDE_DIR} ${SSLIMP_INCLUDE_DIR})
59 link_directories(${LIBCONFIG_LIB_DIR} ${PROTOBUFC_LIB_DIR} ${SSLIMP_LIB_DIR})
60
61 add_executable(umurmurd ${SOURCE})
62 install(TARGETS umurmurd RUNTIME DESTINATION "bin")
63
64 find_path(OLD_CONFIG_FILE NAMES "umurmur.conf" PATHS ${CMAKE_INSTALL_PREFIX} PATH_SUFFIXES "etc")
65 if(NOT OLD_CONFIG_FILE)
66   install(FILES "umurmur.conf.example" DESTINATION "etc" RENAME "umurmur.conf")
67 endif(NOT OLD_CONFIG_FILE)
68
69 add_definitions(${SSLIMP_CFLAGS})
70 target_link_libraries(umurmurd ${LIBCONFIG_LIBRARIES} ${PROTOBUFC_LIBRARIES} ${SSLIMP_LIBRARIES} ${LIBRT})