Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does --target option mean in CMake?

Tags:

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. 
like image 543
user1411110 Avatar asked Sep 17 '14 17:09

user1411110


People also ask

What does target mean in CMake?

Introduction. A CMake-based buildsystem is organized as a set of high-level logical targets. Each target corresponds to an executable or library, or is a custom target containing custom commands.

How do I add a target to CMake?

Use the add_custom_command() command to generate a file with dependencies. By default nothing depends on the custom target. Use the add_dependencies() command to add dependencies to or from other targets.

What is a build target?

A build target is a string that identifies a build rule in your project. Build targets are used as arguments to Buck commands, such as buck build and buck run . Build targets are also used as arguments to build rules to enable one build rule to reference another.

What is option in CMake?

Provide a boolean option that the user can optionally select. option(<variable> "<help_text>" [value]) If no initial <value> is provided, boolean OFF is the default value. If <variable> is already set as a normal or cache variable, then the command does nothing (see policy CMP0077 ).


1 Answers

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.

like image 85
steveire Avatar answered Sep 17 '22 10:09

steveire