xref: /3.0.3-GA/platform/CMakeLists.txt (revision 4aae569d)
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                           ${CMAKE_CURRENT_BINARY_DIR}/src)
13
14IF (WIN32)
15   INCLUDE_DIRECTORIES(AFTER ${CMAKE_CURRENT_SOURCE_DIR}/include/win32)
16   ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
17   SET(PLATFORM_FILES src/getopt.c
18                      src/sockets.c
19                      src/cb_win32.c
20                      src/winrandom.c
21                      include/win32/getopt.h
22                      include/win32/strings.h
23                      include/win32/unistd.h)
24ELSE (WIN32)
25   SET(PLATFORM_FILES src/cb_pthreads.c src/urandom.c)
26   SET(THREAD_LIBS "pthread")
27   SET(DLOPENLIB "dl")
28
29   IF (NOT APPLE)
30      SET(RTLIB "rt")
31   ENDIF(NOT APPLE)
32ENDIF (WIN32)
33
34IF (NOT DEFINED COUCHBASE_NETWORK_LIBS)
35   IF (WIN32)
36      SET(COUCHBASE_NETWORK_LIBS "Ws2_32")
37   ELSEIF ("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS")
38      SET(COUCHBASE_NETWORK_LIBS socket nsl)
39   ENDIF (WIN32)
40ENDIF (NOT DEFINED COUCHBASE_NETWORK_LIBS)
41
42IF(HAVE_CHRONO)
43   SET(PLATFORM_FILES ${PLATFORM_FILES} src/cxxtime.cc)
44ELSE(HAVE_CHRONO)
45   SET(PLATFORM_FILES ${PLATFORM_FILES} src/gethrtime.c)
46ENDIF(HAVE_CHRONO)
47
48#
49# Add all of the libraries
50#
51ADD_LIBRARY(platform SHARED ${PLATFORM_FILES}
52                            ${CMAKE_CURRENT_BINARY_DIR}/src/config.h
53                            src/random.cc
54                            src/byteorder.c
55                            include/platform/platform.h
56                            include/platform/random.h
57                            include/platform/visibility.h)
58
59TARGET_LINK_LIBRARIES(platform ${THREAD_LIBS} ${COUCHBASE_NETWORK_LIBS} ${DLOPENLIB} ${RTLIB})
60SET_TARGET_PROPERTIES(platform PROPERTIES SOVERSION 0.1.0)
61SET_TARGET_PROPERTIES(platform PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib)
62
63ADD_LIBRARY(dirutils SHARED src/dirutils.cc include/platform/dirutils.h)
64SET_TARGET_PROPERTIES(dirutils PROPERTIES SOVERSION 0.1.0)
65SET_TARGET_PROPERTIES(dirutils PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib)
66
67ADD_EXECUTABLE(platform-dirutils-test tests/dirutils_test.cc)
68TARGET_LINK_LIBRARIES(platform-dirutils-test dirutils)
69
70ADD_EXECUTABLE(platform-gettimeofday-test tests/gettimeofday_test.cc)
71TARGET_LINK_LIBRARIES(platform-gettimeofday-test platform)
72
73IF (INSTALL_HEADER_FILES)
74INSTALL (FILES
75         include/platform/dirutils.h
76         include/platform/platform.h
77         include/platform/random.h
78         include/platform/visibility.h
79         include/platform/dirutils.h
80         DESTINATION include/platform)
81
82IF (WIN32)
83INSTALL (FILES
84         include/win32/getopt.h
85         include/win32/strings.h
86         include/win32/unistd.h
87         DESTINATION include)
88ENDIF (WIN32)
89ENDIF (INSTALL_HEADER_FILES)
90
91INSTALL(TARGETS platform dirutils
92        RUNTIME DESTINATION bin
93        LIBRARY DESTINATION lib
94        ARCHIVE DESTINATION lib)
95
96ADD_CUSTOM_TARGET(reformat-platform-source
97                  COMMAND astyle ${ASTYLE_CFLAGS}
98                  VERBATIM)
99
100#
101# Test targets
102#
103ADD_EXECUTABLE(platform-gethrtime-test
104               tests/gethrtime_test.c
105               include/platform/platform.h)
106TARGET_LINK_LIBRARIES(platform-gethrtime-test platform)
107
108ADD_EXECUTABLE(platform-getopt-test tests/getopt_test.cc)
109TARGET_LINK_LIBRARIES(platform-getopt-test platform)
110
111ADD_EXECUTABLE(platform-random-test
112               tests/random_test.cc
113               include/platform/random.h)
114TARGET_LINK_LIBRARIES(platform-random-test platform)
115
116ADD_TEST(platform-dirutils-test platform-dirutils-test)
117ADD_TEST(platform-gettimeofday-test platform-gettimeofday-test)
118ADD_TEST(platform-gethrtime-test platform-gethrtime-test)
119ADD_TEST(platform-getopt-test-0 platform-getopt-test 0)
120ADD_TEST(platform-getopt-test-1 platform-getopt-test 1)
121ADD_TEST(platform-getopt-test-2 platform-getopt-test 2)
122ADD_TEST(platform-random-test platform-random-test)
123