You should have a look at CMake. It uses a simple language to define projects in text files and then generates the native project files for your environment (eg XCode).
Assuming your project structure looks like this:
myproject/
MyProject.h
MyProject.cpp
main.cpp
MyGui.ui
Add the following as CMakeLists.txt
in the same directory:
cmake_mimimum_required( VERSION 2.8)
project( MyProject )
find_package( Qt4 COMPONENTS QtGui <insert components you need> REQUIRED)
include( ${QT_USE_FILE} )
# Qt's includes are already taken care of by the previous command
# add any additionaly include directories if required
# include "binary" dir to make sure the automatically generated files (eg for gui class) are found
include_directories( ${CMAKE_CURRENT_BINARY_DIR} )
# assuming MyProject contains a Q_OBJECT that needs to be processed by moc
QT4_WRAP_CPP( MOCS MyProject.h )
QT4_WRAP_UI( UI MyGui.ui )
add_executable( MyProject
MyProject.cpp
MyProject.h
${MOCS}
${UI}
)
target_link_libraries( MyProject ${QT_LIBRARIES} )
Create the "binary" directory. This directory will contain your XCode files and any files that are generated during the project (compiled objects etc). Thus, CMake allows easy separation of generated files from your source code so it doesn't mess up your source control.
In the binary directory, call:
cmake -G XCode <path to your source directory (where CMakeLists.txt is)>
You could also use the GUI tool CMake-Gui
or console gui ccmake
.
After cmake finished generating the project files, open them in XCode.
For more details, check the CMake documentation
Happy coding!
(Disclaimer: Code is untested.)