-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToolchain.cmake
97 lines (84 loc) · 4.63 KB
/
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
#############################################################################
# Copyright (C) 2007-2012 Laboratório de Sistemas e Tecnologia Subaquática #
# Departamento de Engenharia Electrotécnica e de Computadores #
# Rua Dr. Roberto Frias, 4200-465 Porto, Portugal #
#############################################################################
# Author: Ricardo Martins #
#############################################################################
# $Id:: Toolchain.cmake 8559 2011-12-30 18:32:21Z rasm $:#
#############################################################################
# This script tries to overcome some CMake limitations regarding cross #
# compilers. The alternative method is to have a CMAKE_TOOLCHAIN_FILE #
# describing the toolchain. For now this script is far easier to use. #
#############################################################################
if(CROSS)
# Cleanup prefix.
string(REGEX REPLACE "gcc$" "" CROSS "${CROSS}")
string(REGEX REPLACE "g\\+\\+$" "" CROSS "${CROSS}")
string(REGEX REPLACE "-gcc$" "" CROSS "${CROSS}")
string(REGEX REPLACE "-g\\+\\+$" "" CROSS "${CROSS}")
string(REGEX REPLACE "-$" "" CROSS "${CROSS}")
# MinGW cross toolchain.
string(REGEX MATCH ".*mingw.*" match_mingw "${CROSS}")
if(match_mingw)
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_C_COMPILER "${CROSS}-gcc")
set(CMAKE_CXX_COMPILER "${CROSS}-g++")
set(CMAKE_RC_COMPILER "${CROSS}-windres")
set(CMAKE_STRIP "${CROSS}-strip")
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> --input-format rc --output-format coff -i<SOURCE> -o<OBJECT>")
endif(match_mingw)
# GCC Linux cross toolchain.
string(REGEX MATCH ".*linux.*" match_linux "${CROSS}")
if(match_linux)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_C_COMPILER "${CROSS}-gcc")
set(CMAKE_CXX_COMPILER "${CROSS}-g++")
endif(match_linux)
# RTEMS toolchain.
string(REGEX MATCH ".*rtems.*" match_rtems "${CROSS}")
if(match_rtems)
if(NOT RTEMS_BSP)
message(FATAL_ERROR "\nPlease set RTEMS_BSP to the path of your BSP\n")
endif(NOT RTEMS_BSP)
# Set RTEMS_RELOCADDR to the address where you want your
# image to load (in hexadecimal) If you'll be using GRUB to load
# the images it will have to be >= 0x100000 (1024K). If you are
# using NetBoot to load the images it can be >= 0x10000 (64K) AND
# <= 0x97C00 (607K) OR >= 0x100000 (1024K). The memory top is of
# course another limit. Make sure there is enough space before the
# upper memory limits for the image and the memory allocated by it
# to fit. Make sure the value you choose is aligned to 4 bytes.
if(NOT RTEMS_RELOCADDR)
set(RTEMS_RELOCADDR "0x100000")
endif(NOT RTEMS_RELOCADDR)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_C_COMPILER "${CROSS}-gcc")
set(CMAKE_CXX_COMPILER "${CROSS}-g++")
file(GLOB_RECURSE pcs "${RTEMS_BSP}/*.pc")
exec_program(pkg-config ARGS "${pcs}" --cflags OUTPUT_VARIABLE cflags)
exec_program(pkg-config ARGS "${pcs}" --variable=includedir OUTPUT_VARIABLE include)
string(REPLACE "-O2" "" cflags ${cflags})
string(REPLACE "-g" "" cflags ${cflags})
string(REPLACE "-Wall" "" cflags ${cflags})
string(REPLACE "-Wimplicit-function-declaration" "" cflags ${cflags})
string(REPLACE "-Wstrict-prototypes" "" cflags ${cflags})
string(REPLACE "-Wnested-externs" "" cflags ${cflags})
set(CMAKE_CXX_FLAGS_INIT "${cflags}" CACHE INTERNAL "Initial C++ compiler flags")
set(CMAKE_CXX_FLAGS_DEBUG_INIT "${cflags}" CACHE INTERNAL "Initial C++ compiler flags")
set(CMAKE_CXX_FLAGS_RELEASE_INIT "${cflags}" CACHE INTERNAL "Initial C++ compiler flags")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "${cflags}" CACHE INTERNAL "Initial C++ compiler flags")
set(CMAKE_C_FLAGS_INIT "${cflags}" CACHE INTERNAL "Initial C compiler flags")
set(CMAKE_C_FLAGS_DEBUG_INIT "${cflags}" CACHE INTERNAL "Initial C compiler flags")
set(CMAKE_C_FLAGS_RELEASE_INIT "${cflags}" CACHE INTERNAL "Initial C compiler flags")
set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "${cflags}" CACHE INTERNAL "Initial C compiler flags")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,-Ttext,${RTEMS_RELOCADDR}" CACHE INTERNAL "C linker flags")
set(CMAKE_FIND_ROOT_PATH "${include}")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
endif(match_rtems)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
endif(CROSS)