mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-01 11:50:11 -05:00
cmake: Allow CMAKE_INSTALL_PREFIX to be set by environment variable
Fixes: #25023
This commit is contained in:
committed by
Brad King
parent
b0d8b857d8
commit
06af18b9db
@@ -0,0 +1,11 @@
|
|||||||
|
CMAKE_INSTALL_PREFIX
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
.. versionadded:: 3.29
|
||||||
|
|
||||||
|
.. include:: ENV_VAR.txt
|
||||||
|
|
||||||
|
The ``CMAKE_INSTALL_PREFIX`` environment variable specifies a custom default
|
||||||
|
value for the :variable:`CMAKE_INSTALL_PREFIX` variable in place of the
|
||||||
|
default values specified by CMake itself. The value specified must be an
|
||||||
|
absolute path to a directory.
|
||||||
@@ -50,6 +50,7 @@ Environment Variables that Control the Build
|
|||||||
/envvar/CMAKE_GENERATOR_PLATFORM
|
/envvar/CMAKE_GENERATOR_PLATFORM
|
||||||
/envvar/CMAKE_GENERATOR_TOOLSET
|
/envvar/CMAKE_GENERATOR_TOOLSET
|
||||||
/envvar/CMAKE_INSTALL_MODE
|
/envvar/CMAKE_INSTALL_MODE
|
||||||
|
/envvar/CMAKE_INSTALL_PREFIX
|
||||||
/envvar/CMAKE_LANG_COMPILER_LAUNCHER
|
/envvar/CMAKE_LANG_COMPILER_LAUNCHER
|
||||||
/envvar/CMAKE_LANG_IMPLICIT_LINK_DIRECTORIES_EXCLUDE
|
/envvar/CMAKE_LANG_IMPLICIT_LINK_DIRECTORIES_EXCLUDE
|
||||||
/envvar/CMAKE_LANG_LINKER_LAUNCHER
|
/envvar/CMAKE_LANG_LINKER_LAUNCHER
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
env-cmake-install-prefix
|
||||||
|
------------------------
|
||||||
|
|
||||||
|
* The :envvar:`CMAKE_INSTALL_PREFIX` environment variable was added to
|
||||||
|
provide a default value for the :variable:`CMAKE_BUILD_TYPE` variable.
|
||||||
@@ -4,8 +4,19 @@ CMAKE_INSTALL_PREFIX
|
|||||||
Install directory used by :command:`install`.
|
Install directory used by :command:`install`.
|
||||||
|
|
||||||
If ``make install`` is invoked or ``INSTALL`` is built, this directory is
|
If ``make install`` is invoked or ``INSTALL`` is built, this directory is
|
||||||
prepended onto all install directories. This variable defaults to
|
prepended onto all install directories.
|
||||||
``/usr/local`` on UNIX and ``c:/Program Files/${PROJECT_NAME}`` on Windows.
|
|
||||||
|
This variable defaults as follows:
|
||||||
|
|
||||||
|
* .. versionadded:: 3.29
|
||||||
|
|
||||||
|
If the :envvar:`CMAKE_INSTALL_PREFIX` environment variable is set,
|
||||||
|
its value is used as default for this variable.
|
||||||
|
|
||||||
|
* ``c:/Program Files/${PROJECT_NAME}`` on Windows.
|
||||||
|
|
||||||
|
* ``/usr/local`` on UNIX platforms.
|
||||||
|
|
||||||
See :variable:`CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT` for how a
|
See :variable:`CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT` for how a
|
||||||
project might choose its own default.
|
project might choose its own default.
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,10 @@ CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT
|
|||||||
|
|
||||||
CMake sets this variable to a ``TRUE`` value when the
|
CMake sets this variable to a ``TRUE`` value when the
|
||||||
:variable:`CMAKE_INSTALL_PREFIX` has just been initialized to
|
:variable:`CMAKE_INSTALL_PREFIX` has just been initialized to
|
||||||
its default value, typically on the first run of CMake within
|
its default value, typically on the first
|
||||||
a new build tree. This can be used by project code to change
|
run of CMake within a new build tree and the :envvar:`CMAKE_INSTALL_PREFIX`
|
||||||
the default without overriding a user-provided value:
|
environment variable is not set on the first run of CMake. This can be used
|
||||||
|
by project code to change the default without overriding a user-provided value:
|
||||||
|
|
||||||
.. code-block:: cmake
|
.. code-block:: cmake
|
||||||
|
|
||||||
|
|||||||
@@ -177,20 +177,27 @@ endfunction()
|
|||||||
# was initialized by the block below. This is useful for user
|
# was initialized by the block below. This is useful for user
|
||||||
# projects to change the default prefix while still allowing the
|
# projects to change the default prefix while still allowing the
|
||||||
# command line to override it.
|
# command line to override it.
|
||||||
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
|
if(NOT DEFINED CMAKE_INSTALL_PREFIX AND
|
||||||
|
NOT DEFINED ENV{CMAKE_INSTALL_PREFIX})
|
||||||
set(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT 1)
|
set(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT 1)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Choose a default install prefix for this platform.
|
if(DEFINED ENV{CMAKE_INSTALL_PREFIX})
|
||||||
if(CMAKE_HOST_UNIX)
|
set(CMAKE_INSTALL_PREFIX "$ENV{CMAKE_INSTALL_PREFIX}"
|
||||||
set(CMAKE_INSTALL_PREFIX "/usr/local"
|
|
||||||
CACHE PATH "Install path prefix, prepended onto install directories.")
|
CACHE PATH "Install path prefix, prepended onto install directories.")
|
||||||
else()
|
else()
|
||||||
GetDefaultWindowsPrefixBase(CMAKE_GENERIC_PROGRAM_FILES)
|
# If CMAKE_INSTALL_PREFIX env variable is not set,
|
||||||
set(CMAKE_INSTALL_PREFIX
|
# choose a default install prefix for this platform.
|
||||||
"${CMAKE_GENERIC_PROGRAM_FILES}/${PROJECT_NAME}"
|
if(CMAKE_HOST_UNIX)
|
||||||
CACHE PATH "Install path prefix, prepended onto install directories.")
|
set(CMAKE_INSTALL_PREFIX "/usr/local"
|
||||||
set(CMAKE_GENERIC_PROGRAM_FILES)
|
CACHE PATH "Install path prefix, prepended onto install directories.")
|
||||||
|
else()
|
||||||
|
GetDefaultWindowsPrefixBase(CMAKE_GENERIC_PROGRAM_FILES)
|
||||||
|
set(CMAKE_INSTALL_PREFIX
|
||||||
|
"${CMAKE_GENERIC_PROGRAM_FILES}/${PROJECT_NAME}"
|
||||||
|
CACHE PATH "Install path prefix, prepended onto install directories.")
|
||||||
|
set(CMAKE_GENERIC_PROGRAM_FILES)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Set a variable which will be used as component name in install() commands
|
# Set a variable which will be used as component name in install() commands
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
-- ENV{CMAKE_INSTALL_PREFIX}='[^']*/Tests/RunCMake/CommandLine/install_prefix_set_via_env_var'
|
||||||
|
-- CMAKE_INSTALL_PREFIX='[^']*/Tests/RunCMake/CommandLine/install_prefix_set_via_env_var'
|
||||||
|
-- CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT=''
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
message(STATUS "ENV{CMAKE_INSTALL_PREFIX}='$ENV{CMAKE_INSTALL_PREFIX}'")
|
||||||
|
message(STATUS "CMAKE_INSTALL_PREFIX='${CMAKE_INSTALL_PREFIX}'")
|
||||||
|
message(STATUS "CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT='${CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT}'")
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
-- ENV{CMAKE_INSTALL_PREFIX}='[^']*/Tests/RunCMake/CommandLine/install_prefix_set_via_env_var'
|
||||||
|
-- CMAKE_INSTALL_PREFIX='[^']*/Tests/RunCMake/CommandLine/install_prefix_set_cmd_line_opt'
|
||||||
|
-- CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT=''
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
include(EnvInstallPrefix.cmake)
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
-- ENV{CMAKE_INSTALL_PREFIX}='[^']*/Tests/RunCMake/CommandLine/install_prefix_set_via_env_var'
|
||||||
|
-- CMAKE_INSTALL_PREFIX='[^']*/Tests/RunCMake/CommandLine/install_prefix_set_via_var'
|
||||||
|
-- CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT=''
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
include(EnvInstallPrefix.cmake)
|
||||||
@@ -459,6 +459,15 @@ elseif(RunCMake_GENERATOR MATCHES "Ninja Multi-Config|Visual Studio|Xcode")
|
|||||||
run_EnvironmentConfigTypes()
|
run_EnvironmentConfigTypes()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
function(run_EnvironmentInstallPrefix)
|
||||||
|
set(ENV{CMAKE_INSTALL_PREFIX} "${RunCMake_BINARY_DIR}/install_prefix_set_via_env_var")
|
||||||
|
run_cmake(EnvInstallPrefix)
|
||||||
|
run_cmake_with_options(EnvInstallPrefixOverrideWithVar -DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/install_prefix_set_via_var)
|
||||||
|
run_cmake_with_options(EnvInstallPrefixOverrideWithCmdLineOpt --install-prefix ${RunCMake_BINARY_DIR}/install_prefix_set_cmd_line_opt)
|
||||||
|
unset(ENV{CMAKE_INSTALL_PREFIX})
|
||||||
|
endfunction()
|
||||||
|
run_EnvironmentInstallPrefix()
|
||||||
|
|
||||||
function(run_EnvironmentToolchain)
|
function(run_EnvironmentToolchain)
|
||||||
set(ENV{CMAKE_TOOLCHAIN_FILE} "${RunCMake_SOURCE_DIR}/EnvToolchain-toolchain.cmake")
|
set(ENV{CMAKE_TOOLCHAIN_FILE} "${RunCMake_SOURCE_DIR}/EnvToolchain-toolchain.cmake")
|
||||||
run_cmake(EnvToolchainAbsolute)
|
run_cmake(EnvToolchainAbsolute)
|
||||||
|
|||||||
Reference in New Issue
Block a user