[CMake] Set system install prefix

Theo Diefenthal diefenthal at ifi.uzh.ch
Tue Dec 3 06:42:01 EST 2013


Hey there,

First, I already searched quite a while for my question, but couldn't
find anything related to it, even though I think, it is probably asked
already somewhere. So I'm sorry if this produces a double post...

But now to my question:
I wonder if there is a possibility to set a system wide install prefix
in CMake.

I know, I can call
	cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr /sourceDir && make all install

And I also know that I can override the install prefix for my own
projects easily with this piece of code:
	if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
		if(DEFINED ENV{CMAKE_DEFAULT_INSTALL_DIR})
			set (CMAKE_INSTALL_PREFIX
"$ENV{CMAKE_DEFAULT_INSTALL_DIR}/${MY_PROJECT_NAME}" CACHE PATH "Project
installation path" FORCE )
		endif()
	endif()

However, what I would really like to do is to set a global install
prefix for my system where cmake then installs to, for all projects, not
only my own ones.
Just like having an environment variable set as
CMAKE_DEFAULT_INSTALL_DIR which will be read out and replace the
CMAKE_INSTALL_PREFIX default value with a new default value.
Setting CMAKE_INSTALL_PREFIX as environment variable on my Windows
system sadly doesn't change anything, it still uses C:\Program Files\

Sadly, C:\Program Files is a really annyong install directory. If I
forget to change the install directory and want to test my installation,
I then need to restart Visual Studio with Admin rights to write in
C:\Program Files or need to reexecute CMake to change the install prefix.
Also, I would like to have the install prefix on a different partition,
not the same with the system....

Best regards
Theo



More information about the CMake mailing list