-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
107 lines (86 loc) · 2.91 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#inspurcloud cpp SDK
cmake_minimum_required(VERSION 3.0)
cmake_policy(SET CMP0048 NEW)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
#Project setting
project(inspurcloud-oss-cpp-sdk)
set(SDK_ROOT "${CMAKE_CURRENT_SOURCE_DIR}")
set(TARGET_OUTPUT_NAME_PREFIX "inspurcloud-oss-" CACHE STRING "The target's output name prefix")
#Options
option(BUILD_SHARED_LIBS "Enable shared library" OFF)
option(BUILD_DEMO "Build demo" ON)
option(ENABLE_COVERAGE "Flag to enable/disable building code with -fprofile-arcs and -ftest-coverage. Gcc only" OFF)
#Platform
if (CMAKE_CROSSCOMPILING)
message(FATAL_ERROR "Do not support target platform")
else()
if(CMAKE_HOST_UNIX)
set(PLATFORM_LINUX 1)
set(TARGET_OS "LINUX")
elseif(CMAKE_HOST_WIN32)
set(PLATFORM_WINDOWS 1)
set(TARGET_OS "WINDOWS")
else()
message(FATAL_ERROR "Do not support unknown host OS")
endif()
endif()
message(STATUS "TARGET_OS: ${TARGET_OS}")
add_definitions(-DPLATFORM_${TARGET_OS})
#Find dependency Library, curl, openssl
if (${TARGET_OS} STREQUAL "WINDOWS")
set(WLIB_TARGET "Win32")
if (CMAKE_CL_64)
set(WLIB_TARGET "x64")
endif()
set(CRYPTO_LIBS
${CMAKE_SOURCE_DIR}/third_party/lib/${WLIB_TARGET}/ssleay32.lib
${CMAKE_SOURCE_DIR}/third_party/lib/${WLIB_TARGET}/libeay32.lib)
set(CRYPTO_INCLUDE_DIRS
${CMAKE_SOURCE_DIR}/third_party/include)
set(CLIENT_LIBS
${CMAKE_SOURCE_DIR}/third_party/lib/${WLIB_TARGET}/libcurl.lib)
set(CLIENT_INCLUDE_DIRS
${CMAKE_SOURCE_DIR}/third_party/include)
else()
include(FindCURL)
include(FindOpenSSL)
if(NOT CURL_FOUND)
message(FATAL_ERROR "Could not find curl")
endif()
if(NOT OPENSSL_FOUND)
message(FATAL_ERROR "Could not find openssl")
endif()
set(CRYPTO_LIBS ${OPENSSL_LIBRARIES})
set(CRYPTO_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIRS})
set(CRYPTO_LIBS_ABSTRACT_NAME crypto ssl)
set(CLIENT_LIBS ${CURL_LIBRARIES})
set(CLIENT_INCLUDE_DIRS ${CURL_INCLUDE_DIRS})
set(CLIENT_LIBS_ABSTRACT_NAME curl)
endif()
#Compiler flags
list(APPEND SDK_COMPILER_FLAGS "-std=c++11")
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
list(APPEND SDK_COMPILER_FLAGS "/MP")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
list(APPEND SDK_COMPILER_FLAGS "-fno-exceptions" "-fPIC" "-fno-rtti")
list(APPEND SDK_COMPILER_FLAGS "-Wall" "-Werror" "-pedantic" "-Wextra")
else()
list(APPEND SDK_COMPILER_FLAGS "-fno-exceptions" "-fPIC" "-fno-rtti")
list(APPEND SDK_COMPILER_FLAGS "-Wall" "-Werror" "-pedantic" "-Wextra")
if (ENABLE_COVERAGE)
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
endif()
endif()
if (BUILD_SHARED_LIBS)
set(STATIC_LIB_SUFFIX "-static")
else()
set(STATIC_LIB_SUFFIX "")
endif()
include(ExternalProject)
include(GNUInstallDirs)
add_subdirectory(sdk)
if(BUILD_DEMO)
add_subdirectory(Demo)
endif()