toolchain-raspberry.cmake 3.18 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
############################################################################
# toolchain-raspberry.cmake
# Copyright (C) 2014  Belledonne Communications, Grenoble France
#
############################################################################
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 21 22
#
############################################################################

23 24 25 26 27 28 29 30 31 32
if("$ENV{RASPBERRY_VERSION}" STREQUAL "")
	set(RASPBERRY_VERSION 1)
else()
	if($ENV{RASPBERRY_VERSION} VERSION_GREATER 3)
		set(RASPBERRY_VERSION 3)
	else()
		set(RASPBERRY_VERSION $ENV{RASPBERRY_VERSION})
	endif()
endif()

33 34 35 36 37
if("$ENV{RASPBIAN_ROOTFS}" STREQUAL "")
	message(FATAL_ERROR "Define the RASPBIAN_ROOTFS environment variable to point to the raspbian rootfs.")
else()
	set(SYSROOT_PATH "$ENV{RASPBIAN_ROOTFS}")
endif()
38
set(TOOLCHAIN_HOST "arm-linux-gnueabihf")
39 40 41

message(STATUS "Using sysroot path: ${SYSROOT_PATH}")

42 43 44 45 46 47 48
set(TOOLCHAIN_CC "${TOOLCHAIN_HOST}-gcc")
set(TOOLCHAIN_CXX "${TOOLCHAIN_HOST}-g++")
set(TOOLCHAIN_LD "${TOOLCHAIN_HOST}-ld")
set(TOOLCHAIN_AR "${TOOLCHAIN_HOST}-ar")
set(TOOLCHAIN_RANLIB "${TOOLCHAIN_HOST}-ranlib")
set(TOOLCHAIN_STRIP "${TOOLCHAIN_HOST}-strip")
set(TOOLCHAIN_NM "${TOOLCHAIN_HOST}-nm")
49 50

set(CMAKE_CROSSCOMPILING TRUE)
51
set(CMAKE_SYSROOT "${SYSROOT_PATH}")
52 53 54

# Define name of the target system
set(CMAKE_SYSTEM_NAME "Linux")
55 56 57 58 59
if(RASPBERRY_VERSION VERSION_GREATER 1)
	set(CMAKE_SYSTEM_PROCESSOR "armv7")
else()
	set(CMAKE_SYSTEM_PROCESSOR "arm")
endif()
60 61

# Define the compiler
62 63
set(CMAKE_C_COMPILER ${TOOLCHAIN_CC})
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_CXX})
64
if(RASPBERRY_VERSION VERSION_GREATER 2)
65
	set(CMAKE_C_FLAGS "-mcpu=cortex-a53 -mfpu=vfp -mfloat-abi=hard" CACHE STRING "Flags for Raspberry PI 3")
66 67
	set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "Flags for Raspberry PI 3")
elseif(RASPBERRY_VERSION VERSION_GREATER 1)
68
	set(CMAKE_C_FLAGS "-mcpu=cortex-a7 -mfpu=vfp -mfloat-abi=hard" CACHE STRING "Flags for Raspberry PI 2")
69 70 71 72 73
	set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "Flags for Raspberry PI 2")
else()
	set(CMAKE_C_FLAGS "-mcpu=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard" CACHE STRING "Flags for Raspberry PI 1 B+")
	set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "Flags for Raspberry PI 1 B+")
endif()
74

75
set(CMAKE_FIND_ROOT_PATH "${CMAKE_INSTALL_PREFIX}" "${CMAKE_SYSROOT}")
76 77 78 79 80 81

# search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
82 83
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)