update install default deduction
Why do this change?
The current CMake code prevents the user from defining CMAKE_INSTALL_PREFIX
to the CMake default install location /usr/local
.
general-broken-lines/cpp$ cmake -B build -S . -DCMAKE_INSTALL_PREFIX=/usr/local
<omit other cmake printouts>
--
-- -------------------------------------------------------------------------------
-- Change values with: cmake -D<Variable>=<Value>
-- CMAKE_INSTALL_PREFIX = /home/tom/hps/alignment/general-broken-lines/cpp
-- CMAKE_BUILD_TYPE = RelWithDebInfo
-- BUILD_TESTING = ON
-- CMAKE_MODULE_PATH =
-- /home/tom/hps/alignment/general-broken-lines/cpp/cmake;
-- -------------------------------------------------------------------------------
--
-- Configuring done
-- Generating done
-- Build files have been written to: /home/tom/hps/alignment/general-broken-lines/cpp/build
What did I change?
In newer versions of cmake, there is a special variable we can use to deduce if the user defined a path or not. This allows the project default to actually be a default and the user can change the install path to happen to correspond to the cmake default if they so wish.
For versions of cmake prior to v3.7.1, the deduction of the install prefix default is kept the same.
Checks
I checked this on CentOS7 with CMake v3.22.0.
Without defining the install path, we get the project default.
general-broken-lines/cpp$ cmake -B build -S .
<omit other cmake printouts>
--
-- -------------------------------------------------------------------------------
-- Change values with: cmake -D<Variable>=<Value>
-- CMAKE_INSTALL_PREFIX = /home/tom/hps/alignment/general-broken-lines/cpp
-- CMAKE_BUILD_TYPE = RelWithDebInfo
-- BUILD_TESTING = ON
-- CMAKE_MODULE_PATH =
-- /home/tom/hps/alignment/general-broken-lines/cpp/cmake;
-- -------------------------------------------------------------------------------
--
-- Configuring done
-- Generating done
Defining the install path to the CMake default, we get that value.
general-broken-lines/cpp$ cmake -B build -S . -DCMAKE_INSTALL_PREFIX=/usr/local
<omit other cmake printouts>
--
-- -------------------------------------------------------------------------------
-- Change values with: cmake -D<Variable>=<Value>
-- CMAKE_INSTALL_PREFIX = /usr/local
-- CMAKE_BUILD_TYPE = RelWithDebInfo
-- BUILD_TESTING = ON
-- CMAKE_MODULE_PATH =
-- /home/tom/hps/alignment/general-broken-lines/cpp/cmake;
-- -------------------------------------------------------------------------------
--
-- Configuring done
-- Generating done