[CMake] About CMAKE_INSTALL_PREFIX
Michael Wild
themiwi at gmail.com
Tue Jan 24 03:48:48 EST 2012
On 01/24/2012 09:35 AM, pellegrini wrote:
> Hello everbody,
>
> I would like to understand a bit more one feature related to
> CMAKE_INSTALL_PREFIX initialization.
>
> When reading the documentation, it is specified that this variable
> contains the directory that will be pre-pended to all install
> directories and that it should be defaulted to C:/Program Files on
> Windows. However, in my current build the variable is not defaulted to
> C:/Program Files but to C:/Program Files/libcrysfml where "crysfml " is
> the name of my base project.
>
> This unexpected feature (at least to my understanding !) leads me to my
> second question.
>
> I would like to get rid of the "crysfml " subdirectory in the value of
> CMAKE_INSTALL_PREFIX. I could obvioulsy
> use:
> get_filename_component(MY_CMAKE_INSTALL_PREFIX
> ${CMAKE_INSTALL_PREFIX} PATH)
> but this would fail if CMAKE_INSTALL_PREFIX is set on the cmake command
> line by the user because, in such case, the installation will not be
> done in the directory that he provided but in its parent directory.
> Rather counter-intuitive.
>
> What I would need is a mechanism to detect whether the
> CMAKE_INSTALL_PREFIX has been set or not by the user on the
> command-line. If so, I take directly the values he provided, and if not
> so, I take the parent directory of the default value.
>
> Is that possible ?
>
> thanks a lot
>
> Eric
>
>
>
You can use the variable CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT to
determine whether the cache contains the default value or has been
modified by the user. E.g.
project(Foo)
if(WIN32 AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_GENERIC_PROGRAM_FILES}" CACHE PATH
"Install path prefix, prepended onto install directories." FORCE)
endif()
should do what you want.
HTH
Michael
More information about the CMake
mailing list