我正在开发访问相机的应用程序。该项目是用C ++编写的,我正在使用CMake对其进行打包。
要在Mac中部署项目,请使用以下命令,然后在Xcode中打开项目:
cmake -G Xcode ../src
直到最后一次更新,它开始抱怨:
[access] This app has crashed because it attempted to access
privacy-sensitive data without a usage description. The app's
Info.plist must contain an NSCameraUsageDescription key with
a string value explaining to the user how the app uses this data.
Program ended with exit code: 9
因此,我创建了一个新的Info.plist文件,其内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
<key>CFBundleIconFile</key>
<string></string>
<key>NSCameraUsageDescription</key>
<string>This app requires to access your camera
to retrieve images and perform the demo</string>
</dict>
</plist>
我的问题是:我应该在CMakeLists.txt中添加什么以将该文件放入正确的位置?并且... cmake -G Xcode
是否有可能在Xcode项目中正确包含它?
编辑,我尝试以下建议:
# Compile files:
add_executable(fpv
main.cpp
files.cpp
files.hpp
more-files.cpp
more-files.hpp
)
# Link files:
target_link_libraries(fpv
fpv-lib
${GTKMM_LIBRARIES}
${OpenCV_LIBS} )
# Lets bundle it:
set_target_properties(fpv PROPERTIES
FRAMEWORK TRUE
FRAMEWORK_VERSION C
MACOSX_FRAMEWORK_IDENTIFIER com.cmake.dynamicFramework
MACOSX_FRAMEWORK_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist
# "current version" in semantic format in Mach-O binary file
VERSION 16.4.0
# "compatibility version" in semantic format in Mach-O binary file
SOVERSION 1.0.0
# XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Jean-Michel Gonet"
)
编辑为了确保Info.plist是正确的,我在Xcode项目中手动添加了它:
然后它起作用了。
但是我仍然想在CMake中进行项目配置。
答案 0 :(得分:0)
Cmake的官方文档(请参阅cmake-properties-7)提到了 MACOSX 目标属性的2个系列:
FRAMEWORK
,FRAMEWORK_VERSION
和MACOSX_FRAMEWORK_INFO_PLIST
MACOSX_BUNDLE_INFO_PLIST
和MACOSX_BUNDLE
现在,Info.plist
的包含由后者的 Bundle 系列管理。
要获得一个完整的示例,假设您的应用程序名为 fpv ,目录结构为:
/src <-- Root folder
/lib <-- There you may add sources for your application's library
CMakeLists.txt <-- Library has its own configuration
more-files.cpp
lots-of-files.cpp
etc.cpp
...
/app <-- This is where executable resides
CMakeLists.txt <-- This is where you need to configure the bundle
Info.plist <-- I've placed the plist file just besides.
main.cpp
second.cpp
more.cpp
这是您应用程序的CMakeLists.txt
的样子:
# src/app
project( fpv )
# GTKMM has to be linked/included via pkg_config:
find_package(PkgConfig)
pkg_check_modules(GTKMM gtkmm-3.0) # Defines variables GTKMM_INCLUDE_DIRS, GTKMM_LIBRARY_DIRS and GTKMM_LIBRARIES.
link_directories( ${GTKMM_LIBRARY_DIRS} )
include_directories( ${GTKMM_INCLUDE_DIRS} )
# OpenCV can be linked as usual:
find_package( OpenCV REQUIRED )
# Compile files:
add_executable(fpv
main.cpp
main-window.cpp
main-window.hpp
auto-viseur.cpp
auto-viseur.hpp
)
# Link files:
target_link_libraries(fpv
fpv-lib
${GTKMM_LIBRARIES}
${OpenCV_LIBS} )
# Lets bundle it:
set_target_properties(fpv PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist
)
要构建XCode项目,请在主xcode
文件夹旁边创建一个src
文件夹:
mkdir xcode
cd xcode
cmake -G Xcode ../src
现在您可以从 Xcode 将其作为项目打开。要以调试模式执行:
Info.plist
文件视为资源