问题
Cmake is ad I'm trying to cross compile for raspberry pi 3+ on a Mac using cmake to generate a makefile. My CMakeLists.txt:
cmake_minimum_required (VERSION 3.11.0)
project(decatrack)
# setup cross toolchain for RPi 3
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(TOOLCHAIN_DIR /Volumes/xtool-build-env/armv8-rpi3-linux-gnueabihf)
set(CMAKE_C_COMPILER ${TOOLCHAIN_DIR}/bin/armv8-rpi3-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/bin/armv8-rpi3-linux-gnueabihf-g++)
set(CMAKE_SYSROOT ${TOOLCHAIN_DIR}/armv8-rpi3-linux-gnueabihf/sysroot)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
unset(CMAKE_OSX_DEPLOYMENT_TARGET
# c++ standerd
# force cc++03 standard
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -mcpu=cortex-a53 -mfloat-abi=hard -mfpu=neon-fp-armv8 -mneon-for-64bits -ggdb -O0 -ffunction-sections -fdata-sections -v -shared-libgcc")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(STATUS "Using C++11")
include_directories(
${TOOLCHAIN_DIR}/armv8-rpi3-linux-gnueabihf/sysroot/usr/include
${TOOLCHAIN_DIR}/armv8-rpi3-linux-gnueabihf/include/c++/6.3.0
${TOOLCHAIN_DIR}/armv8-rpi3-linux-gnueabihf/include/c++/6.3.0/backward
${TOOLCHAIN_DIR}/lib/gcc/armv8-rpi3-linux-gnueabihf/6.3.0/include
${TOOLCHAIN_DIR}/lib/gcc/armv8-rpi3-linux-gnueabihf/6.3.0/include-fixed
${TOOLCHAIN_DIR}/armv8-rpi3-linux-gnueabihf/include
)
target_link_libraries (
${TOOLCHAIN_DIR}/armv8-rpi3-linux-gnueabihf/sysroot/lib/libpigpio.so
)
add_subdirectory(src)
The resulting flags.make file looks like this (you must scroll over to see the problem:
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.11
# compile CXX with /Volumes/xtool-build-env/armv8-rpi3-linux-gnueabihf/bin/armv8-rpi3-linux-gnueabihf-g++
CXX_FLAGS = -std=c++11 -mcpu=cortex-a53 -mfloat-abi=hard -mfpu=neon-fp-armv8 -mneon-for-64bits -ggdb -O0 -ffunction-sections -fdata-sections -v -shared-libgcc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -std=gnu++11
CXX_DEFINES =
CXX_INCLUDES = -I/Volumes/xtool-build-env/armv8-rpi3-linux-gnueabihf/armv8-rpi3-linux-gnueabihf/include/c++/6.3.0 -I/Volumes/xtool-build-env/armv8-rpi3-linux-gnueabihf/armv8-rpi3-linux-gnueabihf/include/c++/6.3.0/backward -I/Volumes/xtool-build-env/armv8-rpi3-linux-gnueabihf/lib/gcc/armv8-rpi3-linux-gnueabihf/6.3.0/include -I/Volumes/xtool-build-env/armv8-rpi3-linux-gnueabihf/lib/gcc/armv8-rpi3-linux-gnueabihf/6.3.0/include-fixed -I/Volumes/xtool-build-env/armv8-rpi3-linux-gnueabihf/armv8-rpi3-linux-gnueabihf/include
It added "-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk" and I cannot figure out how to stop it!!!
回答1:
I found a post that suggested to set CMAKE_OSX_SYSROOT to the sysroot of your cross-compiled project, and it worked! I added:
set(CMAKE_OSX_SYSROOT /Volumes/xtool-build-env/armv8-rpi3-linux-gnueabihf/armv8-rpi3-linux-gnueabihf/sysroot)
and all is good.
来源:https://stackoverflow.com/questions/52879026/cmake-cross-compile-on-macos-adds-macos-sdk-to-isysroot-in-flags-make