Install components with presets

I usually install components with:
cmake -DCOMPONENT=componentA -P cmake_install.cmake
With workdir in Build dir (specified in configure call)

With presets, the Build dir is burried somewhere in the CMakePresets.json file. I do not know it without parsing the file and completing the macros:
"binaryDir": "${sourceDir}/Build/$env{TOOLCHAIN}-$env{BUILD_TYPE}-${generator}",

This is a pain so I hoped, I could use cmake --install (introduced in 3.15) like
cmake --install --component componentA --preset presetA
but it did not work.

Is there an other way or would this be a new feature?

1 Like

A workaround is:

add_custom_target(install_componentA
   # Dont use cmake --install for compatibility
   COMMAND ${CMAKE_COMMAND} cmake -DCOMPONENT=componentA -P ${CMAKE_BINARY_DIR}/cmake_install.cmake
)

And then use:
cmake --build --preset presetA --target install_componentA

I made a proposal in Help converting most of a CI matrix to presets? that should help you with this… I’d appreciate in up-vote there if possible…

I’ll also add a comment linking to this one…

1 Like