-
Notifications
You must be signed in to change notification settings - Fork 63
/
CMakeLists.txt
executable file
·226 lines (184 loc) · 5.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
##
# @file CMakeLists.txt
# @brief
# @author Tuya
# @version 1.0.0
# @date 2023-03-26
#/
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
# include cmake
set(TOP_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(TOP_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${TOP_BINARY_DIR}/lib)
SET(EXECUTABLE_OUTPUT_PATH ${TOP_BINARY_DIR}/bin)
if(${TOP_SOURCE_DIR} STREQUAL ${TOP_BINARY_DIR})
message(FATAL_ERROR "
[In-source builds] are not allowed.
You should create separate directory for build files.
Remove \"CMakeCache.txt\" and \"CMakeFiles/\".
Use commands like:
[mkdir build; cd build; cmake ..]
or
[cmake -S . -B build]
")
endif()
MESSAGE(STSTUS "###################################")
IF (WIN32)
MESSAGE(STATUS "Now is windows")
ELSEIF (APPLE)
MESSAGE(STATUS "Now is Apple systens.")
ELSEIF (UNIX)
MESSAGE(STATUS "Now is UNIX-like OS's.")
ENDIF ()
include(${TOP_SOURCE_DIR}/tools/cmake/colors.cmake)
include(${TOP_SOURCE_DIR}/tools/cmake/util.cmake)
if(NOT DEFINED TOS_FRAMEWORK)
set(TOS_FRAMEWORK "base")
endif()
message(STATUS "[TOP] Using framework [${TOS_FRAMEWORK}].")
if(DEFINED TOS_PROJECT_PLATFORM)
set(PLATFORM_NAME ${TOS_PROJECT_PLATFORM})
set(PLATFORM_CHIP ${TOS_PROJECT_CHIP})
set(PLATFORM_PATH "${TOP_SOURCE_DIR}/platform/${TOS_PROJECT_PLATFORM}")
endif()
set(KCONFIG_CATALOG "${PLATFORM_PATH}/CatalogKconfig")
set(DEFAULT_CONFIG_NAME "default.config")
set(PRE_CONFIG_DIR "${TOS_PROJECT_ROOT}/pre_config")
# use Kconfig
set(DOT_CONFIG_DIR "${TOP_BINARY_DIR}/cache")
set(DOT_CONFIG "using.config")
set(CMAKE_CONFIG "using.cmake")
set(HEADER_DIR "${TOP_BINARY_DIR}/include")
set(PLATFORM_NEED_HDIR "${TOP_BINARY_DIR}/include")
set(HEADER_FILE "tuya_kconfig.h")
set(HEADER_IN_PATH "${TOP_SOURCE_DIR}/tools/kconfiglib/config.h.in")
add_subdirectory("${TOP_SOURCE_DIR}/tools/kconfiglib")
# toolchain cmake
include("${PLATFORM_PATH}/toolchain_file.cmake")
message(STATUS "[TOP] Using toolchain file [${CMAKE_TOOLCHAIN_FILE}].")
project(opensdk)
# add platform
include("${PLATFORM_PATH}/platform_config.cmake")
# add src
set(COMPONENT_LIBS "")
set(COMPONENT_PUBINC "")
list_components(COMPONENT_LIST "${TOP_SOURCE_DIR}/src")
foreach(comp ${COMPONENT_LIST})
# message(STATUS "comp: ${comp}")
add_subdirectory("${TOP_SOURCE_DIR}/src/${comp}")
endforeach(comp)
# add arduino src
if(TOS_FRAMEWORK STREQUAL "arduino")
include(${TOP_SOURCE_DIR}/arduino-tuyaopen/CMakeLists.txt)
message(STATUS "[TOP] LD_FILE: ${LD_FILE}")
endif()
# message(STATUS "[TOP] COMPONENT_LIBS: ${COMPONENT_LIBS}")
# copy_public_include("${COMPONENT_PUBINC}" "${HEADER_DIR}")
list(APPEND HEADER_DIR ${PLATFORM_PUBINC})
list(APPEND HEADER_DIR ${COMPONENT_PUBINC})
# message(STATUS "[TOP] HEADER_DIR: ${HEADER_DIR}")
deal_with_components("${COMPONENT_LIBS}" "${HEADER_DIR}")
# build components_all lib
set(COMPONENTS_ALL_LIB "tuyaos")
set(all_need)
foreach(c ${COMPONENT_LIBS})
list(APPEND all_need $<TARGET_OBJECTS:${c}>)
endforeach(c)
add_library(${COMPONENTS_ALL_LIB} STATIC ${all_need})
# add example
set(EXAMPLE_NAME "${TOS_PROJECT_NAME}")
message(STATUS "[TOP] Using example [${EXAMPLE_NAME}].")
if(NOT DEFINED CONFIG_PROJECT_VERSION)
set(CONFIG_PROJECT_VERSION "1.0.0")
endif()
set(EXAMPLE_LIB "tuyaapp")
list(APPEND PLATFORM_NEED_HDIR ${COMPONENT_PUBINC})
string(REPLACE ";" " " PLATFORM_NEED_HDIR "${PLATFORM_NEED_HDIR}")
set(PLATFORM_NEED_LIBS "${EXAMPLE_LIB} ${COMPONENTS_ALL_LIB}")
if(TOS_FRAMEWORK STREQUAL "arduino")
if(PLATFORM_NAME STREQUAL "t2")
set(PLATFORM_NEED_LIBS "${EXAMPLE_LIB} ${COMPONENTS_ALL_LIB} stdc++")
endif()
endif()
message(STATUS "[TOP] PLATFORM_NEED_LIBS: ${PLATFORM_NEED_LIBS}")
include(${TOS_PROJECT_ROOT}/CMakeLists.txt)
target_include_directories(${EXAMPLE_LIB}
PUBLIC
${HEADER_DIR}
)
target_link_libraries(${EXAMPLE_LIB} ${COMPONENTS_ALL_LIB})
add_custom_target(example
WORKING_DIRECTORY
${TOP_SOURCE_DIR}
COMMAND
./tools/build_example.sh "${TOP_BINARY_DIR}" "${DEL_DEPEND}"
)
add_custom_target(example_all
DEPENDS
show_menuconfig
${EXAMPLE_LIB}
build_example_exe
COMMENT
"[TOP] example=[${EXAMPLE_NAME}]"
)
add_custom_command(
OUTPUT
show_menuconfig
COMMAND
${CMAKE_COMMAND} -E echo " ${Cyan}[tos menuconfig]${ColourReset}"
COMMAND
${CMAKE_COMMAND} -E echo ""
COMMENT
"[EXAMPLE] If you want to change the configuration or change example version:"
)
add_custom_command(
OUTPUT
build_example_exe
WORKING_DIRECTORY
${PLATFORM_PATH}
COMMAND
export OPEN_LD_FILE="${LD_FILE}" &&
./build_example.sh "${EXAMPLE_NAME}" "${CONFIG_PROJECT_VERSION}" "${PLATFORM_NEED_HDIR}"
"${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}" "${PLATFORM_NEED_LIBS}"
"${EXECUTABLE_OUTPUT_PATH}" "build" "${PLATFORM_CHIP}"
COMMENT
"[EXAMPLE] Generate execute file [${EXAMPLE_NAME}]"
)
# clean
add_custom_target(platform_clean
WORKING_DIRECTORY
${PLATFORM_PATH}
COMMAND
COMMAND
export OPEN_LD_FILE="${LD_FILE}" &&
./build_example.sh "${EXAMPLE_NAME}" "${CONFIG_PROJECT_VERSION}" "${PLATFORM_NEED_HDIR}"
"${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}" "${PLATFORM_NEED_LIBS}"
"${EXECUTABLE_OUTPUT_PATH}" "clean"
COMMENT
"[TOP] Platform clean."
)
add_custom_target(platform_menuconfig
WORKING_DIRECTORY
${PLATFORM_PATH}
COMMAND
./build_example.sh "${EXAMPLE_NAME}" "${CONFIG_PROJECT_VERSION}" "${PLATFORM_NEED_HDIR}"
"${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}" "${PLATFORM_NEED_LIBS}"
"${EXECUTABLE_OUTPUT_PATH}" "menuconfig"
COMMENT
"[TOP] Platform menuconfig."
)
add_custom_target(clean_all
DEPENDS
platform_clean
COMMAND ${CMAKE_BUILD_TOOL} clean
)
# add UT
enable_testing()
add_subdirectory("${TOP_SOURCE_DIR}/tools/ut")
# prompt
message(STATUS "[TOP] If you want to build example
${Cyan}[tos build]${ColourReset}.
")
message(STATUS "[TOP] If you want to clean project
${Cyan}[tos clean]${ColourReset}.
")