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