31

I want to use the cmake --build command to build my project.
This command has a --config option. I don't know how many different parameters I can assign to. And I found cmake doesn't check if the parameter of --config is correct or not

Samuel
  • 5,977
  • 14
  • 55
  • 77

1 Answers1

53

You can call cmake --build like this:

cmake --build . --target MyExe --config Debug

This would be run from your build root, since the directory is passed as ., and would build the target MyExe in Debug mode.

If your build tool is a multi-configuration one (like devenv on Windows), the --config argument matters. If you pass an invalid parameter as the config type here, the build tool should give an error.

If the build tool isn't multi-config (like gcc), then the --config argument is ignored. Instead the build type is set via the CMAKE_BUILD_TYPE CMake variable; i.e. it's set when running CMake, not when running the build tool.

You can pass further options to the build tool by adding them at the end after a --, e.g to pass -j4 if using gcc:

cmake --build . --target MyExe -- -j4
starball
  • 20,030
  • 7
  • 43
  • 238
Fraser
  • 74,704
  • 20
  • 238
  • 215
  • 4
    what does “multi-configuration” mean. Why gcc is not a multi-config. how to judge if it is a multi-config. – Samuel Jun 20 '13 at 09:28
  • 7
    The two I know of are Visual Studio and Xcode. It means that you can change the build type from within the IDE itself. With gcc, you specify the build type when invoking CMake; there's nothing gcc can do to change between build types once CMake has generated its makefile. – Fraser Jun 20 '13 at 10:21