I have a project that, if a CMAKE_INSTALL_PREFIX
is provided at configure/generation-time, provides that prefix to the project code to help out with certain search paths and file storage logic.
I wanted to provide a warning to the developer if they configured by passing a prefix, but then they try to call cmake --install . --prefix <prefix>
with a different prefix than they configured with.
I assumed that I could do this with something like the following:
if(NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CONFIGURE_PREFIX ${CMAKE_INSTALL_PREFIX})
endif()
install(CODE "
if(NOT \"${CMAKE_INSTALL_PREFIX}\" STREQUAL \"${CONFIGURE_PREFIX}\")
message(AUTHOR_WARNING \" Install prefix differs from configured install prefix! \")
endif()
")
But the value of CMAKE_INSTALL_PREFIX
is still the same as CONFIGURE_PREFIX
regardless of the argument passed with --prefix
.
This might be a bit of an edge case, because who would pass an install prefix different than the one they configured with, but isn’t it a bit odd that we can’t access the contents of a provided --prefix
argument at install time?