-
Notifications
You must be signed in to change notification settings - Fork 28
/
CMakeLists.txt
236 lines (216 loc) · 10 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
cmake_minimum_required(VERSION 3.0)
cmake_policy(SET CMP0004 NEW)
project(huaweicloud-obs-c-sdk)
#***********************************************************************
#*
#* basic definitions
#*
#***********************************************************************
add_definitions(-D__LINUX_USR__)
add_definitions(-D__USE_GNU)
add_definitions(-D__POSIX_SOURCE)
add_definitions(-D_GNU_SOURCE)
add_definitions(-DV5R1C00)
add_definitions(-DMY_PID=196)
add_definitions(-D__DPAX_LINUX_USR__)
add_definitions(-D__DPAX_THREAD_NOPREEMPT__)
set(LIBOBS_VER_MAJOR "3.23")
set(LIBOBS_VER_MINOR "9")
if(NOT CMAKE_HOST_WIN32)
add_definitions(-DLIBOBS_VER_MAJOR="${LIBOBS_VER_MAJOR}")
add_definitions(-DLIBOBS_VER_MINOR="${LIBOBS_VER_MINOR}")
endif()
option(USE_CUSTOM "option for custom library path" OFF)
set(SECUREC_INC_DIR ${PROJECT_SOURCE_DIR}/platform/huaweisecurec/include)
set(CURL_VERSION curl-7.78.0)
set(OPENSSL_VERSION openssl-1.1.1k)
set(LIBXML2_VERSION libxml2-2.9.9)
set(PCRE_VERSION pcre-8.45)
set(ICONV_VERSION iconv-1.15)
set(CJSON_VERSION cjson-1.7.15)
execute_process(COMMAND uname -m OUTPUT_VARIABLE OARCH)
string(STRIP "${OARCH}" ARCH)
message(">>> ARCH ${ARCH}")
if (${ARCH} STREQUAL "aarch64")
set(ESDK_LOG_INC_DIR ${PROJECT_SOURCE_DIR}/platform/eSDK_LogAPI_V2.1.10)
set(ESDK_LOG_LIB_DIR ${PROJECT_SOURCE_DIR}/platform/eSDK_LogAPI_V2.1.10/C/aarch64)
set(LINKARCH "arm")
#execute_process(COMMAND make -f ${PROJECT_SOURCE_DIR}/platform/huaweisecurec/src/Makefile.aarch64)
elseif(${ARCH} STREQUAL "x86_64")
set(ESDK_LOG_INC_DIR ${PROJECT_SOURCE_DIR}/platform/eSDK_LogAPI_V2.1.10)
set(ESDK_LOG_LIB_DIR ${PROJECT_SOURCE_DIR}/platform/eSDK_LogAPI_V2.1.10/C/linux_64)
set(LINKARCH "linux")
#execute_process(COMMAND make -f ${PROJECT_SOURCE_DIR}/platform/huaweisecurec/src/Makefile)
endif()
if(NOT USE_CUSTOM)
set(CURL_INC_DIR ${PROJECT_SOURCE_DIR}/build/script/Provider/build/${LINKARCH}/${CURL_VERSION}/include)
set(CURL_LIB_DIR ${PROJECT_SOURCE_DIR}/build/script/Provider/build/${LINKARCH}/${CURL_VERSION}/lib)
set(OPENSSL_INC_DIR ${PROJECT_SOURCE_DIR}/build/script/Provider/build/${LINKARCH}/${OPENSSL_VERSION}/include)
set(OPENSSL_LIB_DIR ${PROJECT_SOURCE_DIR}/build/script/Provider/build/${LINKARCH}/${OPENSSL_VERSION}/lib)
set(LIBXML2_INC_DIR ${PROJECT_SOURCE_DIR}/build/script/Provider/build/${LINKARCH}/${LIBXML2_VERSION}/include)
set(LIBXML2_LIB_DIR ${PROJECT_SOURCE_DIR}/build/script/Provider/build/${LINKARCH}/${LIBXML2_VERSION}/lib)
set(PCRE_INC_DIR ${PROJECT_SOURCE_DIR}/build/script/Provider/build/${LINKARCH}/${PCRE_VERSION}/include/pcre)
set(PCRE_LIB_DIR ${PROJECT_SOURCE_DIR}/build/script/Provider/build/${LINKARCH}/${PCRE_VERSION}/lib)
set(ICONV_INC_DIR ${PROJECT_SOURCE_DIR}/build/script/Provider/build/${LINKARCH}/${ICONV_VERSION}/include)
set(ICONV_LIB_DIR ${PROJECT_SOURCE_DIR}/build/script/Provider/build/${LINKARCH}/${ICONV_VERSION}/lib)
set(CJSON_INC_DIR ${PROJECT_SOURCE_DIR}/build/script/Provider/build/${LINKARCH}/${CJSON_VERSION}/include)
set(CJSON_LIB_DIR ${PROJECT_SOURCE_DIR}/build/script/Provider/build/${LINKARCH}/${CJSON_VERSION}/lib)
set(SPDLOG_INC_DIR ${PROJECT_SOURCE_DIR}/build/script/Provider/build/${LINKARCH}/${SPDLOG_VERSION}/include)
set(SPDLOG_LIB_DIR ${PROJECT_SOURCE_DIR}/build/script/Provider/build/${LINKARCH}/${SPDLOG_VERSION}/lib)
set(SECUREC_LIB_DIR ${PROJECT_SOURCE_DIR}/platform/huaweisecurec/lib/${LINKARCH})
else()
if(NOT DEFINED CURL_INC_DIR)
set(CURL_INC_DIR "/usr/include" CACHE STRING "")
endif()
if(NOT DEFINED CURL_LIB_DIR)
set(CURL_LIB_DIR "/usr/lib64" CACHE STRING "")
endif()
if(NOT DEFINED OPENSSL_INC_DIR)
set(OPENSSL_INC_DIR "/usr/include" CACHE STRING "")
endif()
if(NOT DEFINED OPENSSL_LIB_DIR)
set(OPENSSL_LIB_DIR "/usr/lib64" CACHE STRING "")
endif()
if(NOT DEFINED LIBXML2_INC_DIR)
set(LIBXML2_INC_DIR "/usr/include/libxml2" CACHE STRING "")
endif()
if(NOT DEFINED LIBXML2_LIB_DIR)
set(LIBXML2_LIB_DIR "/usr/lib64" CACHE STRING "")
endif()
if(NOT DEFINED PCRE_INC_DIR)
set(PCRE_INC_DIR "/usr/include" CACHE STRING "")
endif()
if(NOT DEFINED PCRE_LIB_DIR)
set(PCRE_LIB_DIR "/usr/lib64" CACHE STRING "")
endif()
if(NOT DEFINED ICONV_INC_DIR)
set(ICONV_INC_DIR "/usr/include" CACHE STRING "")
endif()
if(NOT DEFINED ICONV_LIB_DIR)
set(ICONV_LIB_DIR "/usr/lib64" CACHE STRING "")
endif()
if(NOT DEFINED CJSON_INC_DIR)
set(ICONV_LIB_DIR "/usr/lib64" CACHE STRING "")
endif()
if(NOT DEFINED CJSON_LIB_DIR)
set(ICONV_LIB_DIR "/usr/lib64" CACHE STRING "")
endif()
if(NOT DEFINED SPDLOG_INC_DIR)
set(SPDLOG_INC_DIR "/usr/lib64" CACHE STRING "")
endif()
if(NOT DEFINED SPDLOG_LIB_DIR)
set(SPDLOG_LIB_DIR "/usr/lib64" CACHE STRING "")
endif()
endif()
message(STATUS "CURL_INC_DIR: ${CURL_INC_DIR}")
message(STATUS "CURL_LIB_DIR: ${CURL_LIB_DIR}")
message(STATUS "OPENSSL_INC_DIR: ${OPENSSL_INC_DIR}")
message(STATUS "OPENSSL_LIB_DIR: ${OPENSSL_LIB_DIR}")
message(STATUS "LIBXML2_INC_DIR: ${LIBXML2_INC_DIR}")
message(STATUS "LIBXML2_LIB_DIR: ${LIBXML2_LIB_DIR}")
message(STATUS "PCRE_INC_DIR: ${PCRE_INC_DIR}")
message(STATUS "PCRE_LIB_DIR: ${PCRE_LIB_DIR}")
message(STATUS "ICONV_INC_DIR: ${ICONV_INC_DIR}")
message(STATUS "ICONV_LIB_DIR: ${ICONV_LIB_DIR}")
message(STATUS "CJSON_INC_DIR: ${CJSON_INC_DIR}")
message(STATUS "CJSON_LIB_DIR: ${CJSON_LIB_DIR}")
message(STATUS "SPDLOG_INC_DIR: ${SPDLOG_INC_DIR}")
message(STATUS "SPDLOG_LIB_DIR: ${SPDLOG_LIB_DIR}")
#***********************************************************************
#*
#* compile mode
#*
#***********************************************************************
SET(ESDK_BASE_FLAGS "-g -Wall -fPIC -fno-strict-overflow -shared")
SET(ESDK_SP_C_FLAGS "-std=gnu99")
SET(ESDK_SP_C++_FLAGS "-std=c++11")
SET(ESDK_SP_RELEASE_FLAGS "-O2 -s")
SET(ESDK_SP_DEBUG_FLAGS "-O0 -coverage")
if(NOT CMAKE_HOST_WIN32)
SET(SEC_REQ_FLAGS "-fstack-protector-strong -fPIE -pie -Wl,-z,relro,-z,now,-z,noexecstack")
SET(SEC_SUG_BASE_FLAGS "-Wformat=2")
SET(SEC_SUG_SP_C_FLAGS "-Wshadow -Wstack-protector")
endif()
SET(ESDK_C_FLAGS "${ESDK_BASE_FLAGS} ${ESDK_SP_C_FLAGS}")
SET(ESDK_C++_FLAGS "${ESDK_BASE_FLAGS} ${ESDK_SP_C++_FLAGS}")
SET(SEC_C_FLAGS "${SEC_REQ_FLAGS} ${SEC_SUG_BASE_FLAGS} ${SEC_SUG_SP_C_FLAGS}")
SET(SEC_C++_FLAGS "${SEC_REQ_FLAGS} ${SEC_SUG_BASE_FLAGS}")
SET(CMAKE_SKIP_RPATH TRUE)
if(CMAKE_BUILD_TYPE MATCHES "Release")
message(">>> Release Mode")
set(CMAKE_C_FLAGS "${ESDK_C_FLAGS} ${ESDK_SP_RELEASE_FLAGS} ${SEC_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${ESDK_C++_FLAGS} ${ESDK_SP_RELEASE_FLAGS} ${SEC_C++_FLAGS}")
else()
message(">>> Debug Mode")
set(CMAKE_C_FLAGS "${ESDK_C_FLAGS} ${ESDK_SP_DEBUG_FLAGS} ${SEC_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${ESDK_C++_FLAGS} ${ESDK_SP_DEBUG_FLAGS} ${SEC_C++_FLAGS}")
set(COVERAGE_LINK "gcov")
add_definitions(-D_DEBUG)
endif()
message(STATUS ">>> Source Dir: " ${PROJECT_SOURCE_DIR})
message(STATUS ">>> Binary Dir: " ${PROJECT_BINARY_DIR})
message(STATUS ">>> C_FLAGS : " ${CMAKE_C_FLAGS})
message(STATUS ">>> CXX_FLAGS : " ${CMAKE_CXX_FLAGS})
#***********************************************************************
#*
#* set dir of output binary and library
#*
#***********************************************************************
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
#***********************************************************************
#*
#* Link lib
#*
#***********************************************************************
include_directories(${CURL_INC_DIR})
include_directories(${OPENSSL_INC_DIR})
include_directories(${LIBXML2_INC_DIR})
include_directories(${PCRE_INC_DIR})
include_directories(${ICONV_INC_DIR})
include_directories(${CJSON_INC_DIR})
include_directories(${SECUREC_INC_DIR})
include_directories(${ESDK_LOG_INC_DIR})
include_directories(${SPDLOG_INC_DIR})
link_directories(${CURL_LIB_DIR})
link_directories(${OPENSSL_LIB_DIR})
link_directories(${LIBXML2_LIB_DIR})
link_directories(${PCRE_LIB_DIR})
link_directories(${ICONV_LIB_DIR})
link_directories(${CJSON_LIB_DIR})
link_directories(${SECUREC_LIB_DIR})
link_directories(${ESDK_LOG_LIB_DIR})
link_directories(${SPDLOG_LIB_DIR})
include_directories(${CMAKE_SOURCE_DIR}/source/eSDK_OBS_API/eSDK_OBS_API_C++/inc)
include_directories(${CMAKE_SOURCE_DIR}/source/eSDK_OBS_API/eSDK_OBS_API_C++/include)
aux_source_directory(${CMAKE_SOURCE_DIR}/source/eSDK_OBS_API/eSDK_OBS_API_C++/src SOURCE_DIR)
aux_source_directory(${CMAKE_SOURCE_DIR}/source/eSDK_OBS_API/eSDK_OBS_API_C++/src/bucket BUCKET_SOURCE_DIR)
aux_source_directory(${CMAKE_SOURCE_DIR}/source/eSDK_OBS_API/eSDK_OBS_API_C++/src/object OBJECT_SOURCE_DIR)
add_library(eSDKOBS SHARED ${SOURCE_DIR} ${BUCKET_SOURCE_DIR} ${OBJECT_SOURCE_DIR})
target_link_libraries(eSDKOBS curl ssl xml2 pcre iconv cjson securec eSDKLogAPI spdlog)
#***********************************************************************
#*
#* Unset Cache
#*
#***********************************************************************
unset(USE_CUSTOM CACHE)
unset(CURL_INC_DIR CACHE)
unset(CURL_LIB_DIR CACHE)
unset(OPENSSL_INC_DIR CACHE)
unset(OPENSSL_LIB_DIR CACHE)
unset(LIBXML2_INC_DIR CACHE)
unset(LIBXML2_LIB_DIR CACHE)
unset(PCRE_INC_DIR CACHE)
unset(PCRE_LIB_DIR CACHE)
unset(ICONV_INC_DIR CACHE)
unset(ICONV_LIB_DIR CACHE)
unset(CJSON_INC_DIR CACHE)
unset(CJSON_LIB_DIR CACHE)
unset(SPDLOG_INC_DIR CACHE)
unset(SPDLOG_LIB_DIR CACHE)
#***********************************************************************
#*
#* add source code dir
#*
#***********************************************************************
#add_subdirectory(src)