适用于 macOS 的 CMake。如何根据我的默认 Xcode 框架设置 isysroot 变量

问题描述 投票:0回答:1

在我基于 CMake 的 macOS 项目中,未设置参数 CMAKE_OSX_SYSROOT,我希望获得也在 Xcode 构建器中使用的默认框架:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk

但是,默认值是

macosx
,并且在构建命令中无法将其链接到默认的sysroot,并且我收到以下编译错误
c++: warning: no such sysroot directory: 'macosx' [-Wmissing-sysroot]

知道如何让 CMake 在默认情况下选择默认的 sysroot 吗?

c++ macos cmake
1个回答
0
投票

这是我尝试重现您的问题,但效果很好:

CMakeLists.txt

cmake_minimum_required(VERSION 3.28)

set(CMAKE_OSX_DEPLOYMENT_TARGET 11)

project(MyTestSysRoot LANGUAGES CXX)

add_executable(test_app main.cpp)

message(STATUS "CMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT}")

结果:

% cmake --version
cmake version 3.31.0

CMake suite maintained and supported by Kitware (kitware.com/cmake).

% cmake -G Xcode -S . -B build
-- The CXX compiler identification is AppleClang 16.0.0.16000026
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- CMAKE_OSX_SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk
-- Configuring done (11.8s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/marekruszczak/repos/stackoverflow/cmake_macos_sysroot/build
© www.soinside.com 2019 - 2024. All rights reserved.