Quotations in ctest scripts and proper usage of MPIEXEC_PREFLAGS

I use MPIEXEC_PREFLAGS when adding a test as described in the FindMPI documentation. For example:

add_test( 
  NAME mytest 
  COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 4
  ${MPIEXEC_PREFLAGS} mytest ${MPIEXEC_POSTFLAGS}
)

When configuring with -D MPIEXEC_PREFLAGS="--bind-to none" I find that the test command above fails because the following command is generated:

mpiexec "-n" "4" "--bind-to none" mytest

and "--bind-to none" is the point of failure. What does work is -D MPIEXEC_PREFLAGS="--bind-to;none" which generates the following command:

mpiexec "-n" "4" "--bind-to" "none" mytest

Note that "--bind-to none" is now "--bind-to" "none".

This issue is further complicated in the context of CI when setting the CTEST_CONFIGURE_COMMAND in my ctest script. The closest I’ve cometo getting it right is:

set(CTEST_CONFIGURE_COMMAND "cmake -D MPIEXEC_PREFLAGS=\"--bind-to;none\""

which gives the following output when running `ctest -VV -S myscript.cmake:

Configure with command: cmake -D MPIEXEC_PREFLAGS="--bind-to;none"
Run command:  "cmake" "-D" "MPIEXEC_PREFLAGS="--bind-to;none""

First, I wonder if I should use MPIEXEC_PREFLAGS this way - I don’t see any strict guidance in the documentation on how to use the variable.

If I am using it (and not abusing it), then how do I fix the quotation nightmare?

Thanks!

Hmm. I think those are generally filled out by FindMPI. They’re supposed to be lists. Does this work?

set(CTEST_CONFIGURE_COMMAND "cmake -D MPIEXEC_PREFLAGS=--bind-to;none")

That doesn’t work either the run command winds up being:

"cmake" "-D" "MPIEXEC_PREFLAGS=--bind-to;none"

Escaping of the ; may be necessary here. My guidance for these quoting issues is usually to follow the value through all the layers to see where escaping is necessary or messing other things up. It’s hard to give a specific answer without knowing everywhere the string ends up existing (here, probably something like YAML → shell → CMake script → CMake command line → CMake code → command list in add_custom_command and/or add_testCTestTestfile → final shell).