This repository has been archived by the owner on Sep 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
external_toolchain.cmake
99 lines (78 loc) · 3.5 KB
/
external_toolchain.cmake
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
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
# Skip this file for internal CMAKE tests...
if (CMAKE_PROJECT_NAME STREQUAL "CMAKE_TRY_COMPILE")
return()
endif()
if(NOT WIN32)
string(ASCII 27 Esc)
set(ColourReset "${Esc}[m")
set(ColourBold "${Esc}[1m")
set(Red "${Esc}[31m")
set(Green "${Esc}[32m")
set(Yellow "${Esc}[33m")
set(Blue "${Esc}[34m")
set(Magenta "${Esc}[35m")
set(Cyan "${Esc}[36m")
set(White "${Esc}[37m")
set(BoldRed "${Esc}[1;31m")
set(BoldGreen "${Esc}[1;32m")
set(BoldYellow "${Esc}[1;33m")
set(BoldBlue "${Esc}[1;34m")
set(BoldMagenta "${Esc}[1;35m")
set(BoldCyan "${Esc}[1;36m")
set(BoldWhite "${Esc}[1;37m")
endif()
# Check if "external_toolchain.cfg" file exists
if (EXISTS "${CMAKE_SOURCE_DIR}/external_toolchain.cfg" AND IS_SYMLINK "${CMAKE_SOURCE_DIR}/external_toolchain.cfg")
file(STRINGS "external_toolchain.cfg" ConfigContents)
foreach(NameAndValue ${ConfigContents})
# Strip leading spaces
string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue})
# Find variable name
string(REGEX MATCH "^[^=]+" Name ${NameAndValue})
# Find the value
string(REPLACE "${Name}=" "" Value ${NameAndValue})
# Set the variable
set(${Name} "${Value}")
endforeach()
if (NOT TARGET_PLATFORM)
message(FATAL_ERROR "${BoldRed}TARGET_PLATFORM NOT DEFINED!${ColourReset}")
endif()
message("${BoldWhite}Setting TOOLCHAIN for ${BoldGreen}'${TARGET_PLATFORM}'${BoldWhite} platform...${ColourReset}")
# UGW
if (TARGET_PLATFORM STREQUAL "ugw")
set(CMAKE_C_COMPILER ${PLATFORM_TOOLCHAIN_PREFIX}gcc)
set(CMAKE_CXX_COMPILER ${PLATFORM_TOOLCHAIN_PREFIX}g++)
# Target Environment
set(PLATFORM_BUILD_DIR ${PLATFORM_BASE_DIR}/build_dir/${PLATFORM_BUILD_NAME})
set(PLATFORM_STAGING_DIR ${PLATFORM_BASE_DIR}/staging_dir/${PLATFORM_BUILD_NAME})
set(PLATFORM_INCLUDE_DIR ${PLATFORM_STAGING_DIR}/usr/include)
set(CMAKE_FIND_ROOT_PATH ${PLATFORM_STAGING_DIR})
set(ENV{PKG_CONFIG_PATH} "${PLATFORM_STAGING_DIR}/usr/lib/pkgconfig")
# Platform link directories
link_directories(${PLATFORM_STAGING_DIR}/usr/lib)
elseif (TARGET_PLATFORM STREQUAL "rdkb")
set(CMAKE_C_COMPILER ${PLATFORM_TOOLCHAIN_PREFIX}gcc)
set(CMAKE_CXX_COMPILER ${PLATFORM_TOOLCHAIN_PREFIX}g++)
# Target Environment
set(PLATFORM_BUILD_DIR ${PLATFORM_BASE_DIR})
set(PLATFORM_STAGING_DIR ${PLATFORM_BUILD_DIR}/${PLATFORM_BUILD_NAME})
set(PLATFORM_INCLUDE_DIR ${PLATFORM_STAGING_DIR}/usr/include)
set(CMAKE_FIND_ROOT_PATH ${PLATFORM_STAGING_DIR})
set(ENV{PKG_CONFIG_PATH} "${PLATFORM_STAGING_DIR}/usr/lib/pkgconfig")
# Do not use files from system paths
set(NO_CMAKE_SYSTEM_PATH)
# Default Compiler flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --sysroot=${PLATFORM_STAGING_DIR}" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --sysroot=${PLATFORM_STAGING_DIR}" CACHE STRING "" FORCE)
# RDKB Build
add_definitions(-DBEEROCKS_RDKB -DYOCTO)
else()
message(FATAL_ERROR "${BoldRed}Unsupported platform type '${TARGET_PLATFORM}'!${ColourReset}")
endif()
# Set the TARGET_PLATFORM build definition
add_definitions(-DTARGET_PLATFORM=${TARGET_PLATFORM})
else()
message("${BoldWhite}Using default TOOLCHAIN...${ColourReset}")
endif()