-
Notifications
You must be signed in to change notification settings - Fork 46
/
CMakeLists.txt
100 lines (85 loc) · 3.39 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
cmake_minimum_required(VERSION 2.8)
CMAKE_policy(SET CMP0015 NEW)
project(cos-cpp-sdk)
set(CMAKE_VERBOSE_MAKEFILE ON)
option(BUILD_UNITTEST "Build unittest" OFF)
option(BUILD_DEMO "Build demo" ON)
option(BUILD_SHARED_LIB "Build shared library" OFF)
option(ENABLE_COVERAGE "Enable Coverage" OFF)
if(APPLE)
set(OS_TYPE "APPLE")
elseif(UNIX)
set(OS_TYPE "LINUX")
elseif(WIN32)
set(OS_TYPE "WINDOWS")
else()
message(FATAL_ERROR "unkonwn os type")
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
set(OS_TYPE "Android")
message(STATUS "SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "iOS")
set(OS_TYPE "iOS")
message(STATUS "SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")
endif()
message(STATUS "OS type: ${OS_TYPE}")
set(POCO_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/third_party/include/)
set(POCO_LIBS PocoNetSSL PocoNet PocoCrypto PocoUtil PocoJSON PocoXML PocoFoundation)
if (${OS_TYPE} STREQUAL "WINDOWS")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(BUILD_TARGET "Win32")
if (CMAKE_CL_64)
set(BUILD_TARGET "x64")
endif()
message(STATUS "Build target: ${BUILD_TARGET}")
if (NOT DEFINED ${CMAKE_BUILD_TYPE})
set(CMAKE_BUILD_TYPE "Release")
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
set(POCO_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/${BUILD_TARGET}/poco)
set(SYSTEM_LIBS "")
#需要加该参数,不然VS会报错
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
elseif(${OS_TYPE} STREQUAL "iOS")
set(POCO_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}/poco/)
set(OPENSSL_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}/openssl/)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra")
set(SYSTEM_LIBS stdc++ pthread)
set(OPENSSL_LIBS ssl crypto)
elseif(${OS_TYPE} STREQUAL "Android")
set(POCO_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}/poco/)
set(OPENSSL_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}/openssl/)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra")
set(SYSTEM_LIBS stdc++)
set(OPENSSL_LIBS ssl crypto)
# Linux or MacOs
else()
if (${OS_TYPE} STREQUAL "APPLE")
set(POCO_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/macOS/poco/)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra")
else()
set(POCO_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/linux/poco/)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra")
endif()
set(SYSTEM_LIBS stdc++ pthread)
endif()
if(ENABLE_COVERAGE)
# coverage option
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
endif()
add_subdirectory(src)
if(BUILD_UNITTEST)
message(STATUS "Build unittest")
set(GTEST_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/third_party/include/gtest/)
set(GTEST_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/linux/gtest/)
if (${OS_TYPE} STREQUAL "WINDOWS")
set(GTEST_LINK_DIR ${CMAKE_SOURCE_DIR}/third_party/lib/${BUILD_TARGET}/gtest)
endif()
set(GTEST_LIBS gtest gtest_main)
set(UT_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/unittest/include/)
add_subdirectory(unittest)
endif()
if(BUILD_DEMO)
message(STATUS "Build demo")
add_subdirectory(demo)
endif()