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