Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake "make run"

Tags:

I'm a little unsure of terminology in this problem domain, which is an issue when I try to search for things.

I'm using CMake for my build process. I'd like to make a Makefile target such that I can use make run to run a given process (specifically, the one I've just built with make). I realize I could just make a shell script, or just run the command by typing it out. If I was writing a Makefile myself, I'd do this like so:


run:
    ./path/to/binary

I don't ever write a Makefile myself, though - that's generated by cmake - and I'm not sure what to put in my CMakeLists.txt to get it to generate the desired make run target.

I've found the cmake command 'execute_process', but that doesn't seem to be what I'm after - I don't want to actually run anything during the build process.

Extra: In addition, I'd love to be able to do something like the following:


CMAKE_COMMAND_ADD_MAKEFILE_TARGET ( ${CMAKE_PROJECT_DIR}/binary )

That is, add the path/to/binary using a cmake variable, if that's possible.

like image 606
simont Avatar asked Feb 19 '12 15:02

simont


People also ask

Can CMake run Makefile?

CMake will create makefiles inside many of the folders inside a build directory and you can run make or make -j8 in any of these directories and it will do the right thing. You can even run make in your src tree, but since there is no Makefile in your source tree, only CMakeLists. txt files, nothing will happen.

How do I run CMake target?

Sometimes one will want to just run a target and see its output. This can be done with the CMake: Execute the current target without a debugger command, or the associated keybinding (the default is Shift+F5 ). The output of the target will be shown in an integrated terminal.

How run CMake project from command line?

Running CMake from the command line To run in interactive mode, just pass the option “-i” to cmake. This will cause cmake to ask you to enter a value for each value in the cache file for the project.

What is difference between make and CMake?

Make (or rather a Makefile) is a buildsystem - it drives the compiler and other build tools to build your code. CMake is a generator of buildsystems. It can produce Makefiles, it can produce Ninja build files, it can produce KDEvelop or Xcode projects, it can produce Visual Studio solutions.


1 Answers

You are looking for add_custom_target. For instance:

add_custom_target(run
    COMMAND binary
    DEPENDS binary
    WORKING_DIRECTORY ${CMAKE_PROJECT_DIR}
)
like image 151
Simon Avatar answered Oct 13 '22 13:10

Simon