在MacOS上进行CMAKE交叉编译会在flags.make中将MacOS SDK添加到-isysroot [英] CMAKE cross compile on MacOS adds MacOS SDK to -isysroot in flags.make
问题描述
Cmake是广告我正在尝试使用cmake在Mac上针对树莓派3+进行交叉编译,以生成makefile.我的CMakeLists.txt:
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)
生成的flags.make文件如下所示(您必须滚动查看该问题:
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
它添加了"-isysroot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk",我不知道如何阻止它!
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!!!
推荐答案
我找到了一条建议将CMAKE_OSX_SYSROOT设置为交叉编译项目的sysroot的帖子,它可以正常工作!我加了:
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)
一切都很好.
这篇关于在MacOS上进行CMAKE交叉编译会在flags.make中将MacOS SDK添加到-isysroot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!