xref: /3.0.3-GA/platform/CMakeLists.txt (revision 75a175c5)
1CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
2INCLUDE(CheckIncludeFileCXX)
3
4CHECK_INCLUDE_FILE_CXX("chrono" HAVE_CHRONO)
5CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/src/config.cmake.h
6                ${CMAKE_CURRENT_BINARY_DIR}/src/config.h)
7
8#
9# Set the include path
10#
11INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/include)
12
13IF (WIN32)
14   INCLUDE_DIRECTORIES(AFTER ${CMAKE_CURRENT_SOURCE_DIR}/include/win32)
15
16   SET(PLATFORM_FILES src/getopt.c
17                      src/sockets.c
18                      src/cb_win32.c
19                      src/winrandom.c)
20ELSE (WIN32)
21   SET(PLATFORM_FILES src/cb_pthreads.c src/urandom.c)
22   SET(THREAD_LIBS "pthread")
23   SET(DLOPENLIB "dl")
24
25IF (NOT APPLE)
26   SET(RTLIB "rt")
27ENDIF(NOT APPLE)
28
29ENDIF (WIN32)
30
31IF(HAVE_CHRONO)
32   SET(PLATFORM_FILES ${PLATFORM_FILES} src/cxxtime.cc)
33ELSE(HAVE_CHRONO)
34   SET(PLATFORM_FILES ${PLATFORM_FILES} src/gethrtime.c)
35ENDIF(HAVE_CHRONO)
36
37#
38# Add all of the libraries
39#
40ADD_LIBRARY(platform SHARED ${PLATFORM_FILES} src/random.cc src/byteorder.c)
41TARGET_LINK_LIBRARIES(platform ${THREAD_LIBS} ${COUCHBASE_NETWORK_LIBS} ${DLOPENLIB} ${RTLIB})
42SET_TARGET_PROPERTIES(platform PROPERTIES SOVERSION 0.1.0)
43SET_TARGET_PROPERTIES(platform PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib)
44
45ADD_LIBRARY(dirutils SHARED src/dirutils.cc)
46SET_TARGET_PROPERTIES(dirutils PROPERTIES SOVERSION 0.1.0)
47SET_TARGET_PROPERTIES(dirutils PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib)
48
49ADD_EXECUTABLE(platform-dirutils-test tests/dirutils_test.cc)
50TARGET_LINK_LIBRARIES(platform-dirutils-test dirutils)
51
52ADD_EXECUTABLE(platform-gettimeofday-test tests/gettimeofday_test.cc)
53TARGET_LINK_LIBRARIES(platform-gettimeofday-test platform)
54
55IF (INSTALL_HEADER_FILES)
56INSTALL (FILES
57         include/platform/dirutils.h
58         include/platform/platform.h
59         include/platform/visibility.h
60         DESTINATION include/platform)
61
62IF (WIN32)
63INSTALL (FILES
64         include/win32/getopt.h
65	 include/win32/strings.h
66	 include/win32/unistd.h
67         DESTINATION include)
68ENDIF (WIN32)
69ENDIF (INSTALL_HEADER_FILES)
70
71INSTALL(TARGETS platform dirutils
72        RUNTIME DESTINATION bin
73        LIBRARY DESTINATION lib
74        ARCHIVE DESTINATION lib)
75
76ADD_CUSTOM_TARGET(reformat-platform-source
77                  COMMAND astyle ${ASTYLE_CFLAGS}
78                  VERBATIM)
79
80ADD_EXECUTABLE(platform-gethrtime-test tests/gethrtime_test.c)
81TARGET_LINK_LIBRARIES(platform-gethrtime-test platform)
82
83ADD_EXECUTABLE(platform-getopt-test tests/getopt_test.cc)
84TARGET_LINK_LIBRARIES(platform-getopt-test platform)
85
86ADD_EXECUTABLE(platform-random-test tests/random_test.cc)
87TARGET_LINK_LIBRARIES(platform-random-test platform)
88
89
90ADD_TEST(platform-dirutils-test platform-dirutils-test)
91ADD_TEST(platform-gettimeofday-test platform-gettimeofday-test)
92ADD_TEST(platform-gethrtime-test platform-gethrtime-test)
93ADD_TEST(platform-getopt-test-0 platform-getopt-test 0)
94ADD_TEST(platform-getopt-test-1 platform-getopt-test 1)
95ADD_TEST(platform-getopt-test-2 platform-getopt-test 2)
96ADD_TEST(platform-random-test platform-random-test)
97