Cola
Cola

Reputation: 2247

What does --target option mean in CMake?

C:\blah\duh\bin\Android>"C:\Program Files (x86)\CMake\bin\cmake.exe" --build . --target SysTest --use-stderr -- -j 8    

I have this above CMake build command. I get that --build . is going to build from the Makefile in the current directory. But what does the option --target SysTest and -j 8 do? Here is the CMake documentation for --build but I admit, I don't understand the use of --target.

 --build <dir>
Build a CMake-generated project binary tree.

This abstracts a native build tool’s command-line interface with the following options:

<dir>          = Project binary directory to be built.
--target <tgt> = Build <tgt> instead of default targets.
--config <cfg> = For multi-configuration tools, choose <cfg>.
--clean-first  = Build target 'clean' first, then build.
                 (To clean only, use --target 'clean'.)
--use-stderr   = Ignored.  Behavior is default in CMake >= 3.0.
--             = Pass remaining options to the native tool.

Upvotes: 49

Views: 92135

Answers (1)

steveire
steveire

Reputation: 11074

If I have

add_executable(hello hello.cpp)

add_executable(goodbye goodbye.cpp)

then CMake creates 'build targets' for each executable. It also creates other build targets, such as the 'all' build target, which builds everything.

By default, if the target is not specified, the 'all' target is executed, meaning both hello and goodbye are built.

You can specify the target to build if you only want to build one of them.

Upvotes: 63

Related Questions