Created
April 5, 2020 08:43
-
-
Save dodsonmg/b19442c8aa2a4eebe7e970a4768fe4d7 to your computer and use it in GitHub Desktop.
ROS Cross-Compile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Copyright (c) 2016 Alex Richardson | |
# All rights reserved. | |
# | |
# This software was developed by SRI International and the University of | |
# Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-10-C-0237 | |
# ("CTSRD"), as part of the DARPA CRASH research programme. | |
# | |
# Redistribution and use in source and binary forms, with or without | |
# modification, are permitted provided that the following conditions | |
# are met: | |
# 1. Redistributions of source code must retain the above copyright | |
# notice, this list of conditions and the following disclaimer. | |
# 2. Redistributions in binary form must reproduce the above copyright | |
# notice, this list of conditions and the following disclaimer in the | |
# documentation and/or other materials provided with the distribution. | |
# | |
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
# SUCH DAMAGE. | |
# | |
set(CMAKE_SYSTEM_NAME FreeBSD) | |
set(CMAKE_SYSTEM_VERSION "13.0") | |
set(CMAKE_SYSTEM_PROCESSOR "CHERI (MIPS IV compatible) with 128-bit capabilities") | |
if(CMAKE_VERSION VERSION_LESS "3.7") | |
message(FATAL_ERROR "This toolchain file requires CMake >= 3.7") | |
endif() | |
set(CHERI_SDK_BINDIR "/home/broomstick/cheri/output/sdk/bin") | |
# Allow compiler dir to be different from toolchain directory (e.g. LLVM build dir) | |
set(CHERI_COMPILER_BINDIR "/home/broomstick/cheri/output/sdk/bin") | |
set(CHERIBSD_SYSROOT "/home/broomstick/cheri/output/sdk/sysroot128") | |
# add the correct --sysroot: | |
# https://cmake.org/cmake/help/git-master/variable/CMAKE_SYSROOT.html | |
set(CMAKE_SYSROOT ${CHERIBSD_SYSROOT}) | |
# if("${CMAKE_SYSTEM_NAME}" STREQUAL "Generic") | |
set(CMAKE_AR "/home/broomstick/cheri/output/sdk/bin/ar" CACHE FILEPATH "ar") | |
set(CMAKE_RANLIB "/home/broomstick/cheri/output/sdk/bin/ranlib" CACHE FILEPATH "ranlib") | |
# endif() | |
# specify the cross compiler | |
set(CMAKE_C_COMPILER "/home/broomstick/cheri/output/sdk/bin/clang") | |
set(CMAKE_C_COMPILER_TARGET "mips64c128-unknown-freebsd13-purecap") | |
set(CMAKE_CXX_COMPILER "/home/broomstick/cheri/output/sdk/bin/clang++") | |
set(CMAKE_CXX_COMPILER_TARGET "mips64c128-unknown-freebsd13-purecap") | |
set(CMAKE_ASM_COMPILER "/home/broomstick/cheri/output/sdk/bin/clang") | |
set(CMAKE_ASM_COMPILER_TARGET "mips64c128-unknown-freebsd13-purecap") | |
# https://gitlab.kitware.com/cmake/cmake/issues/18575 | |
if (CMAKE_VERSION VERSION_LESS "3.13") | |
set(CMAKE_ASM_COMPILER_ID "Clang") # for some reason CMake doesn't detect this automatically | |
endif() | |
# FIXME: this doesn't work :( | |
# strip the version number from the triple to find the binutils | |
# if ("mips64c128-unknown-freebsd13-purecap" MATCHES "^(.+-freebsd)[0-9]*$") | |
# # These variables are used to find the binutils: (See CMakeFindBinUtils.cmake) | |
# set(_CMAKE_TOOLCHAIN_PREFIX "${CMAKE_MATCH_1}" CACHE INTERNAL "") | |
# message(WARNING _CMAKE_TOOLCHAIN_PREFIX=${_CMAKE_TOOLCHAIN_PREFIX}) | |
# #set(_CMAKE_TOOLCHAIN_SUFFIX "${CMAKE_MATCH_2}") | |
#endif() | |
#include(CMakeFindBinUtils) | |
set(CHERIBSD_COMMON_FLAGS "-target mips64c128-unknown-freebsd13-purecap -pipe --sysroot=/home/broomstick/cheri/output/sdk/sysroot128 -B/home/broomstick/cheri/output/sdk/bin -integrated-as -G0 -msoft-float -stdlib=libc++ -mcpu=beri -mabi=purecap -mcpu=beri -cheri=128 -cheri-cap-table-abi=pcrel -O0 -Wno-unused-command-line-argument -ggdb -Wall -Werror=cheri-capability-misuse -Werror=implicit-function-declaration -Werror=format -Werror=undefined-internal -Werror=incompatible-pointer-types -Werror=mips-cheri-prototypes -Werror=cheri-bitwise-operations -Werror=pass-failed") | |
set(CHERIBSD_LINK_FLAGS "-target mips64c128-unknown-freebsd13-purecap -pipe --sysroot=/home/broomstick/cheri/output/sdk/sysroot128 -B/home/broomstick/cheri/output/sdk/bin -integrated-as -G0 -msoft-float -stdlib=libc++ -mcpu=beri -mabi=purecap -mcpu=beri -cheri=128 -cheri-cap-table-abi=pcrel -fuse-ld=/home/broomstick/cheri/output/sdk/bin/ld.lld -Wl,--gdb-index") | |
# https://cmake.org/cmake/help/git-master/variable/CMAKE_TRY_COMPILE_PLATFORM_VARIABLES.html | |
set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CHERI_SDK_BINDIR CHERIBSD_SYSROOT CHERIBSD_COMMON_FLAGS CHERIBSD_LINK_FLAGS LIB_SUFFIX PKG_CONFIG_USE_CMAKE_PREFIX_PATH) | |
# CMake 3.7 has new variables that we can use to correctly initialize these flags | |
# https://cmake.org/cmake/help/git-master/release/3.7.html#variables | |
set(CMAKE_EXE_LINKER_FLAGS_INIT "${CHERIBSD_LINK_FLAGS}") | |
set(CMAKE_SHARED_LINKER_FLAGS_INIT "${CHERIBSD_LINK_FLAGS}") | |
set(CMAKE_MODULE_LINKER_FLAGS_INIT "${CHERIBSD_LINK_FLAGS}") | |
# These flags are passed to ar -> not what we want | |
# set(CMAKE_STATIC_LINKER_FLAGS_INIT "${CHERIBSD_LINK_FLAGS}") | |
set(CMAKE_C_FLAGS_INIT "${CHERIBSD_COMMON_FLAGS} ") | |
set(CMAKE_ASM_FLAGS_INIT "${CHERIBSD_COMMON_FLAGS} ") | |
set(CMAKE_CXX_FLAGS_INIT "${CHERIBSD_COMMON_FLAGS} ") | |
if(0) | |
# Don't let find modules find .so files | |
set(CMAKE_SHARED_LIBRARY_SUFFIX ".a") | |
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") | |
set(CMAKE_EXTRA_SHARED_LIBRARY_SUFFIXES ".a") | |
endif() | |
# where is the target environment | |
set(CMAKE_FIND_ROOT_PATH ${CHERIBSD_SYSROOT}) | |
# search in /usr/libcheri for CHERI target | |
# cheri libraries are found in /usr/libcheri: | |
if("${CMAKE_VERSION}" VERSION_LESS 3.9) | |
# message(STATUS "CMAKE < 3.9 HACK to find libcheri libraries") | |
# need to create a <sysroot>/usr/lib/cheri -> <sysroot>/usr/libcheri symlink | |
set(CMAKE_LIBRARY_ARCHITECTURE "cheri") | |
set(CMAKE_SYSTEM_LIBRARY_PATH "${CMAKE_FIND_ROOT_PATH}/usr/libcheri;${CMAKE_FIND_ROOT_PATH}/usr/local/cheri/lib;${CMAKE_FIND_ROOT_PATH}/usr/local/cheri/libcheri") | |
else() | |
set(CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX "cheri") | |
endif() | |
set(LIB_SUFFIX "cheri" CACHE INTERNAL "") | |
# search for programs in the build host directories | |
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH FALSE) | |
# PKG_CONFIG_LIBDIR overrides PKG_CONFIG_PATH | |
set(PKG_CONFIG_LIBDIR "/home/broomstick/cheri/output/sdk/sysroot128/usr/libcheri/pkgconfig:/home/broomstick/cheri/output/sdk/sysroot128/usr/local/cheri/lib/pkgconfig:/home/broomstick/cheri/output/sdk/sysroot128/usr/local/cheri/libcheri/pkgconfig") | |
set(ENV{PKG_CONFIG_LIBDIR} "/home/broomstick/cheri/output/sdk/sysroot128/usr/libcheri/pkgconfig:/home/broomstick/cheri/output/sdk/sysroot128/usr/local/cheri/lib/pkgconfig:/home/broomstick/cheri/output/sdk/sysroot128/usr/local/cheri/libcheri/pkgconfig") | |
set(PKG_CONFIG_SYSROOT_DIR ${CHERIBSD_SYSROOT}) | |
set(ENV{PKG_CONFIG_SYSROOT_DIR} ${CHERIBSD_SYSROOT}) | |
set(PKG_CONFIG_PATH "") | |
set(ENV{PKG_CONFIG_PATH} "") | |
# Use -pthread flag https://gitlab.kitware.com/cmake/cmake/issues/16920 | |
set(THREADS_HAVE_PTHREAD_ARG TRUE) | |
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) | |
# For some reason ranlib doesn't like our static libraries: | |
# /build/ctsrd/sdk256/bin/mips64-unknown-freebsd-ranlib: libcmTC_1737a.a: | |
# File format is ambiguous | |
# /build/ctsrd/sdk256/bin/mips64-unknown-freebsd-ranlib: Matching formats: | |
# elf64-tradbigmips ecoff-bigmips ecoff-littlemips | |
# As it is not required we can simply use : instead | |
# set(CMAKE_RANLIB ":") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment