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 src/cb_time.c 68 include/platform/platform.h 69 include/platform/random.h 70 include/platform/visibility.h) 71 72TARGET_LINK_LIBRARIES(platform ${THREAD_LIBS} ${COUCHBASE_NETWORK_LIBS} ${DLOPENLIB} ${RTLIB}) 73SET_TARGET_PROPERTIES(platform PROPERTIES SOVERSION 0.1.0) 74SET_TARGET_PROPERTIES(platform PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib) 75 76ADD_LIBRARY(dirutils SHARED src/dirutils.cc include/platform/dirutils.h) 77SET_TARGET_PROPERTIES(dirutils PROPERTIES SOVERSION 0.1.0) 78SET_TARGET_PROPERTIES(dirutils PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib) 79 80ADD_EXECUTABLE(platform-dirutils-test tests/dirutils_test.cc) 81TARGET_LINK_LIBRARIES(platform-dirutils-test dirutils) 82 83ADD_EXECUTABLE(platform-gettimeofday-test tests/gettimeofday_test.cc) 84TARGET_LINK_LIBRARIES(platform-gettimeofday-test platform) 85 86IF (INSTALL_HEADER_FILES) 87 INSTALL (FILES 88 include/platform/cbassert.h 89 include/platform/dirutils.h 90 include/platform/platform.h 91 include/platform/random.h 92 include/platform/visibility.h 93 include/platform/dirutils.h 94 DESTINATION include/platform) 95 96 INSTALL(FILES include/cJSON.h include/JSON_checker.h DESTINATION include) 97 98 IF (WIN32) 99 INSTALL(FILES 100 include/win32/getopt.h 101 include/win32/strings.h 102 include/win32/unistd.h 103 DESTINATION include) 104 ENDIF (WIN32) 105ENDIF (INSTALL_HEADER_FILES) 106 107INSTALL(TARGETS cJSON JSON_checker platform dirutils 108 RUNTIME DESTINATION bin 109 LIBRARY DESTINATION lib 110 ARCHIVE DESTINATION lib) 111 112ADD_CUSTOM_TARGET(reformat-platform-source 113 COMMAND astyle ${ASTYLE_CFLAGS} 114 VERBATIM) 115 116# 117# Test targets 118# 119ADD_EXECUTABLE(platform-gethrtime-test 120 tests/gethrtime_test.c 121 include/platform/platform.h) 122TARGET_LINK_LIBRARIES(platform-gethrtime-test platform) 123 124ADD_EXECUTABLE(platform-getopt-test tests/getopt_test.cc) 125TARGET_LINK_LIBRARIES(platform-getopt-test platform) 126 127ADD_EXECUTABLE(platform-random-test 128 tests/random_test.cc 129 include/platform/random.h) 130TARGET_LINK_LIBRARIES(platform-random-test platform) 131 132ADD_TEST(platform-dirutils-test platform-dirutils-test) 133ADD_TEST(platform-gettimeofday-test platform-gettimeofday-test) 134ADD_TEST(platform-gethrtime-test platform-gethrtime-test) 135ADD_TEST(platform-getopt-test-0 platform-getopt-test 0) 136ADD_TEST(platform-getopt-test-1 platform-getopt-test 1) 137ADD_TEST(platform-getopt-test-2 platform-getopt-test 2) 138ADD_TEST(platform-random-test platform-random-test) 139 140ADD_EXECUTABLE(platform-cjson-test include/cJSON.h tests/cjson_test.c) 141TARGET_LINK_LIBRARIES(platform-cjson-test cJSON) 142ADD_TEST(platform-cjson-test platform-cjson-test) 143 144ADD_EXECUTABLE(platform-cjson-parse-test 145 include/cJSON.h 146 tests/cjson_parse_test.c) 147TARGET_LINK_LIBRARIES(platform-cjson-parse-test cJSON platform) 148ADD_TEST(platform-cjson-parse-test 149 platform-cjson-parse-test -f ${PROJECT_SOURCE_DIR}/tests/testdata.json 150 -n 1) 151 152ADD_EXECUTABLE(platform-json-checker-test tests/json_checker_test.cc) 153TARGET_LINK_LIBRARIES(platform-json-checker-test JSON_checker) 154ADD_TEST(platform-json-checker-test platform-json-checker-test) 155