How to use XCODE_SCHEME_ARGUMENTS?

How do I set this property to specify some default arguments for an executable when using the Xcode generator?

I have something like this:

add_executable (test test.c ...)
if (CMAKE_GENERATOR MATCHES "Xcode")
    set_property (TARGET test PROPERTY XCODE_SCHEME_ARGUMENTS "blah")
endif ()

If I open Xcode and select “Edit Scheme…” for this target, it doesn’t seem to have any effect (default arguments are empty).

No need to test if CMAKE_GENERATOR matches Xcode since other generators will ignore the XCODE_SCHEME_... properties.

I’d also recommend not calling your executable target “test”, since this will conflict with a target that CMake will create when enable_testing() has been called.

Do you enable schema creation? To do that, you would need to either set the CMAKE_XCODE_GENERATE_SCHEME variable or else set XCODE_GENERATE_SCHEME on each target.

Ah, the name “test” is just a placeholder I came up with for this post. The actual target name is “basic_solve”.

I do not enable schema creation. I checked the docs for XCODE_GENERATE_SCHEME, but I’m not well-versed enough with CMake to know how to proceed.

In your top level CMakeLists.txt file, you probably want something like this:

set(CMAKE_XCODE_GENERATE_SCHEME TRUE)

Try adding that to your project and see if that causes the arguments to then appear. Not sure if you will need to wipe your existing build directory or not (probably not, but something to try if it doesn’t seem to work initially).

That works! Thanks a lot for the speedy assistance, Craig.

I also found that by passing the arguments as separate strings, I was able to have the arguments populate as separate entries under Xcode. E.g., calling:

set_property (TARGET basic_solve PROPERTY XCODE_SCHEME_ARGUMENTS "blah" "hello")

results in the following:

Screen Shot 2020-12-09 at 4.45.15 PM