Working with CMake and Xcode: keep project changes when CMakeLists.txt is modified Working with CMake and Xcode: keep project changes when CMakeLists.txt is modified xcode xcode

Working with CMake and Xcode: keep project changes when CMakeLists.txt is modified


I think you are going to lose this one. Xcode stores all the project definitions in a file called Foo.xcodeproj/project.pbxproj. When one of your Mac developers changes a flag or setting, it's recorded in the project.pbxproj file. When you change your CMakeLists.txt file, CMake triggers a rebuild of project.pbxproj, wiping out all the Mac developer's changes. Xcode was not designed with CMake in mind, and they two work only so well together.

One possible solution (which isn't the greatest for the Mac developers) is to use CMake to generate makefiles. They would need to write a few custom commands in Xcode which invoke CMake/Make to build the executables, but they would be able to pass arguments into CMake to control the build process. The executables would be defined separately to Xcode, and CMake would only wipe out the Makefiles. This might be a way to keep everyone happy.

The CMake folks have not given Xcode the attention it deserves, IMHO. But this limitation is inherent in Xcode's architecture, and will be a tough nut.

Hope this helps,
-dan

Edit:

Your Xcode developers have some limited ability to use "User-Defined Settings". I don't know to how to use these (I'm an emacs/make-sort of guy), but perhaps they could use these to override CMake's settings.


You can add a target which runs the program by add_custom_target(foobar COMMAND foo --bar DEPENDS foo). You can also call a script instead of the program, where it is easy to set environment variables (I use this setup under Win32 to tweak paths in VC). This script could also be a template in the VCS, so each developer has an own version of the script with the actual command line parameters.


Xcode developers will use the executable that appears under the Executables list of the Group & Files window of Xcode. They will configure it by double-clicking and add their tweaks (configuring debugging directories, setting environment variables, but more importantly, setting the arguments of the executable).

For recent versions of Cmake, many of the settings in Xcode's scheme settings can be set externally in Cmake, without navigating through Xcode:

XCODE_SCHEME_ARGUMENTSXCODE_SCHEME_DEBUG_AS_ROOTXCODE_SCHEME_DEBUG_DOCUMENT_VERSIONINGXCODE_SCHEME_ENVIRONMENTXCODE_SCHEME_EXECUTABLEXCODE_SCHEME_WORKING_DIRECTORY

To set something for all targets, Prepend CMAKE_ to the variables above and it will become global.

It's mandatory to set CMAKE_XCODE_GENERATE_SCHEME to true for the variables above to take effect.

https://cmake.org/cmake/help/latest/prop_tgt/XCODE_GENERATE_SCHEME.html#prop_tgt:XCODE_GENERATE_SCHEME