Set installation prefix automatically to custom path if not explicitly specified on the command line

CMake sets the boolean variable CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT if CMAKE_INSTALL_PREFIX has not been explicitly specified and is initialized to its default setting. You can override it in the following way:

if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
    set (CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/installed"
           CACHE PATH "default install path" FORCE)
endif()

Leave a Comment