xcodebuild -list can not find scheme which existed - xcode

I have xcode project, I want to build this project under command line, this project composed many sub-project, first I fetch these source files to local disk, I use xcodebuild -list to find scheme, I can not find anything, while after I manually open this project with xcode and then use xcodebuild -list to find scheme, some scheme can be seen.
I compare the project file of these two scenario, for the second project, there existed xcuserdata folder, so I can find the scheme, the problem I need use scheme to build this project.
Any suggestion will be appreciated.

I've found that for -scheme builds to work correctly you need to have the project.xcworkspace/ directory in place within the .xcodeproj directory. The project.xcworkspace/ directory should have a contents.xcworkspacedata file within it.
In my case, the project.xcworkspace/ directory wasn't it the git repository because it wasn't previously necessary so I had *.xcworkspace in my .gitignore file.

check the file .xcodeproj/xcuserdata/.xcuserdatad/xcschemes exists,if not open *.xcodeproj and the file will be created by xcode,then get the current Schemes from xcodebuild -list

Related

Create XCode workspace and pin a project from command line

I found that it is possible to create XCode project from command line with a help of CMake (are there any other options?). Is there any tool to create XCode workspace and pin projects into it?
If not, can I create it manually? My current version of XCode (7.3 beta) makes a workspace that consists of below file structure:
WORKSPACE_NAME.xcworkspace/
contents.xcworkspacedata
xcuserdata/
USER_NAME.xcuserdatad/
UserInterfaceState.xcuserstate
Content of contents.xcworkspacedata looks straightforward and I guess this is the file that pins projects into workspace.
UserInterfaceState.xcuserstate is a binary file that can be generated when workspace is opened in XCode.
Summing up, if there is no command line tool for creating workspace and pinning projects into it, can I just generate proper contents.xcworkspacedata file or should I do something more?
If your project has a CMakeLists.txt file, CMake can generate an XCode project file from it (on the command line), and you can then build it as well (from the command line).
Assuming you are currently in your project's source directory and it contains a CMakeLists.txt:
$ mkdir build && cd build
$ cmake -G "Xcode" ../
$ cmake --build .
Alternatively you can remove the -G option, it'll then generate a Makefile, and then you can do make and it will build on the command-line too, using the Xcode build tools.

iOS: Absolute project path with xcodebuild

I use following command to build project using xcodebuild from the directory where .xcodeproj is.
admin$ xcodebuild install DSTROOT=. INSTALL_PATH=/bin
Could someone please tell me how to specify full path of .xcodeproj in xcodebuild command and run it from anywhere?
[EDIT]
...so you cannot specify absolute path of the project with xcodebuild command but you can specify where do you want your .app file placed like following. You need to run this command from the root project directory and you will be able to compile other sub projects without CD to their directories but you need to specify "scheme" that you are building.
admin$ xcodebuild install DSTROOT=/Users/admin/myProjectRoot INSTALL_PATH=/bin -scheme MySubProject1 -configuration Release -sdk iphonesimulator clean build
According to the manpage for xcodebuild, you must launch "xcodebuild" from within the directory where your project is. I.E. the specific line that clarifies that is:
To build an Xcode project, run xcodebuild from the directory
containing your project (i.e. the directory containing the
projectname.xcodeproj package).
And if there are multiple projects within that directory, that's when you can use the "-project projectname" command line parameter.
In my own build scripts, I "cd" to the folder where the project lives before calling "xcodebuild".

Where does xcode resolve "$(BUILT_PRODUCTS_DIR) to on my system?

When Compiling for iPhone Simulator with Xcode 4.2, if I place
"$(BUILT_PRODUCTS_DIR)"
in
Build Settings / Header search paths / Debug
and exit editing I can see it resolves to:
"build/Debug-iphoneos"
Where should this be on my system? I have looked in:
Library/Developer/Xcode/DerivedData/{Project Name}/Build
but I can't find a file called build that contains a folder called Debug-iphoneos.
On my system, compiling an OSX project, that resolves to an absolute path:
BUILT_PRODUCTS_DIR /Users/andy/Source/MyProject/build/Debug
There are so many Xcode build variables that I keep a text file with a sample list of them which I got from executing a custom build script and viewing the output within the log tab.
If your code is going into the Library folder, then that is hidden under Lion. You can unhide it from the command line (Terminal) using:
$ cd ~
$ chflags nohidden Library
You should then be able to see its content.
Another tip: I have a ~/tmp folder where I let temporary stuff accumulate and I have set my Xcode preferences to put DerivedData and Archives into that folder so I can:
delete it now and again (I don't like temporary stuff accumulating where I cannot control it).
see it for packaging pre-release Archived project to testers.

Best build dir location to use in Xcode

I'm consolidating my Xcode/TextMate setup and is interested in where you put your build dir.
Some years ago I started out having the build dir in the same dir as my xcodeproj file.
However it became a mess when my project became a multi project with a applications and frameworks and tests, so I started using ../build as the build dir, so that all the sub projects used the same dir. However Spotlight is indexing this build dir and TextMate's global find is unusable when there is a build dir in the project.
I'm thinking either using ~/.build or /build as Xcode's build dir.
What build dir do you use and why?
If you let Xcode create the build directory then it shouldn't get indexed by Spotlight (Xcode sets an extended attribute on the directory specifically to make this happen). If it's a build directory from an old project that been upgraded, or a build directory that you created manually, then this won't be the case and it will get indexed. You can either add this attribute manually if it's missing, or perhaps delete the build directory and let Xcode re-create it. Once you have this sorted out you should be good to go with your common build folder scheme.
The extended attribute is com.apple.XcodeGenerated.

CMake, Xcode and Unix Makefile

I was using classic Unix Makefile generator until I found a webpage explaining CMake could produce a nice xcode project file using "cmake -G Xcode" so I ran that command in my source directory and I get a nice xcode project. This is great but I'm facing some drawback and was wondering if there are solutions to these :
now I can't build out of tree using unix makefiles (I use to run cmake ../myproj in a build dir and then make command) this doesn't work anymore (I suppose temp files in the project dir are responsible)
some of my headers are generated by cmake (myproj.h.in became myproj.h and is include in some tests for example) but I can't find those files in the xcode project I get.
Thanks in advance for any good advice on how I can combine xcode project and unix makefile to be able to use both.
I found the answer by myself (I mean asking the good person) :
Use 2 separate build directories for each type of build files. This will ensure each build directory has the correct build files and generated files for its use.
In the add_executable() command, in addition to the source files also include the headers and generated headers for those to show up in Xcode.
You can use xcodebuild to still have a proper Xcode project and build it from the command line/shell script/Makefile, e.g.
xcodebuild -project MyProject.xcodeproj -target MyTarget -configuration Release

Resources