--prefix argument to
cmake --install is generally the best way to set an installation prefix because it lets you decouple install-time requirements from your configuration logic.
I think the fact that
CMAKE_INSTALL_PREFIX affects configure-time logic just reinforces that position.
Usually you (or at least consumers of your project!) really want to directly manipulate
CMAKE_SYSTEM_PREFIX_PATH to alter configure-time logic. Ideally in a mechanism like a CMake toolchain file of maybe a CMake preset to keep your logic consistent, reusable, and tidy. As an aside, pretty much every time
CMakeLists.txt or reusable CMake modules start manipulating these variables, they lose portability, gain complexity, or both.
CMAKE_INSTALL_PREFIX seems to mostly work a lot of the time, but I’m currently convinced that it has been sufficiently surpassed by other mechanisms at this point to just stop using it full-stop. I’d be curious if there are edge cases that challenge that advice.