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