Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optional targets in Cmake

Tags:

c++

c

cmake

Is there a way to specify optional targets in CMake? I mean ones that are built only when one specifies them explicitly, for example by make <target>, and are not built when you specify just make? I know I can do this with add_custom_command(), but I need all the features that a normal build target has

like image 996
Alexander Vassilev Avatar asked Feb 16 '12 19:02

Alexander Vassilev


People also ask

What are targets in CMake?

In general, targets comprise executables or libraries which are defined by calling add_executable or add_library and which can have many properties set. They can have dependencies on one another, which for targets such as these just means that dependent ones will be built after their dependencies.

How do I set a target on CMake?

set_target_properties(target1 target2 ... PROPERTIES prop1 value1 prop2 value2 ...) Sets properties on targets. The syntax for the command is to list all the targets you want to change, and then provide the values you want to set next.

What are build targets?

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 an executable target?

An IMPORTED executable target references an executable file located outside the project. No rules are generated to build it, and the IMPORTED target property is True . The target name has scope in the directory in which it is created and below, but the GLOBAL option extends visibility.


1 Answers

There is no need to use add_custom_target. You can simply specify EXCLUDE_FROM_ALL, when specifying the build rule for an executable via add_executable. The same applies to add_library.

like image 145
Martin Avatar answered Sep 25 '22 08:09

Martin