Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Problems :

  • With ninja, after configuration, the myBuildDir/Component1 directory doesn’t contain build.ninja file
  • If i try to do cmake --build in the mySourcedDir/Component1 directory, i have an error message : CMake Error: Could not read presets from...

>Solution :

Try editing Component1/CMakeList.txt with:

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

And then do:

cmake --build --preset=myPreset --target component1
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading