How do I set CMAKE_INSTALL_PREFIX in my root CMakeLists.txt file?
I have been doing
cmake_minimum_required(VERSION 2.8)
project(MyProject)
# Set default install prefix
set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR})
with the hopes that by installations would be destined to folders in the source tree. That is,
install(TARGETS my_exe DESTINATION bin/)
would install to ${CMAKE_SOURCE_DIR}/bin/
. Instead, it keeps trying to write to /usr/local/bin
(the default for Ubuntu 14.04).
I tried the answers to this question, but I still get the standard usr/local/
as my CMAKE_INSTALL_PREFIX when I check CMakeCache.txt.
The only working solution I have is to do
install(TARGETS my_exe DESTINATION "${CMAKE_SOURCE_DIR}/bin/")
but this then removes the user's ability to specify where the bin directory to install is.
tl;dr I would like make install
to automatically install to ${CMAKE_SOURCE_DIR}
by default, rather than /usr/local/
.
CMake developers suggest to use given pattern for change default value of CMAKE_INSTALL_PREFIX inside
CMakeLists.txt
:Using that approach
is not recommended: