oleksandr_fryziuk
oleksandr_fryziuk

Reputation: 143

How to build target by name in CMake?

I have cmake project that consist of multiple targets.

MyProject/
/target1
       /Some stuff
       /CMakeLists.txt // here add_executable(target1 main.c)
/target2
/target3
...
CMakeLists.txt // root CMakeLists.txt file
/build // folder for build files

I wand to build only target1 and put it into /build folder inside my project

I could build all targets

[MyProject/build]$ cmake ..
[MyProject/build]$ make

How to build only target1?

I guess it must be something like this?

[MyProject/build]$ cmake ..
[MyProject/build]$ cmake --build . --target target1 -- -j 12

Upvotes: 0

Views: 2354

Answers (2)

mob
mob

Reputation: 76

Your commands should work fine

cmake ..
cmake --build . --target target1 -- -j 12

will build target1 and its dependencies only.

Upvotes: 1

Dmitry
Dmitry

Reputation: 2158

Suppose you set an executable inside CMakeLists.txt

add_executable( my_exe ${my_exe_sources} )

Then you can call make my_exe -j 2

Upvotes: 3

Related Questions