Sedji Aka
Sedji Aka

Reputation: 227

CMake : Compile only one subdirectory with preset

I have a project with this structure, where Components are subdirectories :

CMakeList.txt
CMakePresets.json
|
---Component1/CMakeList.txt
|
---Component2/CMakeList.txt
|
---Component3/CMakeList.txt

I would like to compile only Component1 with the root preset. (I mean compile all targets under Component1).

Normally, to configure and compile all the project i use this commands :

#Configuration
cd myBuildDir
cmake mySourcedDir --preset=myPreset
#Compilation
cd mySourcedDir 
cmake --build --preset=myPreset

Problems :

Upvotes: 0

Views: 711

Answers (1)

KamilCuk
KamilCuk

Reputation: 140970

Try editing Component1/CMakeList.txt with:

get_property(ALL_BUILDSYSTEM_TARGETS DIRECTORY PROPERTY BUILDSYSTEM_TARGETS)
add_custom_target(Component1 DEPENDS ${ALL_BUILDSYSTEM_TARGETS})

And then do:

cmake --build --preset=myPreset --target component1

Upvotes: 1

Related Questions