Difference between revisions of "RecipeAppendVersionNumberToInstallpath"

From KitwarePublic
Jump to navigationJump to search
Line 1: Line 1:
In some situations, it's necessary to keep older versions of a program along with the newer.  Here is a recipe for appending the version number to your install path:
In some situations, it's necessary to keep older versions of a program along with the newer.  Here is a recipe for appending the version number to your install path:


<pre>PROJECT(MyProg C)
<pre>IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
SET (VERSION "0.1.4")
    SET(ORIGINAL_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE STRING "Default prefix path" FORCE)
...
ENDIF()
IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
MARK_AS_ADVANCED(ORIGINAL_INSTALL_PREFIX)
SET(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}-${VERSION}"
CACHE STRING "Install path" FORCE)
ENDIF()  
...


# and if you use CPack, just default the installer to the right path using:
IF( NOT( VERSION VERSION_EQUAL PROJECT_VERSION) )
set(CPACK_PACKAGE_INSTALL_DIRECTORY "MyProg-${VERSION}")</pre>
    SET(CMAKE_INSTALL_PREFIX "${ORIGINAL_INSTALL_PREFIX}-${VERSION}" CACHE STRING "Install path" FORCE)
    SET(PROJECT_VERSION ${VERSION})
ENDIF()</pre>
This ensures that the CMAKE_INSTALL_PREFIX is updated whenever the old version number and the new version number doesn't match.  This does have some side-effects, such as situations where the user is customizing the CMAKE_INSTALL_PREFIX to some custom location.  Such users would need to modify the ORIGINAL_INSTALL_PREFIX instead to ensure that the project is going to the desired place.
   
   
The CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT is necessary here because if it's missing, the path becomes recursive and will continue to append ${PROJECT_NAME}-${VERSION} to the path infinitely.  The conditional ensures that it only does this once.
The CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT is necessary here because if it's missing, the path becomes recursive and will continue to append ${PROJECT_NAME}-${VERSION} to the path infinitely.  The conditional ensures that it only does this once.

Revision as of 09:36, 9 October 2009

In some situations, it's necessary to keep older versions of a program along with the newer. Here is a recipe for appending the version number to your install path:

IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
    SET(ORIGINAL_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE STRING "Default prefix path" FORCE)
ENDIF()
MARK_AS_ADVANCED(ORIGINAL_INSTALL_PREFIX)

IF( NOT( VERSION VERSION_EQUAL PROJECT_VERSION) )
    SET(CMAKE_INSTALL_PREFIX "${ORIGINAL_INSTALL_PREFIX}-${VERSION}" CACHE STRING "Install path" FORCE)
    SET(PROJECT_VERSION ${VERSION})
ENDIF()

This ensures that the CMAKE_INSTALL_PREFIX is updated whenever the old version number and the new version number doesn't match. This does have some side-effects, such as situations where the user is customizing the CMAKE_INSTALL_PREFIX to some custom location. Such users would need to modify the ORIGINAL_INSTALL_PREFIX instead to ensure that the project is going to the desired place.

The CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT is necessary here because if it's missing, the path becomes recursive and will continue to append ${PROJECT_NAME}-${VERSION} to the path infinitely. The conditional ensures that it only does this once.