xref: /3.0.3-GA/platform/CMakeLists.txt (revision 4f9c608d)
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(MATH_LIBS "m")
23   SET(THREAD_LIBS "pthread")
24   SET(DLOPENLIB "dl")
25
26IF (NOT APPLE)
27   SET(RTLIB "rt")
28ENDIF(NOT APPLE)
29
30ENDIF (WIN32)
31
32IF(HAVE_CHRONO)
33   SET(PLATFORM_FILES ${PLATFORM_FILES} src/cxxtime.cc)
34ELSE(HAVE_CHRONO)
35   SET(PLATFORM_FILES ${PLATFORM_FILES} src/gethrtime.c)
36ENDIF(HAVE_CHRONO)
37
38#
39# Add all of the libraries
40#
41ADD_LIBRARY(platform SHARED ${PLATFORM_FILES} src/byteorder.c)
42TARGET_LINK_LIBRARIES(platform ${THREAD_LIBS} ${COUCHBASE_NETWORK_LIBS} ${DLOPENLIB} ${RTLIB})
43SET_TARGET_PROPERTIES(platform PROPERTIES SOVERSION 0.1.0)
44SET_TARGET_PROPERTIES(platform PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib)
45
46ADD_LIBRARY(dirutils SHARED src/dirutils.cc)
47SET_TARGET_PROPERTIES(dirutils PROPERTIES SOVERSION 0.1.0)
48SET_TARGET_PROPERTIES(dirutils PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib)
49
50ADD_EXECUTABLE(platform-dirutils-test tests/dirutils_test.cc)
51TARGET_LINK_LIBRARIES(platform-dirutils-test dirutils)
52
53ADD_EXECUTABLE(platform-gettimeofday-test tests/gettimeofday_test.cc)
54TARGET_LINK_LIBRARIES(platform-gettimeofday-test platform)
55
56IF (INSTALL_HEADER_FILES)
57INSTALL (FILES
58         include/platform/dirutils.h
59         include/platform/platform.h
60         include/platform/visibility.h
61         DESTINATION include/platform)
62
63IF (WIN32)
64INSTALL (FILES
65         include/win32/getopt.h
66	 include/win32/strings.h
67	 include/win32/unistd.h
68         DESTINATION include)
69ENDIF (WIN32)
70ENDIF (INSTALL_HEADER_FILES)
71
72INSTALL(TARGETS platform dirutils
73        RUNTIME DESTINATION bin
74        LIBRARY DESTINATION lib
75        ARCHIVE DESTINATION lib)
76
77ADD_CUSTOM_TARGET(reformat-platform-source
78                  COMMAND astyle ${ASTYLE_CFLAGS}
79                  VERBATIM)
80
81ADD_EXECUTABLE(platform-gethrtime-test tests/gethrtime_test.c)
82TARGET_LINK_LIBRARIES(platform-gethrtime-test platform)
83
84ADD_EXECUTABLE(platform-getopt-test tests/getopt_test.cc)
85TARGET_LINK_LIBRARIES(platform-getopt-test platform)
86
87ADD_EXECUTABLE(platform-random-test tests/random_test.c)
88TARGET_LINK_LIBRARIES(platform-random-test platform)
89
90
91ADD_TEST(platform-dirutils-test platform-dirutils-test)
92ADD_TEST(platform-gettimeofday-test platform-gettimeofday-test)
93ADD_TEST(platform-gethrtime-test platform-gethrtime-test)
94ADD_TEST(platform-getopt-test-0 platform-getopt-test 0)
95ADD_TEST(platform-getopt-test-1 platform-getopt-test 1)
96ADD_TEST(platform-getopt-test-2 platform-getopt-test 2)
97ADD_TEST(platform-random-test platform-random-test)
98