install() does not allow passing full component string as variable
I am developing some CMake functions where I optionally might pass the installation component as an argument to a CMake function.
Ideally, I would like to pass both the COMPONENT keyword and component name in a variable. This allows me to use an empty string when I do not have a component. The following minimal example reproduces the issue.
cmake_minimum_required(VERSION 3.18)
project(installDirectoryWithVariableComponent)
set(_comp "COMPONENT sdk")
install(
DIRECTORY ${CMAKE_SOURCE_DIR}
DESTINATION ${CMAKE_BINARY_DIR}
#COMPONENT sdk # Uncomment to make configuration succeed
${_comp} # Comment to make configuration succeed
)
This yields the following error message:
c:\projects\CMakeInstallBug\build>cmake -GNinja ..
CMake Error at CMakeLists.txt:6 (install):
install DIRECTORY given unknown argument "COMPONENT sdk".
-- Configuring incomplete, errors occurred!
See also "C:/projects/CMakeInstallBug/build/CMakeFiles/CMakeOutput.log".
Since install() is implemented as a C++ function, I am assuming the argument isn't being split correctly in cmInstallCommand.cxx.