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.
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}
}
Related
Whenever I set my build options in Qt for a specific folder and I compile using MVSC it creates a release and debug folder and puts the output exe file inside that folder. If I compile in linux it usually just puts the final executable file in the folder that I specify. Is there a way to get this last behaviour (that is to stop the creation release and debug folder)?
You can set CONFIG -= debug_and_release in your .pro file and it will stop doing so.
With qmake you can actually specify a destination directory for your binary(ies), and other generated output as well. For example:
DESTDIR = $${OUT_PWD}/bin # this is where the binaries ('target' files) go
OBJECTS_DIR = $${OUT_PWD}/obj # compiled objects
MOC_DIR = $${OUT_PWD}/moc # generated MOC files
UI_DIR = $${OUT_PWD}/ui # generated C++ code from .ui files
RCC_DIR = $${OUT_PWD}/rcc # generated C++ code from .qrc files
OUT_PWD is a built-in variable specifying the current build directory. You could actually use any valid path here.
Reference: http://doc.qt.io/qt-5/qmake-variable-reference.html
I have a Xamarin.Forms GetFiles.IOS project that has a "Resources" directory that's part of the project. I have placed 25 files into the Resources Directory. I now want to be able to go to the resource directory and get all the file names. I created some code to read the files in the directory but I'm getting a DirectoryNotFoundException. Here's the code I'm using.
String dir = Directory.GetCurrentDirectory();
var filePath = Path.Combine(dir,"Resources");
String[] files = Directory.GetFiles(filePath);
I just can't seem to get the path correct!
Thank you for helping me.
There are two things necessary to have the files be copied into the app folder:
They need to be set with Build Action Content with Copy to Output Directory Copy Always in the Properties window.
They must be in a different custom folder than Resources.
Number 2. is because Resources is a special reserved directory name and even if you put some content files in it, it is never copied in the app bundle's folder. You can check for yourself, if you put the files in a folder Test, your code will work as intended.
I'm attempting to write a Ruby script that will delete certain files from the Xcode project. I can find the files based on the absolute path and remove them from the project using the remove_from_project method of PBXFileReference. However this leaves source files (e.g. .m or .swift files) in the "Compile Sources" build phase of whatever target(s) it is a member of, but without a name.
I know I need to also remove the file from the target(s) but there seems to be no easy link between a PBXFileReference and a target (PBXNativeTarget).
From what I can make out I need to iterate through each of the project's targets, then iterate through the files or files_references of that target's source_build_phase looking for the PBXFileReference I already have.
Is this correct or am I missing some obvious link such e.g. file_ref.target_memberships?
if (object.is_a?(Xcodeproj::Project::Object::PBXFileReference))
if (!object.real_path.exist?)
object.remove_from_project
end
end
project.save(project_path)
Not sure when this was introduced, but as of xcodeproj version 1.15.0, you can can get the build files associated with a file reference with:
file_ref.build_files
From the documentation:
Method: Xcodeproj::Project::Object::PBXFileReference#build_files
#build_files ⇒ Array<PBXBuildFile>
Returns the build files associated with the current file reference.
Returns:
(Array<PBXBuildFile>) — the build files associated with the current file reference.
Seems like this should do the trick:
file_ref.build_files.each { |file| file.remove_from_project }
I have created a Sub project which just prints "Hello World". My goal is to create a C file inside the same subproject but within a folder named "src", also I want to create a H file within a folder named "include".
The H file contains only one function declaration "void printContent();" and the C file contains its definition which prints "Hello Buddy".
I added the C file inside the Source Files section of Sub project and added the H file inside the Header File Section, but when I compile the subproject and try to deploy it on to an emulator, I got an error.
BUILD: [01:0000000047:ERRORE] NMAKE : U1073: don't know how to make 'obj\ARMV4I\debug\content.obj'
I tried to configure the subproject by providing the below lines in the sources file of every Sub project.
INCLUDES= include/
But nothing changed and the problem still persists.
In wince subproject, sub folders are treated differently in the source file layout.
Rule No.1 You can't have both source and dirs files in the same folder.
So you either use one folder, or use several sub folders, then the root folder is clean and have one dirs file and several folders, no source file.
Rule No. 2 Each sub folder should have both source and makefile
You can copy and then edit the source file, the makefile will always be the same.
Ok, if you are going to use subfolder just to make the folder structure cleaner, my suggestion is that you create 2 subprojects, one is the main subproject; the other includes all your src files and its type is set to be static library. Then you can link to the static .lib file just as you are including them as in a subfolder. Of cource you need to set the additional include folder and input library.
I'm getting a compile error in XCode where a file that I've removed from the project is showing up as a Duplicate Interface definition for class 'class_name' and it shows the hierarchy of dependencies and ultimately arrives at the header file of the class in question. But that header file doesn't actually exist in the project hierarchy. In the file location section above the header file's code it just shows class_name.h > #interface class_name rather than every other file in the project: project_name > group_name > class_name.h > No Selection
Doing a search for this object type (cmd+shift+O) and global search turn up no instance of this header file existing in the project. I've cleaned, exited xcode, rebooted, even checked the proj file for instances of this class, but it's not there.
I had the path to the old location of my class in my project's "Header Search Paths" so it was seeing the file twice.
First step: properly manage your xcode Header Search Path, delete the unused old Search path
Second step: choose product-->clean