-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
206 lines (154 loc) · 8.93 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
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12 FATAL_ERROR)
# ---[ Project
PROJECT(brick C CXX)
# ---[ Options.
SET(BRICK_LIBRARY_TYPE "default" CACHE STRING "Type of library (shared, static, or default) to build")
SET_PROPERTY(CACHE BRICK_LIBRARY_TYPE PROPERTY STRINGS default static shared)
OPTION(BRICK_BUILD_TESTS "Build BRICK unit tests" ON)
# OPTION(BRICK_DOWNLOAD_LIBS "Build BRICK unit tests" OFF)
IF(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
SET(TARGET_OS_LINK_LIBS pthread)
ELSEIF(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
SET(_CMAKE_TOOLCHAIN_LOCATION "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin")
MESSAGE(STATUS ${_CMAKE_TOOLCHAIN_LOCATION})
SET(CMAKE_C_COMPILER ${_CMAKE_TOOLCHAIN_LOCATION}/cl.exe)
SET(CMAKE_CXX_COMPILER ${_CMAKE_TOOLCHAIN_LOCATION}/cl.exe)
ELSEIF()
MESSAGE(FATAL_ERROR "Not support ${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}!!!")
ENDIF()
# ---[ CMake options
IF(BRICK_BUILD_TESTS)
ENABLE_TESTING()
ENDIF()
# ---[ Download deps
SET(CONFU_DEPENDENCIES_SOURCE_DIR ${CMAKE_SOURCE_DIR}/deps
CACHE PATH "Confu-style dependencies source directory")
SET(CONFU_DEPENDENCIES_BINARY_DIR ${CMAKE_BINARY_DIR}/deps
CACHE PATH "Confu-style dependencies binary directory")
IF(BRICK_BUILD_TESTS AND NOT DEFINED GOOGLETEST_SOURCE_DIR)
MESSAGE(STATUS "Downloading Google Test to ${CONFU_DEPENDENCIES_SOURCE_DIR}/googletest (define GOOGLETEST_SOURCE_DIR to avoid it)")
CONFIGURE_FILE(cmake/DownloadGoogleTest.cmake "${CONFU_DEPENDENCIES_BINARY_DIR}/googletest-download/CMakeLists.txt")
EXECUTE_PROCESS(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY "${CONFU_DEPENDENCIES_BINARY_DIR}/googletest-download")
EXECUTE_PROCESS(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CONFU_DEPENDENCIES_BINARY_DIR}/googletest-download")
SET(GOOGLETEST_SOURCE_DIR "${CONFU_DEPENDENCIES_SOURCE_DIR}/googletest" CACHE STRING "Google Test source directory")
ENDIF()
IF(BRICK_BUILD_TESTS AND NOT DEFINED ZLIB_SOURCE_DIR)
MESSAGE(STATUS "Downloading Zlib to ${CONFU_DEPENDENCIES_SOURCE_DIR}/zlib (define ZLIB_SOURCE_DIR to avoid it)")
CONFIGURE_FILE(cmake/DownloadZlib.cmake "${CONFU_DEPENDENCIES_BINARY_DIR}/zlib-download/CMakeLists.txt")
EXECUTE_PROCESS(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY "${CONFU_DEPENDENCIES_BINARY_DIR}/zlib-download")
EXECUTE_PROCESS(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CONFU_DEPENDENCIES_BINARY_DIR}/zlib-download")
SET(ZLIB_SOURCE_DIR "${CONFU_DEPENDENCIES_SOURCE_DIR}/zlib" CACHE STRING "Zlib source directory")
ENDIF()
IF(BRICK_BUILD_TESTS AND NOT DEFINED PROTOBUF_SOURCE_DIR)
MESSAGE(STATUS "Downloading Protobuf to ${CONFU_DEPENDENCIES_SOURCE_DIR}/protobuf (define PROTOBUF_SOURCE_DIR to avoid it)")
CONFIGURE_FILE(cmake/DownloadProtobuf.cmake "${CONFU_DEPENDENCIES_BINARY_DIR}/protobuf-download/CMakeLists.txt")
EXECUTE_PROCESS(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY "${CONFU_DEPENDENCIES_BINARY_DIR}/protobuf-download")
EXECUTE_PROCESS(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CONFU_DEPENDENCIES_BINARY_DIR}/protobuf-download")
SET(PROTOBUF_SOURCE_DIR "${CONFU_DEPENDENCIES_SOURCE_DIR}/protobuf" CACHE STRING "Protobuf source directory")
ENDIF()
IF(BRICK_BUILD_TESTS AND NOT DEFINED GFLAGS_INCLUDE_DIR)
MESSAGE(STATUS "Downloading Gflags to ${CONFU_DEPENDENCIES_SOURCE_DIR}/gflags (define PROTOBUF_SOURCE_DIR to avoid it)")
CONFIGURE_FILE(cmake/DownloadGflags.cmake "${CONFU_DEPENDENCIES_BINARY_DIR}/gflags/CMakeLists.txt")
EXECUTE_PROCESS(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY "${CONFU_DEPENDENCIES_SOURCE_DIR}/gflags")
EXECUTE_PROCESS(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CONFU_DEPENDENCIES_SOURCE_DIR}/gflags")
SET(GFLAGS_LIB_DIR "${CONFU_DEPENDENCIES_SOURCE_DIR}/gflags/lib" CACHE STRING "Gflags source directory")
SET(GFLAGS_INCLUDE_DIR "${CONFU_DEPENDENCIES_SOURCE_DIR}/gflags/include" CACHE STRING "Gflags source directory")
ENDIF()
IF(BRICK_BUILD_TESTS AND NOT DEFINED BEARSSL_SOURCE_DIR)
MESSAGE(STATUS "Downloading Bearssl to ${CONFU_DEPENDENCIES_SOURCE_DIR}/bearssl (define BEARSSL_SOURCE_DIR to avoid it)")
CONFIGURE_FILE(cmake/DownloadBearssl.cmake "${CONFU_DEPENDENCIES_BINARY_DIR}/bearssl-download/CMakeLists.txt")
EXECUTE_PROCESS(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY "${CONFU_DEPENDENCIES_BINARY_DIR}/bearssl-download")
EXECUTE_PROCESS(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CONFU_DEPENDENCIES_BINARY_DIR}/bearssl-download")
SET(BEARSSL_SOURCE_DIR "${CONFU_DEPENDENCIES_SOURCE_DIR}/bearssl" CACHE STRING "Bearssl source directory")
ENDIF()
IF(BRICK_BUILD_TESTS AND NOT DEFINED CURL_SOURCE_DIR)
MESSAGE(STATUS "Downloading Curl to ${CONFU_DEPENDENCIES_SOURCE_DIR}/curl (define CURL_SOURCE_DIR to avoid it)")
CONFIGURE_FILE(cmake/DownloadCurl.cmake "${CONFU_DEPENDENCIES_BINARY_DIR}/curl-download/CMakeLists.txt")
EXECUTE_PROCESS(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY "${CONFU_DEPENDENCIES_BINARY_DIR}/curl-download")
EXECUTE_PROCESS(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CONFU_DEPENDENCIES_BINARY_DIR}/curl-download")
SET(CURL_SOURCE_DIR "${CONFU_DEPENDENCIES_SOURCE_DIR}/curl" CACHE STRING "Curl source directory")
ENDIF()
IF(BRICK_BUILD_TESTS AND NOT DEFINED EIGEN_SOURCE_DIR)
MESSAGE(STATUS "Downloading Eigen to ${CONFU_DEPENDENCIES_SOURCE_DIR}/eigen (define EIGEN_SOURCE_DIR to avoid it)")
CONFIGURE_FILE(cmake/DownloadEigen.cmake "${CONFU_DEPENDENCIES_BINARY_DIR}/eigen-download/CMakeLists.txt")
EXECUTE_PROCESS(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY "${CONFU_DEPENDENCIES_BINARY_DIR}/eigen-download")
EXECUTE_PROCESS(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CONFU_DEPENDENCIES_BINARY_DIR}/eigen-download")
SET(EIGEN_SOURCE_DIR "${CONFU_DEPENDENCIES_SOURCE_DIR}/eigen" CACHE STRING "Eigen source directory")
ENDIF()
IF(BRICK_BUILD_TESTS AND NOT DEFINED GLOG_INCLUDE_DIR)
MESSAGE(STATUS "Downloading Glog to ${CONFU_DEPENDENCIES_SOURCE_DIR}/glog (define GLOG_SOURCE_DIR to avoid it)")
CONFIGURE_FILE(cmake/DownloadGlog.cmake "${CONFU_DEPENDENCIES_BINARY_DIR}/glog/CMakeLists.txt")
EXECUTE_PROCESS(COMMAND "./configure"
WORKING_DIRECTORY "${CONFU_DEPENDENCIES_SOURCE_DIR}/glog")
EXECUTE_PROCESS(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CONFU_DEPENDENCIES_SOURCE_DIR}/glog")
SET(GLOG_LIB_DIR "${CONFU_DEPENDENCIES_SOURCE_DIR}/glog" CACHE STRING "Glog source directory")
SET(GLOG_INCLUDE_DIR "${CONFU_DEPENDENCIES_SOURCE_DIR}/glog/src" CACHE STRING "Glog include directory")
ENDIF()
IF(BRICK_BUILD_TESTS AND NOT DEFINED JSON11_INCLUDE_DIR)
MESSAGE(STATUS "Downloading Json11 to ${CONFU_DEPENDENCIES_SOURCE_DIR}/json11 (define JSON11_SOURCE_DIR to avoid it)")
EXECUTE_PROCESS(COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CONFU_DEPENDENCIES_SOURCE_DIR}/json11")
SET(JSON11_LIB_DIR "${CONFU_DEPENDENCIES_SOURCE_DIR}/json11")
SET(JSON11_INCLUDE_DIR "${CONFU_DEPENDENCIES_SOURCE_DIR}/json11")
ENDIF()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -Wall -O2")
# test zlib
INCLUDE_DIRECTORIES(
${ZLIB_SOURCE_DIR}
${EIGEN_SOURCE_DIR}
${GLOG_INCLUDE_DIR}
${GFLAGS_INCLUDE_DIR}
${JSON11_INCLUDE_DIR})
LINK_DIRECTORIES(
${GLOG_LIB_DIR}
${GFLAGS_LIB_DIR}
${JSON11_LIB_DIR}
)
ADD_EXECUTABLE(test_sample_zlib ${CMAKE_SOURCE_DIR}/samples/sample_zlib.cpp)
TARGET_LINK_LIBRARIES(test_sample_zlib z)
MESSAGE(STATUS "build protobuf sample")
ADD_EXECUTABLE(test_sample_protobuf
${CMAKE_SOURCE_DIR}/samples/sample_protobuf.cpp
${CMAKE_SOURCE_DIR}/samples/protobuf/addressbook.pb.cc)
TARGET_LINK_LIBRARIES(test_sample_protobuf protobuf)
ADD_EXECUTABLE(test_sample_curl ${CMAKE_SOURCE_DIR}/samples/sample_curl.cpp)
TARGET_LINK_LIBRARIES(test_sample_curl curl ${TARGET_OS_LINK_LIBS})
# ADD_EXECUTABLE(test_sample_gflag ${CMAKE_SOURCE_DIR}/samples/sample_gflag.cpp)
# TARGET_LINK_LIBRARIES(test_sample_gflag gflags glog ${TARGET_OS_LINK_LIBS})
MESSAGE(STATUS "build eigen sample")
ADD_EXECUTABLE(test_sample_eigen ${CMAKE_SOURCE_DIR}/samples/sample_eigen.cpp)
# test glog
# MESSAGE(STATUS "build glog sample")
# ADD_EXECUTABLE(test_sample_glog ${CMAKE_SOURCE_DIR}/samples/sample_glog.cpp)
# TARGET_LINK_LIBRARIES(test_sample_glog glog ${TARGET_OS_LINK_LIBS})
# test c++ basic samples
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
AUX_SOURCE_DIRECTORY(${CMAKE_SOURCE_DIR}/samples/cppbasic CPP_BASIC_DEMO)
FOREACH(sample_path ${CPP_BASIC_DEMO})
STRING(REGEX REPLACE ".+/(.+)\\..*" "\\1" FILE_NAME ${sample_path})
ADD_EXECUTABLE(test_${FILE_NAME} ${sample_path})
ENDFOREACH()
AUX_SOURCE_DIRECTORY(${CMAKE_SOURCE_DIR}/demo DEMO_SRC)
FOREACH(sample_path ${DEMO_SRC})
STRING(REGEX REPLACE ".+/(.+)\\..*" "\\1" FILE_NAME ${sample_path})
ADD_EXECUTABLE(test_${FILE_NAME} ${sample_path})
ENDFOREACH()
TARGET_LINK_LIBRARIES(test_get_file_md5 curl crypto)
TARGET_LINK_LIBRARIES(test_gen_json json11)
# add opencv_test
add_subdirectory(opencv_test)