1d4afb5ceSopenharmony_ci#
2d4afb5ceSopenharmony_ci# CMake Toolchain file for crosscompiling on Mediatek Linkit 7967
3d4afb5ceSopenharmony_ci#
4d4afb5ceSopenharmony_ci# This can be used like this (with Linkit sdk unpacked to /opt/linkit)
5d4afb5ceSopenharmony_ci#
6d4afb5ceSopenharmony_ci#  cd build/
7d4afb5ceSopenharmony_ci#  cmake .. -DCMAKE_INSTALL_PREFIX:PATH=/opt/linkit/cross-root \
8d4afb5ceSopenharmony_ci#           -DCMAKE_TOOLCHAIN_FILE=../contrib/cross-linkit.cmake \
9d4afb5ceSopenharmony_ci#           -DLWS_PLAT_FREERTOS=1 \
10d4afb5ceSopenharmony_ci#           -DLWS_WITH_ZLIB=0 \
11d4afb5ceSopenharmony_ci#           -DLWS_WITHOUT_EXTENSIONS=1 \
12d4afb5ceSopenharmony_ci#           -DLWS_WITH_ZIP_FOPS=0 \
13d4afb5ceSopenharmony_ci#           -DLWS_WITH_HTTP_STREAM_COMPRESSION=0 \
14d4afb5ceSopenharmony_ci#           -DLWS_WITH_MBEDTLS=1 \
15d4afb5ceSopenharmony_ci#           -DLWS_WITH_FILE_OPS=0
16d4afb5ceSopenharmony_ci#
17d4afb5ceSopenharmony_ci
18d4afb5ceSopenharmony_ci# if your sdk lives somewhere else, this is the only place that should need changing
19d4afb5ceSopenharmony_ciset(CROSS_BASE /opt/linkit/sdk)
20d4afb5ceSopenharmony_ciset(CROSS_PATH ${CROSS_BASE}/tools/gcc/gcc-arm-none-eabi)
21d4afb5ceSopenharmony_ci
22d4afb5ceSopenharmony_ci#
23d4afb5ceSopenharmony_ci# Target operating system name.
24d4afb5ceSopenharmony_ciset(CMAKE_SYSTEM_NAME Generic)
25d4afb5ceSopenharmony_ci
26d4afb5ceSopenharmony_ci# Name of C compiler.
27d4afb5ceSopenharmony_ciset(CMAKE_C_COMPILER "${CROSS_PATH}/bin/arm-none-eabi-gcc")
28d4afb5ceSopenharmony_ciset(CMAKE_CXX_COMPILER "${CROSS_PATH}/bin/arm-none-eabi-g++")
29d4afb5ceSopenharmony_ci
30d4afb5ceSopenharmony_ci#
31d4afb5ceSopenharmony_ci# cmake believes we should link a NOP test program OK, but since we're
32d4afb5ceSopenharmony_ci# baremetal, that's not true in our case.  It tries to build this test
33d4afb5ceSopenharmony_ci# with the cross compiler, but with no args on it, and it fails.
34d4afb5ceSopenharmony_ci# So disable this test for this toolchain (we'll find out soon enough
35d4afb5ceSopenharmony_ci# if we actually can't compile anything)
36d4afb5ceSopenharmony_ci
37d4afb5ceSopenharmony_ciset(CMAKE_C_COMPILER_WORKS 1)
38d4afb5ceSopenharmony_ciset(CMAKE_CXX_COMPILER_WORKS 1)
39d4afb5ceSopenharmony_ci
40d4afb5ceSopenharmony_ci#
41d4afb5ceSopenharmony_ci# similarly we're building a .a like this, we can't actually build
42d4afb5ceSopenharmony_ci# complete test programs to probe api availability... so force some
43d4afb5ceSopenharmony_ci# key ones
44d4afb5ceSopenharmony_ci
45d4afb5ceSopenharmony_ciset(LWS_HAVE_mbedtls_ssl_conf_alpn_protocols 1)
46d4afb5ceSopenharmony_ciset(LWS_HAVE_mbedtls_ssl_conf_alpn_protocols 1)
47d4afb5ceSopenharmony_ciset(LWS_HAVE_mbedtls_ssl_get_alpn_protocol 1)
48d4afb5ceSopenharmony_ciset(LWS_HAVE_mbedtls_ssl_conf_sni 1)
49d4afb5ceSopenharmony_ciset(LWS_HAVE_mbedtls_ssl_set_hs_ca_chain 1)
50d4afb5ceSopenharmony_ciset(LWS_HAVE_mbedtls_ssl_set_hs_own_cert 1)
51d4afb5ceSopenharmony_ciset(LWS_HAVE_mbedtls_ssl_set_hs_authmode 1)
52d4afb5ceSopenharmony_ciset(LWS_HAVE_mbedtls_net_init 1)
53d4afb5ceSopenharmony_ciset(LWS_HAVE_mbedtls_md_setup 1) # not on xenial 2.2
54d4afb5ceSopenharmony_ciset(LWS_HAVE_mbedtls_rsa_complete 1) # not on xenial 2.2
55d4afb5ceSopenharmony_ciset(LWS_HAVE_mbedtls_internal_aes_encrypt 1)
56d4afb5ceSopenharmony_ci#
57d4afb5ceSopenharmony_ci# Different build system distros set release optimization level to different
58d4afb5ceSopenharmony_ci# things according to their local policy, eg, Fedora is -O2 and Ubuntu is -O3
59d4afb5ceSopenharmony_ci# here.  Actually the build system's local policy is completely unrelated to
60d4afb5ceSopenharmony_ci# our desire for cross-build release optimization policy for code built to run
61d4afb5ceSopenharmony_ci# on a completely different target than the build system itself.
62d4afb5ceSopenharmony_ci#
63d4afb5ceSopenharmony_ci# Since this goes last on the compiler commandline we have to override it to a
64d4afb5ceSopenharmony_ci# sane value for cross-build here.  Notice some gcc versions enable broken
65d4afb5ceSopenharmony_ci# optimizations with -O3.
66d4afb5ceSopenharmony_ci#
67d4afb5ceSopenharmony_ciif (CMAKE_BUILD_TYPE MATCHES RELEASE OR CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES release)
68d4afb5ceSopenharmony_ci	set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2")
69d4afb5ceSopenharmony_ci	set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
70d4afb5ceSopenharmony_ciendif()
71d4afb5ceSopenharmony_ci
72d4afb5ceSopenharmony_ciset(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lnosys -nostartfiles -I${CROSS_BASE}/middleware/third_party/lwip/src/include/lwip -I${CROSS_BASE}/middleware/third_party/lwip/src/include -I${CROSS_BASE}/project/mt7687_hdk/apps/httpd/inc/ -I${CROSS_BASE}/kernel/service/inc/ -I${CROSS_BASE}/driver/chip/inc -I${CROSS_BASE}/driver/chip/mt7687/inc/ -I${CROSS_BASE}/driver/CMSIS/Device/MTK/mt7687/Include/ -I${CROSS_BASE}/driver/CMSIS/Include -I${CROSS_BASE}/middleware/third_party/lwip/ports/include/ -I${CROSS_BASE}/middleware/third_party/lwip/src/include/posix/ -I${CROSS_BASE}/kernel/rtos/FreeRTOS/Source/include/ -I${CROSS_BASE}/middleware/third_party/mbedtls/include/ -I${CROSS_BASE}/kernel/rtos/FreeRTOS/Source/portable/GCC/ARM_CM4F/ -I${CROSS_BASE}/middleware/third_party/sntp/inc/ -DLWS_AMAZON_RTOS=1"  CACHE STRING "" FORCE)
73d4afb5ceSopenharmony_ci
74d4afb5ceSopenharmony_ci# Where to look for the target environment. (More paths can be added here)
75d4afb5ceSopenharmony_ciset(CMAKE_FIND_ROOT_PATH "${CROSS_PATH}")
76d4afb5ceSopenharmony_ci
77d4afb5ceSopenharmony_ci# Adjust the default behavior of the FIND_XXX() commands:
78d4afb5ceSopenharmony_ci# search programs in the host environment only.
79d4afb5ceSopenharmony_ciset(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
80d4afb5ceSopenharmony_ci
81d4afb5ceSopenharmony_ci# Search headers and libraries in the target environment only.
82d4afb5ceSopenharmony_ciset(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
83d4afb5ceSopenharmony_ciset(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
84d4afb5ceSopenharmony_ci
85