forked from JunhwanPark/artik-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
205 lines (173 loc) · 8.04 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
CMAKE_MINIMUM_REQUIRED ( VERSION 3.0 )
SET ( LIB_VERSION_MAJOR 1 CACHE STRING "Library version major")
SET ( LIB_VERSION_MINOR 9 CACHE STRING "Library version minor")
SET ( LIB_VERSION_PATCH 0 CACHE STRING "Library version patch")
SET ( MODULE "" CACHE STRING "Compile specific source module " )
SET ( TEST_X "" CACHE STRING "Compile specific unit test " )
SET ( NAME_TARGET "" CACHE STRING "Compile to a specific architecture target" )
SET ( PATH_TARGET "" CACHE STRING "Path of target ROOT " )
PROJECT ( artik-sdk C CXX )
SET ( EXT_DLL .so )
IF ( "${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin" )
SET ( EXT_DLL .dylib )
ENDIF( )
SET ( NAME_TARGET ${CMAKE_SYSTEM_PROCESSOR} )
SET ( LIB_TARGET Release/${NAME_TARGET}/lib )
SET ( BIN_TARGET Release/${NAME_TARGET}/bin )
SET ( LIB_DIR ${CMAKE_BINARY_DIR}/${LIB_TARGET} )
SET ( BIN_DIR ${CMAKE_BINARY_DIR}/${BIN_TARGET} )
include(GNUInstallDirs)
if ("${CMAKE_LIBRARY_ARCHITECTURE}" STREQUAL "")
SET(CMAKE_INSTALL_INCLUDEDIR "include")
else()
SET(CMAKE_INSTALL_INCLUDEDIR "include/${CMAKE_LIBRARY_ARCHITECTURE}")
endif()
IF ( CMAKE_SYSROOT )
SET ( CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT} )
SET ( C_CPP_FLAGS "-Werror -Wall -Wpedantic -Wno-unused-parameter -Wno-unused-result --sysroot=${CMAKE_SYSROOT}" )
SET ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_CPP_FLAGS}" )
SET ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${C_CPP_FLAGS}" )
SET ( NODE_CFLAGS "-I${CMAKE_SYSROOT}/usr/include" )
LINK_DIRECTORIES ( ${LIB_DIR} ${CMAKE_SYSROOT}/usr/lib ${CMAKE_SYSROOT}/usr )
IF (DEFINED CMAKE_PKG_CONFIG_PATH)
MESSAGE("Using pre-defined PKG_CONFIG_PATH")
SET ( ENV{PKG_CONFIG_PATH} "${CMAKE_PKG_CONFIG_PATH}" )
SET ( ENV{PKG_CONFIG_LIBDIR} "${CMAKE_PKG_CONFIG_PATH}")
ELSE ( )
SET ( ENV{PKG_CONFIG_PATH} "${CMAKE_SYSROOT}/${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig" )
SET ( ENV{PKG_CONFIG_LIBDIR} "${CMAKE_SYSROOT}/${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig" )
ENDIF ( )
MESSAGE("PKG CONFIG PATH is $ENV{PKG_CONFIG_PATH}")
SET ( ENV{PKG_CONFIG_DIR} "")
SET ( ENV{PKG_CONFIG_SYSROOT_DIR} ${CMAKE_SYSROOT})
ELSE ( )
LINK_DIRECTORIES ( ${LIB_DIR} )
SET ( NODE_CFLAGS "" )
ENDIF ( )
SET ( LIB_INC ${CMAKE_CURRENT_SOURCE_DIR}/inc )
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
SET ( CMAKE_INSTALL_PREFIX /usr/ )
SET ( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIB_DIR} )
SET ( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BIN_DIR} )
SET ( CMAKE_SKIP_BUILD_RPATH TRUE )
FILE ( GLOB pkgconfig "${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/*.cmake" )
FOREACH(file ${pkgconfig})
GET_FILENAME_COMPONENT(BASE_NAME ${file} NAME_WE)
CONFIGURE_FILE(${file} ${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/${BASE_NAME}.pc @ONLY)
ENDFOREACH()
FILE ( GLOB outpkgconfig "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/*.pc" )
INSTALL ( FILES ${outpkgconfig} DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" )
SET ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x" )
IF ( NOT CMAKE_BUILD_TYPE )
MESSAGE ( "-- Defaulting to Release build" )
SET ( CMAKE_BUILD_TYPE Release CACHE STRING "Build configuration (Release|Debug)" FORCE)
ENDIF ( )
option (CMAKE_ENABLE_SANITIZER "" OFF)
if (CMAKE_ENABLE_SANITIZER)
SET ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fno-common -fsanitize=address -fsanitize=undefined -static-libasan" )
SET ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fno-common -fsanitize=address -fsanitize=undefined -static-libasan" )
endif ()
SET ( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DCONFIG_RELEASE" )
SET ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DCONFIG_RELEASE" )
SET ( CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -DCONFIG_RELEASE" )
SET ( CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DCONFIG_RELEASE" )
# Figure out host processor
EXECUTE_PROCESS ( COMMAND uname -p
COMMAND xargs echo -n
OUTPUT_VARIABLE HOST_PROCESSOR )
MESSAGE ( "-- Host Processor: " ${HOST_PROCESSOR} )
MESSAGE ( "-- Target Processor: " ${CMAKE_SYSTEM_PROCESSOR} )
MESSAGE ( "-- Cross compiling: " ${CMAKE_CROSSCOMPILING} )
FUNCTION ( exec_cmake_target name_target path_target )
EXECUTE_PROCESS ( COMMAND rm -rf CMakeCache.txt )
ENDFUNCTION ( exec_cmake_target )
FUNCTION ( exec_check_syntax target path_target )
ADD_CUSTOM_TARGET ( ${target}
COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/scripts/code-syntax.sh ${path_target}
VERBATIM )
ENDFUNCTION ( exec_check_syntax )
FUNCTION ( conf_build_option )
MAKE_DIRECTORY ( ${BIN_DIR} )
MAKE_DIRECTORY ( ${LIB_DIR} )
ENDFUNCTION ( conf_build_option )
FUNCTION ( build_src_c_cpp module )
SET ( ARCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/ )
SET ( MODULE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/modules/ )
ADD_SUBDIRECTORY ( src )
ENDFUNCTION ( build_src_c_cpp )
FUNCTION ( build_src module )
ADD_DEFINITIONS ( -DLIB_VERSION_MAJOR=${LIB_VERSION_MAJOR}
-DLIB_VERSION_MINOR=${LIB_VERSION_MINOR}
-DLIB_VERSION_PATCH=${LIB_VERSION_PATCH} )
build_src_c_cpp( ${module} )
ENDFUNCTION ( build_src )
FUNCTION ( build_test unit )
SET ( TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test )
ADD_SUBDIRECTORY ( ${TEST_DIR}/module_test )
ADD_SUBDIRECTORY ( ${TEST_DIR}/http_test )
ADD_SUBDIRECTORY ( ${TEST_DIR}/cloud_test )
ADD_SUBDIRECTORY ( ${TEST_DIR}/gpio_test )
ADD_SUBDIRECTORY ( ${TEST_DIR}/loop_test )
ADD_SUBDIRECTORY ( ${TEST_DIR}/i2c_test )
ADD_SUBDIRECTORY ( ${TEST_DIR}/serial_test )
ADD_SUBDIRECTORY ( ${TEST_DIR}/pwm_test )
ADD_SUBDIRECTORY ( ${TEST_DIR}/adc_test )
ADD_SUBDIRECTORY ( ${TEST_DIR}/wifi_test )
ADD_SUBDIRECTORY ( ${TEST_DIR}/media_test )
ADD_SUBDIRECTORY ( ${TEST_DIR}/time_test )
ADD_SUBDIRECTORY ( ${TEST_DIR}/security_test )
ADD_SUBDIRECTORY ( ${TEST_DIR}/spi_test )
ADD_SUBDIRECTORY ( ${TEST_DIR}/sensor_test )
ADD_SUBDIRECTORY ( ${TEST_DIR}/websocket_test )
ADD_SUBDIRECTORY ( ${TEST_DIR}/bluetooth_test )
ADD_SUBDIRECTORY ( ${TEST_DIR}/zigbee_test )
ADD_SUBDIRECTORY ( ${TEST_DIR}/layercpp_test )
ADD_SUBDIRECTORY ( ${TEST_DIR}/network_test )
ADD_SUBDIRECTORY ( ${TEST_DIR}/lwm2m_test )
ADD_SUBDIRECTORY ( ${TEST_DIR}/mqtt_test )
ADD_SUBDIRECTORY ( ${TEST_DIR}/sdr_test )
ENDFUNCTION ( build_test )
FUNCTION ( build_examples )
SET ( EXAMPLES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/examples )
ADD_SUBDIRECTORY ( ${EXAMPLES_DIR}/adc )
ADD_SUBDIRECTORY ( ${EXAMPLES_DIR}/cloud )
ADD_SUBDIRECTORY ( ${EXAMPLES_DIR}/coap )
ADD_SUBDIRECTORY ( ${EXAMPLES_DIR}/gpio )
ADD_SUBDIRECTORY ( ${EXAMPLES_DIR}/http )
ADD_SUBDIRECTORY ( ${EXAMPLES_DIR}/lwm2m )
ADD_SUBDIRECTORY ( ${EXAMPLES_DIR}/loop )
ADD_SUBDIRECTORY ( ${EXAMPLES_DIR}/network )
ADD_SUBDIRECTORY ( ${EXAMPLES_DIR}/media )
ADD_SUBDIRECTORY ( ${EXAMPLES_DIR}/mqtt )
ADD_SUBDIRECTORY ( ${EXAMPLES_DIR}/module )
ADD_SUBDIRECTORY ( ${EXAMPLES_DIR}/sdr )
ADD_SUBDIRECTORY ( ${EXAMPLES_DIR}/time )
ADD_SUBDIRECTORY ( ${EXAMPLES_DIR}/pwm )
ADD_SUBDIRECTORY ( ${EXAMPLES_DIR}/websocket )
ADD_SUBDIRECTORY ( ${EXAMPLES_DIR}/wifi )
ADD_SUBDIRECTORY ( ${EXAMPLES_DIR}/bluetooth )
ADD_SUBDIRECTORY ( ${EXAMPLES_DIR}/sensor )
ADD_SUBDIRECTORY ( ${EXAMPLES_DIR}/serial )
ADD_SUBDIRECTORY ( ${EXAMPLES_DIR}/security )
ADD_SUBDIRECTORY ( ${EXAMPLES_DIR}/i2c )
ADD_SUBDIRECTORY ( ${EXAMPLES_DIR}/spi )
ADD_SUBDIRECTORY ( ${EXAMPLES_DIR}/zigbee )
ENDFUNCTION (build_examples )
FUNCTION ( check_syntax )
execute_process( COMMAND find ${CMAKE_CURRENT_SOURCE_DIR} -name "*.[ch]" -path "*/src/modules/*" -printf "%h/%f " OUTPUT_VARIABLE SRC_DATA )
execute_process( COMMAND find ${CMAKE_CURRENT_SOURCE_DIR} -name "*.h" -path "*/inc/*" -printf "%h/%f " OUTPUT_VARIABLE INC_DATA )
execute_process( COMMAND find ${CMAKE_CURRENT_SOURCE_DIR} -name "*.[ch]" -path "*/test/*" -printf "%h/%f " OUTPUT_VARIABLE TEST_DATA )
exec_check_syntax( "check_syntax" "${SRC_DATA} ${INC_DATA} ${TEST_DATA}")
ENDFUNCTION ( check_syntax )
FUNCTION ( build_main )
conf_build_option()
check_syntax()
build_src("all")
IF ( CMAKE_BUILD_TEST )
build_test("all")
ENDIF ( CMAKE_BUILD_TEST )
IF ( CMAKE_BUILD_EXAMPLES )
build_examples()
ENDIF ( CMAKE_BUILD_EXAMPLES )
ENDFUNCTION ( build_main )
build_main ( )