Issue
If you have an Xcode project and want to add a file (say test.txt) to the project, you simply just drag and drop the file into the Xcode project and are asked if you want to "Copy items if needed" (which in this case I would do). Then you can access the file with:
[[NSBundle mainBundle] pathForResource:@"test" ofType:@"txt"];
Now with a Xcode project created via CMake (via CMakeLists.txt), how do I do the same thing? That is, have the test.txt file available inside the Xcode project just as if I did with the above method. Bonus points if you can make a group (AKA folder) show up inside of the Xcode project with the file inside.
Solution
I typically add it as a Resource, but you could also just add it as a regular ol' source file:
# This will be our group of resource files
set(project_RESOURCE_FILES
test.txt
)
# Set properties for this group of files
set_source_files_properties(
${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}
}
Answered By - Cinder Biscuits Answer Checked By - Mary Flores (WPSolving Volunteer)