2016-11-08 51 views
0

如果你有一個Xcode項目,並想添加一個文件(說的test.txt)的項目,你只需只需將文件拖放到Xcode項目,並要求如果你想「如果需要複製項目」(在這種情況下,我會這樣做)。然後,您可以訪問該文件:添加文本文件的Xcode項目與CMakeList.txt

[[NSBundle mainBundle] pathForResource:@"test" ofType:@"txt"]; 
與(通過的CMakeLists.txt)通過CMake的創建Xcode項目

現在,我該怎麼做同樣的事情?也就是說,讓Xcode項目中的test.txt文件可用,就像我使用上述方法一樣。獎勵積分,如果你可以讓一個組(AKA文件夾)出現在Xcode項目裏面的文件裏面。

+0

我不知道有多少適用於Xcode的,但生成時Visual Studio項目是通過在創建目標時將文件簡單添加到源文件列表來完成的。然後可以使用'source_group'命令將文件放入文件夾中。 –

回答

2

我通常把它添加到作爲資源,但你也可以只將其添加爲一個普通的醇」源文件:

# 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} 
} 
相關問題