BUILD_TYPE not set during `cmake --install`

I’ve been looking into installing my code into different directories depending upon the configuration type. This is for Visual Studios – multi-config compiler.

I’ve done this by setting


I found conflicting results depending upon how I triggered the install.

If the install is triggered from Visual Studio by seleting the “INSTALL” target and building from there, it works.

If the install is triggered from the command line with the command

cmake --build Build/build64/VS2022 --config "Release" --target install

It also works.

However, if the install is triggered from the command line with the comand

cmake --install Build/build64/VS2022 --config "Release"

It doesn’t work.

I added some message() statements to the generated cmake_isntall.cmake file and I learned the BUILD_TYPE variable isn’t set for the cmake --install scenario.

Is this a known defect? Or is this on purpose? If on purpose why would it behave differently from the --target install variant?

I’m using cmake version 3.23.1

FYI. After adding more debug output to the cmake_install.cmake file, I found:

cmake --build Build/build64/VS2022 --config "Release" --target install



cmake --install Build/build64/VS2022 --config "Release"

does not set BUILD_TYPE but passing in the command argument -DCMAKE_INSTALL_CONFIG_NAME

With this information I was able to hack together a workaround of


that works for both install modes.

Still, this feels like it might be a defect.