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

Viewed 12209

First of all, I've never developed with Xcode. I have a project that has been developed by me under a certain environment (Linux and emacs) and now some colleagues that use a different environment will work with me. This is a C++ project that uses CMake.

Long story short:

  • I use Linux/emacs. Other developers use mac/Xcode.
  • I use the GNU Makefiles generator. They use Xcode generator.
  • Everything seemed to work ok.

The problem

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).

When a developer (me) changes the CMakeLists.txt (namely to add a new source file), the XCode developers are forced to re-generate their project and they lose all the configuration mentioned above.

Question: Is there a way to avoid this?

If each Xcode developer constantly loses that configuration I would certainly be the only one using CMake. :(

Thanks for your help!

3 Answers

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_ARGUMENTS
XCODE_SCHEME_DEBUG_AS_ROOT
XCODE_SCHEME_DEBUG_DOCUMENT_VERSIONING
XCODE_SCHEME_ENVIRONMENT
XCODE_SCHEME_EXECUTABLE
XCODE_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

Related