-
Notifications
You must be signed in to change notification settings - Fork 86
/
CMakeLists.txt
157 lines (130 loc) · 5.09 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
PROJECT(oss_c_sdk)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
set(CMAKE_VERSION 3.0.0)
# default C / CXX flags
if(CMAKE_HOST_WIN32)
else()
set(CMAKE_C_FLAGS " -g -ggdb -O0 -Wall -fpic -fPIC -D_LARGEFILE64_SOURCE")
set(CMAKE_CXX_FLAGS " -g -ggdb -O0 -Wall -fpic -fPIC -D_LARGEFILE64_SOURCE")
set(CMAKE_C_FLAGS_DEBUG " -g -ggdb -O0 -Wall -fpic -fPIC -D_LARGEFILE64_SOURCE")
set(CMAKE_CXX_FLAGS_DEBUG " -g -ggdb -O0 -Wall -fpic -fPIC -D_LARGEFILE64_SOURCE")
set(CMAKE_C_FLAGS_RELEASE " -O3 -Wall -fpic -fPIC -D_LARGEFILE64_SOURCE")
set(CMAKE_CXX_FLAGS_RELEASE " -O3 -Wall -fpic -fPIC -D_LARGEFILE64_SOURCE")
set(CMAKE_C_FLAGS_MINSIZEREF " -Os -Wall -fpic -fPIC -D_LARGEFILE64_SOURCE")
set(CMAKE_CXX_FLAGS_MINSIZEREF " -Os -Wall -fpic -fPIC -D_LARGEFILE64_SOURCE")
set(CMAKE_C_FLAGS_RELWITHDEBINFO " -O2 -Wall -fpic -fPIC -D_LARGEFILE64_SOURCE")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO " -O2 -Wall -fpic -fPIC -D_LARGEFILE64_SOURCE")
set(CMAKE_C_FLAGS_COVERAGE " ${CMAKE_C_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS_COVERAGE " ${CMAKE_C_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
endif()
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/build/${CMAKE_BUILD_TYPE}/lib)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/build/${CMAKE_BUILD_TYPE}/bin)
set(CMAKE_C_OUTPUT_EXTENSION_REPLACE 1)
set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1)
# find dependency librarys
if(CMAKE_HOST_WIN32)
set(EXTRA_INCLUDE_PATH ${CMAKE_SOURCE_DIR}/third_party/include)
if (CMAKE_CL_64)
set(EXTRA_LIB_PATH ${CMAKE_SOURCE_DIR}/third_party/lib/x64/)
else()
set(EXTRA_LIB_PATH ${CMAKE_SOURCE_DIR}/third_party/lib/Win32/)
endif()
find_path(APR_INCLUDE_DIR NAMES apr.h PATH_SUFFIXES apr PATHS ${EXTRA_INCLUDE_PATH})
find_library(APR_LIBRARY NAMES libapr-1 PATHS ${EXTRA_LIB_PATH})
find_path(APR_UTIL_INCLUDE_DIR NAMES apu.h PATH_SUFFIXES aprutil PATHS ${EXTRA_INCLUDE_PATH})
find_library(APR_UTIL_LIBRARY NAMES libaprutil-1 PATHS ${EXTRA_LIB_PATH})
find_path(MINIXML_INCLUDE_DIR NAMES mxml.h PATH_SUFFIXES mxml PATHS ${EXTRA_INCLUDE_PATH})
find_library(MINIXML_LIBRARY NAMES mxml1 PATHS ${EXTRA_LIB_PATH})
find_path(CURL_INCLUDE_DIR NAMES curl/curl.h PATHS ${EXTRA_INCLUDE_PATH})
find_library(CURL_LIBRARY NAMES libcurl PATHS ${EXTRA_LIB_PATH})
else()
FIND_PROGRAM(APR_CONFIG_BIN NAMES apr-config apr-1-config PATHS /usr/bin /usr/local/bin /usr/local/apr/bin/)
FIND_PROGRAM(APU_CONFIG_BIN NAMES apu-config apu-1-config PATHS /usr/bin /usr/local/bin /usr/local/apr/bin/)
IF (APR_CONFIG_BIN)
EXECUTE_PROCESS(
COMMAND ${APR_CONFIG_BIN} --includedir
OUTPUT_VARIABLE APR_INCLUDE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
EXECUTE_PROCESS(
COMMAND ${APR_CONFIG_BIN} --cflags
OUTPUT_VARIABLE APR_C_FLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
EXECUTE_PROCESS(
COMMAND ${APR_CONFIG_BIN} --link-ld
OUTPUT_VARIABLE APR_LIBRARIES
OUTPUT_STRIP_TRAILING_WHITESPACE
)
ELSE()
MESSAGE(FATAL_ERROR "Could not find apr-config/apr-1-config")
ENDIF()
IF (APU_CONFIG_BIN)
EXECUTE_PROCESS(
COMMAND ${APU_CONFIG_BIN} --includedir
OUTPUT_VARIABLE APR_UTIL_INCLUDE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
EXECUTE_PROCESS(
COMMAND ${APU_CONFIG_BIN} --cflags
OUTPUT_VARIABLE APU_C_FLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
EXECUTE_PROCESS(
COMMAND ${APU_CONFIG_BIN} --link-ld
OUTPUT_VARIABLE APU_LIBRARIES
OUTPUT_STRIP_TRAILING_WHITESPACE
)
ELSE()
MESSAGE(FATAL_ERROR "Could not find apu-config/apu-1-config")
ENDIF()
#curl-config
FIND_PROGRAM(CURL_CONFIG_BIN NAMES curl-config)
IF (CURL_CONFIG_BIN)
EXECUTE_PROCESS(
COMMAND ${CURL_CONFIG_BIN} --libs
OUTPUT_VARIABLE CURL_LIBRARIES
OUTPUT_STRIP_TRAILING_WHITESPACE
)
ELSE()
MESSAGE(FATAL_ERROR "Could not find curl-config")
ENDIF()
endif()
# Compile and link lib_oss_c_sdk
include_directories(${APR_INCLUDE_DIR})
include_directories(${APR_UTIL_INCLUDE_DIR})
include_directories(${MINIXML_INCLUDE_DIR})
include_directories(${CURL_INCLUDE_DIR})
aux_source_directory(oss_c_sdk SRC_LIST)
# build & install
if(CMAKE_HOST_WIN32)
add_library(${CMAKE_PROJECT_NAME} STATIC ${SRC_LIST})
INSTALL(TARGETS ${CMAKE_PROJECT_NAME} ARCHIVE DESTINATION lib)
else()
add_library(${CMAKE_PROJECT_NAME} SHARED ${SRC_LIST})
add_library(${CMAKE_PROJECT_NAME}_static STATIC ${SRC_LIST})
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES VERSION ${CMAKE_VERSION} SOVERSION ${CMAKE_VERSION})
INSTALL(TARGETS ${CMAKE_PROJECT_NAME} LIBRARY DESTINATION lib)
INSTALL(TARGETS ${CMAKE_PROJECT_NAME}_static ARCHIVE DESTINATION lib)
endif()
INSTALL(FILES
oss_c_sdk/aos_buf.h
oss_c_sdk/aos_define.h
oss_c_sdk/aos_fstack.h
oss_c_sdk/aos_http_io.h
oss_c_sdk/aos_list.h
oss_c_sdk/aos_log.h
oss_c_sdk/aos_status.h
oss_c_sdk/aos_string.h
oss_c_sdk/aos_transport.h
oss_c_sdk/aos_util.h
oss_c_sdk/aos_crc64.h
oss_c_sdk/oss_api.h
oss_c_sdk/oss_auth.h
oss_c_sdk/oss_define.h
oss_c_sdk/oss_resumable.h
oss_c_sdk/oss_util.h
oss_c_sdk/oss_xml.h
DESTINATION include/oss_c_sdk)
add_subdirectory(oss_c_sdk_sample)
add_subdirectory(oss_c_sdk_test)