From 169f116632321e99701986f48a19e836d2b9e710 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 4 Dec 2014 23:19:45 +0100 Subject: Help: Link to cmake-packages(7) from the Module creation documentation. --- Help/manual/cmake-developer.7.rst | 4 +++- Help/manual/cmake-packages.7.rst | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Help/manual/cmake-developer.7.rst b/Help/manual/cmake-developer.7.rst index 672c9b7..c7bafc0 100644 --- a/Help/manual/cmake-developer.7.rst +++ b/Help/manual/cmake-developer.7.rst @@ -720,7 +720,9 @@ by the :command:`find_package` command when invoked for ````. The primary task of a find module is to determine whether a package exists on the system, set the ``_FOUND`` variable to reflect this and provide any variables, macros and imported targets required to -use the package. +use the package. A find module is useful in cases where an upstream +library does not provide a +:ref:`config file package `. The traditional approach is to use variables for everything, including libraries and executables: see the `Standard Variable Names`_ section diff --git a/Help/manual/cmake-packages.7.rst b/Help/manual/cmake-packages.7.rst index 0d18fd7..fba1d61 100644 --- a/Help/manual/cmake-packages.7.rst +++ b/Help/manual/cmake-packages.7.rst @@ -76,6 +76,8 @@ By setting the :variable:`CMAKE_DISABLE_FIND_PACKAGE_` variable to ``TRUE``, the ``PackageName`` package will not be searched, and will always be ``NOTFOUND``. +.. _`Config File Packages`: + Config-file Packages -------------------- -- cgit v0.12 From b96b025b2a337d7b09157f8b24cf9ca77a825863 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 4 Dec 2014 23:25:56 +0100 Subject: Help: Remove disadvantage creating IMPORTED targets in Find modules. An IMPORTED target in either type of package can equally depend on an IMPORTED target in a Find module, which must be found as a dependency, which is presumably the problem being implied. This is not a distinction of creating an IMPORTED target in a Find module. --- Help/manual/cmake-developer.7.rst | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Help/manual/cmake-developer.7.rst b/Help/manual/cmake-developer.7.rst index c7bafc0..f054d83 100644 --- a/Help/manual/cmake-developer.7.rst +++ b/Help/manual/cmake-developer.7.rst @@ -733,10 +733,7 @@ The more modern approach is to behave as much like ``Config.cmake`` files as possible, by providing imported targets. As well as matching how ``*Config.cmake`` files work, the libraries, include directories and compile definitions are all set just -by using the target in a :command:`target_link_libraries` call. The -disadvantage is that ``*Config.cmake`` files of projects that use -imported targets from find modules may require more work to make sure -those imported targets that are in the link interface are available. +by using the target in a :command:`target_link_libraries` call. In either case (or even when providing both variables and imported targets), find modules should provide backwards compatibility with old -- cgit v0.12 From 31452416ba1be692b55ed09f8cf39fa2914ad349 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 4 Dec 2014 23:30:20 +0100 Subject: Help: Add useful links to IMPORTED targets and usage requirements. --- Help/manual/cmake-developer.7.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Help/manual/cmake-developer.7.rst b/Help/manual/cmake-developer.7.rst index f054d83..d928097 100644 --- a/Help/manual/cmake-developer.7.rst +++ b/Help/manual/cmake-developer.7.rst @@ -730,10 +730,9 @@ below. This is what most of the existing find modules provided by CMake do. The more modern approach is to behave as much like -``Config.cmake`` files as possible, by providing imported -targets. As well as matching how ``*Config.cmake`` files work, the -libraries, include directories and compile definitions are all set just -by using the target in a :command:`target_link_libraries` call. +:ref:`config file packages ` files as possible, by +providing :ref:`imported target `. This has the advantage +of propagating :ref:`Target Usage Requirements` to consumers. In either case (or even when providing both variables and imported targets), find modules should provide backwards compatibility with old -- cgit v0.12 From f0d0d761b2150e41397af8cfce2b846107cf8921 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 4 Dec 2014 23:55:15 +0100 Subject: Help: Remove recommendation about checking minimum CMake version. If this file is being executed, the user has the CMake version providing it. --- Help/manual/cmake-developer.7.rst | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Help/manual/cmake-developer.7.rst b/Help/manual/cmake-developer.7.rst index d928097..94fc019 100644 --- a/Help/manual/cmake-developer.7.rst +++ b/Help/manual/cmake-developer.7.rst @@ -943,16 +943,6 @@ licence notice block # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) -If the module is new to CMake, you may want to provide a warning for -projects that do not require a high enough CMake version. - -.. code-block:: cmake - - if(CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 3.0.0) - message(AUTHOR_WARNING - "Your project should require at least CMake 3.0.0 to use FindFoo.cmake") - endif() - Now the actual libraries and so on have to be found. The code here will obviously vary from module to module (dealing with that, after all, is the point of find modules), but there tends to be a common pattern for libraries. -- cgit v0.12 From e18e21aeb52923d470680aa171f722b4d3b5d01d Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 4 Dec 2014 23:56:21 +0100 Subject: Help: Document IMPORTED_CONFIGURATIONS target property for Find modules. --- Help/manual/cmake-developer.7.rst | 41 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/Help/manual/cmake-developer.7.rst b/Help/manual/cmake-developer.7.rst index 94fc019..6f7bbdc 100644 --- a/Help/manual/cmake-developer.7.rst +++ b/Help/manual/cmake-developer.7.rst @@ -876,7 +876,10 @@ To prevent users being overwhelmed with settings to configure, try to keep as many options as possible out of the cache, leaving at least one option which can be used to disable use of the module, or locate a not-found library (e.g. ``Xxx_ROOT_DIR``). For the same reason, mark -most cache options as advanced. +most cache options as advanced. For packages which provide both debug +and release binaries, it is common to create cache variables with a +``_LIBRARY_`` suffix, such as ``Foo_LIBRARY_RELEASE`` and +``Foo_LIBRARY_DEBUG``. While these are the standard variable names, you should provide backwards compatibility for any old names that were actually in use. @@ -1049,6 +1052,42 @@ not any of its dependencies. Instead, those dependencies should also be targets, and CMake should be told that they are dependencies of this target. CMake will then combine all the necessary information automatically. +If the library is available with multiple configurations, the +:prop_tgt:`IMPORTED_CONFIGURATIONS` target property should also be +populated: + +.. code-block:: cmake + + if(Foo_FOUND) + if (NOT TARGET Foo::Foo) + add_library(Foo::Foo UNKNOWN IMPORTED) + endif() + if (Foo_LIBRARY_RELEASE) + set_property(TARGET Foo::Foo APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE + ) + set_target_properties(Foo::Foo PROPERTIES + IMPORTED_LOCATION_RELEASE "${Foo_LIBRARY_RELEASE}" + ) + endif() + if (Foo_LIBRARY_DEBUG) + set_property(TARGET Foo::Foo APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG + ) + set_target_properties(Foo::Foo PROPERTIES + IMPORTED_LOCATION_DEBUG "${Foo_LIBRARY_DEBUG}" + ) + endif() + set_target_properties(Foo::Foo PROPERTIES + INTERFACE_COMPILE_OPTIONS "${PC_Foo_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${Foo_INCLUDE_DIR}" + ) + endif() + +The ``RELEASE`` variant should be listed first in the property +so that that variant is chosen if the user uses a configuration which is +not an exact match for any listed ``IMPORTED_CONFIGURATIONS``. + We should also provide some information about the package, such as where to download it. -- cgit v0.12 From 67cb50abd77dddc3cc74597efe38285f9bc9e4cf Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 4 Dec 2014 23:56:52 +0100 Subject: Help: Document that IMPORTED targets in Find modules may be UNKNOWN. --- Help/manual/cmake-developer.7.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Help/manual/cmake-developer.7.rst b/Help/manual/cmake-developer.7.rst index 6f7bbdc..3b9b921 100644 --- a/Help/manual/cmake-developer.7.rst +++ b/Help/manual/cmake-developer.7.rst @@ -1052,6 +1052,11 @@ not any of its dependencies. Instead, those dependencies should also be targets, and CMake should be told that they are dependencies of this target. CMake will then combine all the necessary information automatically. +The type of the :prop_tgt:`IMPORTED` target created in the +:command:`add_library` command can always be specified as ``UNKNOWN`` +type. This simplifies the code in cases where static or shared variants may +be found, and CMake will determine the type by inspecting the files. + If the library is available with multiple configurations, the :prop_tgt:`IMPORTED_CONFIGURATIONS` target property should also be populated: -- cgit v0.12