My question is somewhat similar to this SO but not the same.
I created a HelloWorld
program with the following:
add_executable( HelloWorld ${SRC} )
When I generate a project file (for example a Visual Studio .sln file, or an XCode .xcodeproj file). I want to hit the run button and pass in some command line arguments to HelloWorld
when it executes the program, like the following:
./HelloWorld --gtest_filter=Test_Cases1*
Also see this SO for how this is done in Visual Studio.
Is it possible to do this in CMakeList file? If not, why?
This answer was written before CMake 3.13 was released, so it's now outdated. There is an answer showing solution with CMake 3.13+ also available.
CMake 3.12 and below has no built-in support for this. The reason is that the settings from the Debugging
tab of Visual Studio Project properties are not stored in the project file (.vc[x]proj
), but in a user-and-machine-specific .user
file, and CMake does not generate these.
You can code it yourself in CMake (I did that for our framework at work). The file is just XML, so you can pre-populate it according to your needs. Its structure is pretty easy to understand. The command-line arguments for the program being debugged are stored in the CommandArguments
attribute inside a <DebugSettings>
XML element (nested in <Configurations><Configuration>
), for example.