如果您有Xcode项目,并想向该项目添加文件(例如test.txt),则只需将文件拖放到Xcode项目中,然后询问您是否要“如果需要,复制项目”(在这种情况下我会做)。然后,您可以通过以下方式访问文件:
[[NSBundle mainBundle] pathForResource:@"test" ofType:@"txt"];
现在,有了通过CMake创建的Xcode项目(通过CMakeLists.txt),我该怎么做?也就是说,就像我使用上述方法一样,在Xcode项目中提供test.txt文件。如果可以使一个组(AKA文件夹)显示在Xcode项目内部,并且包含文件,则可以得到加分。
我通常将其添加为资源,但您也可以将其添加为常规的源文件:
# This will be our group of resource files
set(project_RESOURCE_FILES
test.txt
)
# Set properties for this group of files
set_source_file_proerties(
${project_RESOURCE_FILES}
PROPERTIES
HEADER_FILE_ONLY TRUE # Since it's just a text file, it doesn't need compiled
#MACOSX_PACKAGE_LOCATION Resource <- only do this if you need to copy the file!
)
# Bonus points unlocked :)
source_group(
"Resources" FILES ${project_RESOURCE_FILES}
)
# Append your resources to the source files you declared.
list(APPEND
project_SOURCE_FILES
${project_RESOURCE_FILES}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句