• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# CMake Toolchain file for crosscompiling on Atmel Arm products
3#
4# To build without tls
5#
6#  cd build/
7#  cmake .. -DCMAKE_INSTALL_PREFIX:PATH=/opt/atmel/cross-root \
8#           -DCMAKE_TOOLCHAIN_FILE=../contrib/cross-atmel.cmake \
9#           -DLWS_PLAT_FREERTOS=1 \
10#           -DLWS_WITH_ZLIB=0 \
11#           -DLWS_WITHOUT_EXTENSIONS=1 \
12#           -DLWS_WITH_ZIP_FOPS=0 \
13#           -DLWS_WITH_HTTP_STREAM_COMPRESSION=0 \
14#           -DLWS_WITH_MBEDTLS=0 \
15#           -DLWS_WITH_SSL=0 \
16#           -DLWS_WITH_FILE_OPS=0
17#
18
19# I had to edit /opt/xdk-asf-3.48.0/thirdparty/lwip/lwip-port-1.4.1-dev/sam/include/arch/cc.h
20# to comment out #define LWIP_PROVIDE_ERRNO
21
22# if your sdk lives somewhere else, this is the only place that should need changing
23
24set(CROSS_BASE /opt/arm-none-eabi)
25set(SDK_BASE /opt/xdk-asf-3.48.0)
26set(CROSS_PATH ${CROSS_BASE}/bin/arm-none-eabi)
27
28set(LWIP_VER 1.4.1-dev)
29set(FREERTOS_VER 10.0.0)
30
31#
32# Target operating system name.
33set(CMAKE_SYSTEM_NAME Generic)
34
35# Name of C compiler.
36set(CMAKE_C_COMPILER "${CROSS_PATH}-gcc")
37
38#
39# cmake believes we should link a NOP test program OK, but since we're
40# baremetal, that's not true in our case.  It tries to build this test
41# with the cross compiler, but with no args on it, and it fails.
42# So disable this test for this toolchain (we'll find out soon enough
43# if we actually can't compile anything)
44
45set(CMAKE_C_COMPILER_WORKS 1)
46set(CMAKE_CXX_COMPILER_WORKS 1)
47
48#
49# similarly we're building a .a like this, we can't actually build
50# complete test programs to probe api availability... so force some
51# key ones
52
53set(LWS_HAVE_mbedtls_ssl_conf_alpn_protocols 1)
54set(LWS_HAVE_mbedtls_ssl_conf_alpn_protocols 1)
55set(LWS_HAVE_mbedtls_ssl_get_alpn_protocol 1)
56set(LWS_HAVE_mbedtls_ssl_conf_sni 1)
57set(LWS_HAVE_mbedtls_ssl_set_hs_ca_chain 1)
58set(LWS_HAVE_mbedtls_ssl_set_hs_own_cert 1)
59set(LWS_HAVE_mbedtls_ssl_set_hs_authmode 1)
60set(LWS_HAVE_mbedtls_net_init 1)
61set(LWS_HAVE_mbedtls_md_setup 1) # not on xenial 2.2
62set(LWS_HAVE_mbedtls_rsa_complete 1) # not on xenial 2.2
63set(LWS_HAVE_mbedtls_internal_aes_encrypt 1)
64#
65# Different build system distros set release optimization level to different
66# things according to their local policy, eg, Fedora is -O2 and Ubuntu is -O3
67# here.  Actually the build system's local policy is completely unrelated to
68# our desire for cross-build release optimization policy for code built to run
69# on a completely different target than the build system itself.
70#
71# Since this goes last on the compiler commandline we have to override it to a
72# sane value for cross-build here.  Notice some gcc versions enable broken
73# optimizations with -O3.
74#
75if (CMAKE_BUILD_TYPE MATCHES RELEASE OR CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES release)
76	set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2")
77	set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
78endif()
79
80set(PLAT_ARCH        ARM_CM4F)
81set(PLAT_ARCH_CMSIS  sam4e)
82set(PLAT_SOC         __SAM4E16E__)
83set(PLAT_BOARD       SAM4E_XPLAINED_PRO)
84
85set(CF_LWIP "${CF_LWIP} -I${SDK_BASE}/thirdparty/lwip/lwip-${LWIP_VER}/src/include/lwip")
86set(CF_LWIP "${CF_LWIP} -I${SDK_BASE}/thirdparty/lwip/lwip-${LWIP_VER}/src/include/posix")
87set(CF_LWIP "${CF_LWIP} -I${SDK_BASE}/thirdparty/lwip/lwip-${LWIP_VER}/src/include")
88set(CF_LWIP "${CF_LWIP} -I${SDK_BASE}/thirdparty/lwip/lwip-${LWIP_VER}/src/module_config")
89set(CF_LWIP "${CF_LWIP} -I${SDK_BASE}/thirdparty/lwip/lwip-port-${LWIP_VER}/sam/include")
90set(CF_LWIP "${CF_LWIP} -I${SDK_BASE}/thirdparty/lwip/lwip-${LWIP_VER}/src/include/ipv4")
91
92set(CF_FREERTOS "${CF_FREERTOS} -I${SDK_BASE}/thirdparty/freertos/freertos-${FREERTOS_VER}/Source/include")
93set(CF_FREERTOS "${CF_FREERTOS} -I${SDK_BASE}/thirdparty/freertos/freertos-${FREERTOS_VER}/module_config")
94set(CF_FREERTOS "${CF_FREERTOS} -I${SDK_BASE}/thirdparty/freertos/freertos-${FREERTOS_VER}/Source/portable/GCC/${PLAT_ARCH}")
95
96set(CF_SDK_GLUE "${CF_SDK_GLUE} -I${SDK_BASE}/common/boards")
97set(CF_SDK_GLUE "${CF_SDK_GLUE} -I${SDK_BASE}/common/utils")
98set(CF_SDK_GLUE "${CF_SDK_GLUE} -I${SDK_BASE}/sam/utils/")
99set(CF_SDK_GLUE "${CF_SDK_GLUE} -I${SDK_BASE}/sam/utils/preprocessor")
100set(CF_SDK_GLUE "${CF_SDK_GLUE} -I${SDK_BASE}/sam/utils/header_files")
101set(CF_SDK_GLUE "${CF_SDK_GLUE} -I${SDK_BASE}/sam/boards")
102set(CF_SDK_GLUE "${CF_SDK_GLUE} -I${SDK_BASE}/sam/utils/cmsis/${PLAT_ARCH_CMSIS}/source/templates")
103set(CF_SDK_GLUE "${CF_SDK_GLUE} -I${SDK_BASE}/sam/utils/cmsis/${PLAT_ARCH_CMSIS}/include")
104set(CF_SDK_GLUE "${CF_SDK_GLUE} -I${SDK_BASE}/thirdparty/CMSIS/Include")
105set(CF_SDK_GLUE "${CF_SDK_GLUE} -I${SDK_BASE}/common/utils/osprintf")
106
107set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lnosys -nostartfiles ${CF_LWIP} ${CF_FREERTOS} ${CF_SDK_GLUE} -DBOARD=${PLAT_BOARD} -D${PLAT_SOC} -DLWIP_TIMEVAL_PRIVATE=0 -DLWS_AMAZON_RTOS=1 -DLWIP_SOCKET_OFFSET=0 -DLWIP_COMPAT_SOCKETS -DLWIP_DNS=1 -DLWIP_SOCKETS=1 "  CACHE STRING "" FORCE)
108
109# Where to look for the target environment. (More paths can be added here)
110set(CMAKE_FIND_ROOT_PATH "${CROSS_PATH}")
111
112# Adjust the default behavior of the FIND_XXX() commands:
113# search programs in the host environment only.
114set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
115
116# Search headers and libraries in the target environment only.
117set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
118set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
119
120