I want to generate Makefile with install target, making installation to /usr instead of default /usr/local. Assuming that build directory is done in the source subdirectory, I execute:
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr ..
CMakeCache.txt contains: CMAKE_INSTALL_PREFIX:PATH=/usr
(OK?)
Now I execute:
make make install
All files are still installed to usr/local. What is wrong?
Edit: There is no CMAKE_INSTALL_PREFIX in any of CMakeLists.txt project files. Before running cmake, I delete everything from the output directory. install directives in CMakeLists.txt look like:
install(TARGETS mylibrary DESTINATION lib)
There are two ways to use this variable:
passing it as a command line argument just like Job mentioned:
cmake -DCMAKE_INSTALL_PREFIX=< install_path > ..
assigning value to it in
CMakeLists.txt
:SET(CMAKE_INSTALL_PREFIX < install_path >)
But do remember to place it BEFORE
PROJECT(< project_name>)
command, otherwise it will not work!My first week of using cmake - after some years of GNU autotools - so I am still learning (better then writing m4 macros), but I think modifying CMAKE_INSTALL_PREFIX after setting project is the better place.
CMakeLists.txt
First run (no cache)
Second run
Let me know if I am mistaken, I have a lot of learning to do. It's fun.
That should be (see the docs):