`cmake --build` with specifying Debug or Release configuration

CMake gives a features of building the generated project by using --build command argument . For example, this builds the build target X.

cmake --build . --target X

I tried building X with configuration Debug or Release with this command line, but it does not work. It builds without Debug or Release.

cmake --build . --target X --config Debug

I checked out preset page but I cannot find anything mentioning about setting configuration Debug or Release. I printed CMAKE_BUILD_TYPE and it shows nothing.

How can I do cmake --build with specifying Debug or Release configuration?

The CLI instructions will depend on the type of generator you are using: