mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-25 04:25:29 +08:00
export: Disable PACKAGE mode user package registry by default
The user package registry populated by the `export()` command causes side effects outside the build and source directories. Such effects should be opt-in rather than op-out. Introduce a policy to change default behavior of `export(PACKAGE)` to do nothing.
This commit is contained in:
committed by
Brad King
parent
0df31d99ae
commit
9bede5c4ce
@@ -62,8 +62,13 @@ registry that this command creates works only in conjunction with a
|
|||||||
package configuration file (``<PackageName>Config.cmake``) that works with the
|
package configuration file (``<PackageName>Config.cmake``) that works with the
|
||||||
build tree. In some cases, for example for packaging and for system
|
build tree. In some cases, for example for packaging and for system
|
||||||
wide installations, it is not desirable to write the user package
|
wide installations, it is not desirable to write the user package
|
||||||
registry. If the :variable:`CMAKE_EXPORT_NO_PACKAGE_REGISTRY` variable
|
registry.
|
||||||
is enabled, the ``export(PACKAGE)`` command will do nothing.
|
|
||||||
|
By default the ``export(PACKAGE)`` command does nothing (see policy
|
||||||
|
:policy:`CMP0090`) because populating the user package registry has effects
|
||||||
|
outside the source and build trees. Set the
|
||||||
|
:variable:`CMAKE_EXPORT_PACKAGE_REGISTRY` variable to add build directories to
|
||||||
|
the CMake user package registry.
|
||||||
|
|
||||||
.. code-block:: cmake
|
.. code-block:: cmake
|
||||||
|
|
||||||
|
|||||||
@@ -647,12 +647,17 @@ Disabling the Package Registry
|
|||||||
In some cases using the Package Registries is not desirable. CMake
|
In some cases using the Package Registries is not desirable. CMake
|
||||||
allows one to disable them using the following variables:
|
allows one to disable them using the following variables:
|
||||||
|
|
||||||
* :variable:`CMAKE_EXPORT_NO_PACKAGE_REGISTRY` disables the
|
* The :command:`export(PACKAGE)` command does not populate the user
|
||||||
:command:`export(PACKAGE)` command.
|
package registry when :policy:`CMP0090` is set to ``NEW`` unless the
|
||||||
* :variable:`CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY` disables the
|
:variable:`CMAKE_EXPORT_PACKAGE_REGISTRY` variable explicitly enables it.
|
||||||
User Package Registry in all the :command:`find_package` calls.
|
When :policy:`CMP0090` is *not* set to ``NEW`` then
|
||||||
* :variable:`CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY` disables
|
:command:`export(PACKAGE)` populates the user package registry unless
|
||||||
the System Package Registry in all the :command:`find_package` calls.
|
the :variable:`CMAKE_EXPORT_NO_PACKAGE_REGISTRY` variable explicitly
|
||||||
|
disables it.
|
||||||
|
* :variable:`CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY` disables the
|
||||||
|
User Package Registry in all the :command:`find_package` calls.
|
||||||
|
* :variable:`CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY` disables
|
||||||
|
the System Package Registry in all the :command:`find_package` calls.
|
||||||
|
|
||||||
Package Registry Example
|
Package Registry Example
|
||||||
------------------------
|
------------------------
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ Policies Introduced by CMake 3.15
|
|||||||
.. toctree::
|
.. toctree::
|
||||||
:maxdepth: 1
|
:maxdepth: 1
|
||||||
|
|
||||||
|
CMP0090: export(PACKAGE) does not populate package registry by default. </policy/CMP0090>
|
||||||
CMP0089: Compiler id for IBM Clang-based XL compilers is now XLClang. </policy/CMP0089>
|
CMP0089: Compiler id for IBM Clang-based XL compilers is now XLClang. </policy/CMP0089>
|
||||||
|
|
||||||
Policies Introduced by CMake 3.14
|
Policies Introduced by CMake 3.14
|
||||||
@@ -73,6 +74,7 @@ Policies Introduced by CMake 3.14
|
|||||||
CMP0083: Add PIE options when linking executable. </policy/CMP0083>
|
CMP0083: Add PIE options when linking executable. </policy/CMP0083>
|
||||||
CMP0082: Install rules from add_subdirectory() are interleaved with those in caller. </policy/CMP0082>
|
CMP0082: Install rules from add_subdirectory() are interleaved with those in caller. </policy/CMP0082>
|
||||||
|
|
||||||
|
|
||||||
Policies Introduced by CMake 3.13
|
Policies Introduced by CMake 3.13
|
||||||
=================================
|
=================================
|
||||||
|
|
||||||
|
|||||||
@@ -159,6 +159,7 @@ Variables that Change Behavior
|
|||||||
/variable/CMAKE_ERROR_DEPRECATED
|
/variable/CMAKE_ERROR_DEPRECATED
|
||||||
/variable/CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION
|
/variable/CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION
|
||||||
/variable/CMAKE_EXPORT_COMPILE_COMMANDS
|
/variable/CMAKE_EXPORT_COMPILE_COMMANDS
|
||||||
|
/variable/CMAKE_EXPORT_PACKAGE_REGISTRY
|
||||||
/variable/CMAKE_EXPORT_NO_PACKAGE_REGISTRY
|
/variable/CMAKE_EXPORT_NO_PACKAGE_REGISTRY
|
||||||
/variable/CMAKE_FIND_APPBUNDLE
|
/variable/CMAKE_FIND_APPBUNDLE
|
||||||
/variable/CMAKE_FIND_FRAMEWORK
|
/variable/CMAKE_FIND_FRAMEWORK
|
||||||
|
|||||||
27
Help/policy/CMP0090.rst
Normal file
27
Help/policy/CMP0090.rst
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
CMP0090
|
||||||
|
-------
|
||||||
|
|
||||||
|
:command:`export(PACKAGE)` does not populate package registry by default.
|
||||||
|
|
||||||
|
In CMake 3.14 and below the :command:`export(PACKAGE)` command populated the
|
||||||
|
user package registry by default and users needed to set the
|
||||||
|
:variable:`CMAKE_EXPORT_NO_PACKAGE_REGISTRY` to disable it, e.g. in automated
|
||||||
|
build and packaging environments. Since the user package registry is stored
|
||||||
|
outside the build tree, this side effect should not be enabled by default.
|
||||||
|
Therefore CMake 3.15 and above prefer that :command:`export(PACKAGE)` does
|
||||||
|
nothing unless an explicit :variable:`CMAKE_EXPORT_PACKAGE_REGISTRY` variable
|
||||||
|
is set to enable it. This policy provides compatibility with projects that
|
||||||
|
have not been updated.
|
||||||
|
|
||||||
|
The ``OLD`` behavior for this policy is for :command:`export(PACKAGE)` command
|
||||||
|
to populate the user package registry unless
|
||||||
|
:variable:`CMAKE_EXPORT_NO_PACKAGE_REGISTRY` is enabled.
|
||||||
|
The ``NEW`` behavior is for :command:`export(PACKAGE)` command to do nothing
|
||||||
|
unless the :variable:`CMAKE_EXPORT_PACKAGE_REGISTRY` is enabled.
|
||||||
|
|
||||||
|
This policy was introduced in CMake version 3.15. Use the
|
||||||
|
:command:`cmake_policy` command to set it to ``OLD`` or ``NEW`` explicitly.
|
||||||
|
Unlike most policies, CMake version |release| does *not* warn
|
||||||
|
when this policy is not set and simply uses ``OLD`` behavior.
|
||||||
|
|
||||||
|
.. include:: DEPRECATED.txt
|
||||||
6
Help/release/dev/export-package-default-off.rst
Normal file
6
Help/release/dev/export-package-default-off.rst
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
export-package-default-off
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
* The :command:`export(PACKAGE)` command now does nothing unless
|
||||||
|
enabled via :variable:`CMAKE_EXPORT_PACKAGE_REGISTRY`.
|
||||||
|
See policy :policy:`CMP0090`.
|
||||||
@@ -1,11 +1,16 @@
|
|||||||
CMAKE_EXPORT_NO_PACKAGE_REGISTRY
|
CMAKE_EXPORT_NO_PACKAGE_REGISTRY
|
||||||
--------------------------------
|
--------------------------------
|
||||||
|
|
||||||
Disable the :command:`export(PACKAGE)` command.
|
Disable the :command:`export(PACKAGE)` command when :policy:`CMP0090`
|
||||||
|
is not set to ``NEW``.
|
||||||
|
|
||||||
In some cases, for example for packaging and for system wide
|
In some cases, for example for packaging and for system wide
|
||||||
installations, it is not desirable to write the user package registry.
|
installations, it is not desirable to write the user package registry.
|
||||||
If the :variable:`CMAKE_EXPORT_NO_PACKAGE_REGISTRY` variable is enabled,
|
If the ``CMAKE_EXPORT_NO_PACKAGE_REGISTRY`` variable is enabled,
|
||||||
the :command:`export(PACKAGE)` command will do nothing.
|
the :command:`export(PACKAGE)` command will do nothing.
|
||||||
|
|
||||||
|
If :policy:`CMP0090` is set to ``NEW`` this variable does nothing, and the
|
||||||
|
:variable:`CMAKE_EXPORT_PACKAGE_REGISTRY` variable controls the behavior
|
||||||
|
instead.
|
||||||
|
|
||||||
See also :ref:`Disabling the Package Registry`.
|
See also :ref:`Disabling the Package Registry`.
|
||||||
|
|||||||
15
Help/variable/CMAKE_EXPORT_PACKAGE_REGISTRY.rst
Normal file
15
Help/variable/CMAKE_EXPORT_PACKAGE_REGISTRY.rst
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
CMAKE_EXPORT_PACKAGE_REGISTRY
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
|
Enables the :command:`export(PACKAGE)` command when :policy:`CMP0090`
|
||||||
|
is set to ``NEW``.
|
||||||
|
|
||||||
|
The :command:`export(PACKAGE)` command does nothing by default. In some cases
|
||||||
|
it is desirable to write to the user package registry, so the
|
||||||
|
``CMAKE_EXPORT_PACKAGE_REGISTRY`` variable may be set to enable it.
|
||||||
|
|
||||||
|
If :policy:`CMP0090` is *not* set to ``NEW`` this variable does nothing, and
|
||||||
|
the :variable:`CMAKE_EXPORT_NO_PACKAGE_REGISTRY` variable controls the behavior
|
||||||
|
instead.
|
||||||
|
|
||||||
|
See also :ref:`Disabling the Package Registry`.
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
#include "cmGlobalGenerator.h"
|
#include "cmGlobalGenerator.h"
|
||||||
#include "cmMakefile.h"
|
#include "cmMakefile.h"
|
||||||
#include "cmMessageType.h"
|
#include "cmMessageType.h"
|
||||||
|
#include "cmPolicies.h"
|
||||||
#include "cmStateTypes.h"
|
#include "cmStateTypes.h"
|
||||||
#include "cmSystemTools.h"
|
#include "cmSystemTools.h"
|
||||||
#include "cmTarget.h"
|
#include "cmTarget.h"
|
||||||
@@ -243,10 +244,23 @@ bool cmExportCommand::HandlePackage(std::vector<std::string> const& args)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the CMAKE_EXPORT_NO_PACKAGE_REGISTRY variable is set the command
|
// CMP0090 decides both the default and what variable changes it.
|
||||||
// export(PACKAGE) does nothing.
|
switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0090)) {
|
||||||
if (this->Makefile->IsOn("CMAKE_EXPORT_NO_PACKAGE_REGISTRY")) {
|
case cmPolicies::WARN:
|
||||||
return true;
|
case cmPolicies::OLD:
|
||||||
|
// Default is to export, but can be disabled.
|
||||||
|
if (this->Makefile->IsOn("CMAKE_EXPORT_NO_PACKAGE_REGISTRY")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case cmPolicies::REQUIRED_IF_USED:
|
||||||
|
case cmPolicies::REQUIRED_ALWAYS:
|
||||||
|
case cmPolicies::NEW:
|
||||||
|
// Default is to not export, but can be enabled.
|
||||||
|
if (!this->Makefile->IsOn("CMAKE_EXPORT_PACKAGE_REGISTRY")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We store the current build directory in the registry as a value
|
// We store the current build directory in the registry as a value
|
||||||
|
|||||||
@@ -264,6 +264,9 @@ class cmMakefile;
|
|||||||
3, 14, 0, cmPolicies::WARN) \
|
3, 14, 0, cmPolicies::WARN) \
|
||||||
SELECT(POLICY, CMP0089, \
|
SELECT(POLICY, CMP0089, \
|
||||||
"Compiler id for IBM Clang-based XL compilers is now XLClang.", 3, \
|
"Compiler id for IBM Clang-based XL compilers is now XLClang.", 3, \
|
||||||
|
15, 0, cmPolicies::WARN) \
|
||||||
|
SELECT(POLICY, CMP0090, \
|
||||||
|
"export(PACKAGE) does not populate package registry by default.", 3, \
|
||||||
15, 0, cmPolicies::WARN)
|
15, 0, cmPolicies::WARN)
|
||||||
|
|
||||||
#define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
|
#define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1)
|
||||||
|
|||||||
@@ -380,6 +380,7 @@ try_compile(EXPORTER_COMPILED
|
|||||||
${FindPackageTest_SOURCE_DIR}/Exporter
|
${FindPackageTest_SOURCE_DIR}/Exporter
|
||||||
CMakeTestExportPackage dummy
|
CMakeTestExportPackage dummy
|
||||||
CMAKE_FLAGS "-UCMAKE_EXPORT_NO_PACKAGE_REGISTRY"
|
CMAKE_FLAGS "-UCMAKE_EXPORT_NO_PACKAGE_REGISTRY"
|
||||||
|
"-DCMAKE_POLICY_DEFAULT_CMP0090:STRING=OLD"
|
||||||
-Dversion=${version}
|
-Dversion=${version}
|
||||||
OUTPUT_VARIABLE output)
|
OUTPUT_VARIABLE output)
|
||||||
message(STATUS "Searching for export(PACKAGE) test project")
|
message(STATUS "Searching for export(PACKAGE) test project")
|
||||||
@@ -417,6 +418,25 @@ if(CMakeTestExportPackage_FOUND)
|
|||||||
message(SEND_ERROR "CMakeTestExportPackage should not be FOUND!")
|
message(SEND_ERROR "CMakeTestExportPackage should not be FOUND!")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
message(STATUS "Remove export(PACKAGE) test project")
|
||||||
|
file(REMOVE_RECURSE ${FindPackageTest_BINARY_DIR}/Exporter-build)
|
||||||
|
|
||||||
|
message(STATUS "Preparing export(PACKAGE) test project with POLICY CMP0090=NEW")
|
||||||
|
try_compile(EXPORTER_COMPILED
|
||||||
|
${FindPackageTest_BINARY_DIR}/Exporter-build
|
||||||
|
${FindPackageTest_SOURCE_DIR}/Exporter
|
||||||
|
CMakeTestExportPackage dummy
|
||||||
|
CMAKE_FLAGS
|
||||||
|
"-DCMAKE_POLICY_DEFAULT_CMP0090:STRING=NEW"
|
||||||
|
-Dversion=${version}
|
||||||
|
OUTPUT_VARIABLE output)
|
||||||
|
message(STATUS "Searching for export(PACKAGE) test project")
|
||||||
|
find_package(CMakeTestExportPackage 1.${version} EXACT QUIET)
|
||||||
|
if(CMakeTestExportPackage_FOUND)
|
||||||
|
message(SEND_ERROR "CMakeTestExportPackage should not be FOUND!")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
# Test configure_package_config_file().
|
# Test configure_package_config_file().
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user