4

I am creating and building a c++ project using cmake from scratch.
The executable requires command line arguments.
I am specifying them in Visual studio.

Is it possible to specify them by default when cmake builds the project (in my CmakeLists.txt for example) ? So that I (or others) won't need to specify these arguments each time I build the project for the first time (I would want to just run the project without worrying about that but still can change them in visual studio of course if needed) ?

enter image description here

7
  • The principle with CMake is that it will regenerate the solution if something changes, so no, you must not manually change the solution. Still don't understand what the link is with command line arguments for an executable though. Commented Jan 2, 2019 at 11:30
  • Well I have to push arguments to the executable (basically a port number) and I am doing that in Visual studio after cmake has already built the project (from debugging options). I want to have a default port number that would be defined when cmake builds the project. When I get to visual studio, I will just have to run the project. You understand me better ? @MatthieuBrucher Commented Jan 2, 2019 at 11:32
  • What I mean is that what I want to achieve is like defining a default startup project in the solution (Instead of ALL_BUILD) by putting this in CmakeLists.txt : set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT projectname) Commented Jan 2, 2019 at 11:34
  • You can add config.h file (like here) and then add some additional instructions to CMakeLists.txt file (like here) and then use info from config.h file as default. Commented Jan 2, 2019 at 11:36
  • 1
    See my now undeleted answer then. Commented Jan 2, 2019 at 11:42

1 Answer 1

6

If you are using CMake 3.13 and above you can add the VS_DEBUGGER_COMMAND_ARGUMENTS property to your executable target in order specify those arguments.

Sign up to request clarification or add additional context in comments.

1 Comment

This is the line to add to CmakeLists.txt in case someone needs that : set_target_properties(TargetName PROPERTIES VS_DEBUGGER_COMMAND_ARGUMENTS "arg1 arg2 ... argN")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.