diff options
| author | Alex Merry <alex.merry@kde.org> | 2014-04-16 12:16:43 +0100 | 
|---|---|---|
| committer | Alex Merry <alex.merry@kde.org> | 2014-04-25 10:31:41 +0100 | 
| commit | 283aeda90db966de58f3c3ecdc1ce64f44ab849b (patch) | |
| tree | 7fd9c82cc9317ca2a1b33e4615e3d1b7ba0b261b | |
| parent | a92b1da58ea317a3a6d2e9c0d68fbf1b77518717 (diff) | |
| download | extra-cmake-modules-283aeda90db966de58f3c3ecdc1ce64f44ab849b.tar.gz extra-cmake-modules-283aeda90db966de58f3c3ecdc1ce64f44ab849b.tar.bz2 | |
ECMFindModuleHelpers: set traditional variables
The traditional *_LIBRARIES, *_INCLUDE_DIRS and *_DEFINITIONS do have
some uses - they make it easier to create package config files that use
found libraries in their link interface.  So this makes sure these
variables are set by ecm_find_package_handle_library_components() (and
hence by FindWayland.cmake and FindXCB.cmake).
REVIEW: 117585
| -rw-r--r-- | find-modules/FindWayland.cmake | 21 | ||||
| -rw-r--r-- | find-modules/FindXCB.cmake | 21 | ||||
| -rw-r--r-- | modules/ECMFindModuleHelpers.cmake | 71 | 
3 files changed, 85 insertions, 28 deletions
| diff --git a/find-modules/FindWayland.cmake b/find-modules/FindWayland.cmake index b7790e75..79c93c81 100644 --- a/find-modules/FindWayland.cmake +++ b/find-modules/FindWayland.cmake @@ -20,6 +20,18 @@  #     True if (the requestion version of) Wayland is available  # ``Wayland_VERSION``  #     Found Wayland version +# ``Wayland_TARGETS`` +#     A list of all targets imported by this module (note that there may be more +#     than the components that were requested) +# ``Wayland_LIBRARIES`` +#     This can be passed to target_link_libraries() instead of the imported +#     targets +# ``Wayland_INCLUDE_DIRS`` +#     This should be passed to target_include_directories() if the targets are +#     not used for linking +# ``Wayland_DEFINITIONS`` +#     This should be passed to target_compile_options() if the targets are not +#     used for linking  #  # For each searched-for components, ``Wayland_<component>_FOUND`` will be set to  # true if the corresponding Wayland library was found, and false otherwise.  If @@ -28,11 +40,10 @@  # determine ``Wayland_*_VERSION`` variables for each imported target, although  # ``Wayland_VERSION`` should normally be sufficient.  # -# The following variable will also be defined for convenience, and for -# compatibility with old-style find module conventions: -# -# ``Wayland_LIBRARIES`` -#     A list of all Wayland imported targets +# In general we recommend using the imported targets, as they are easier to use +# and provide more control.  Bear in mind, however, that if any target is in the +# link interface of an exported library, it must be made available by the +# package config file.  #=============================================================================  # Copyright 2014 Alex Merry <alex.merry@kde.org> diff --git a/find-modules/FindXCB.cmake b/find-modules/FindXCB.cmake index dd876b21..8027bdf3 100644 --- a/find-modules/FindXCB.cmake +++ b/find-modules/FindXCB.cmake @@ -27,6 +27,18 @@  #     True if (the requestion version of) xcb is available  # ``XCB_VERSION``  #     Found xcb version +# ``XCB_TARGETS`` +#     A list of all targets imported by this module (note that there may be more +#     than the components that were requested) +# ``XCB_LIBRARIES`` +#     This can be passed to target_link_libraries() instead of the imported +#     targets +# ``XCB_INCLUDE_DIRS`` +#     This should be passed to target_include_directories() if the targets are +#     not used for linking +# ``XCB_DEFINITIONS`` +#     This should be passed to target_compile_options() if the targets are not +#     used for linking  #  # For each searched-for components, ``XCB_<component>_FOUND`` will be set to  # true if the corresponding xcb library was found, and false otherwise.  If @@ -35,11 +47,10 @@  # ``XCB_*_VERSION`` variables for each imported target, although  # ``XCB_VERSION`` should normally be sufficient.  # -# The following variable will also be defined for convenience, and for -# compatibility with old-style find module conventions: -# -# ``XCB_LIBRARIES`` -#     A list of all XCB imported targets +# In general we recommend using the imported targets, as they are easier to use +# and provide more control.  Bear in mind, however, that if any target is in the +# link interface of an exported library, it must be made available by the +# package config file.  #=============================================================================  # Copyright 2011 Fredrik Höglund <fredrik@kde.org> diff --git a/modules/ECMFindModuleHelpers.cmake b/modules/ECMFindModuleHelpers.cmake index 15df9ef0..79bd6fb8 100644 --- a/modules/ECMFindModuleHelpers.cmake +++ b/modules/ECMFindModuleHelpers.cmake @@ -71,14 +71,27 @@  # in <name>_<component>_component_deps to be listed before <component> in the  # COMPONENTS argument.  # -# <name>_LIBRARIES will list the imported targets. +# The following variables will be set:  # -# <name>_VERSION will be set to the same as <name>_<component>_VERSION for -# the component that is searched for first (note that components are searched -# for in the order they are passed to the macro). - -# FIXME: we should actually set proper traditional variables, because it can -#        be convenient to use them in the link interface of exported libraries +# ``<name>_TARGETS`` +#   the imported targets +# ``<name>_LIBRARIES`` +#   the found libraries +# ``<name>_INCLUDE_DIRS`` +#   the combined required include directories for the components +# ``<name>_DEFINITIONS`` +#   the "other" CFLAGS provided by pkg-config, if any +# ``<name>_VERSION`` +#   the value of ``<name>_<component>_VERSION`` for the first component that +#   has this variable set (note that components are searched for in the order +#   they are passed to the macro), although if it is already set, it will not +#   be altered +# +# Note that these variables are never cleared, so if +# ecm_find_package_handle_library_components() is called multiple times with +# different components (typically because of multiple find_package() calls) then +# ``<name>_TARGETS``, for example, will contain all the targets found in any +# call (although no duplicates).  #=============================================================================  # Copyright 2014 Alex Merry <alex.merry@kde.org> @@ -184,11 +197,11 @@ macro(ecm_find_package_handle_library_components module_name)      find_package(PkgConfig)      foreach(ecm_fpwc_comp ${ECM_FPWC_COMPONENTS})          set(ecm_fpwc_dep_vars) -        set(ecm_fpwc_dep_libs) +        set(ecm_fpwc_dep_targets)          if(NOT SKIP_DEPENDENCY_HANDLING)              foreach(ecm_fpwc_dep ${${module_name}_${ecm_fpwc_comp}_component_deps})                  list(APPEND ecm_fpwc_dep_vars "${module_name}_${ecm_fpwc_dep}_FOUND") -                list(APPEND ecm_fpwc_dep_libs "${module_name}::${ecm_fpwc_dep}") +                list(APPEND ecm_fpwc_dep_targets "${module_name}::${ecm_fpwc_dep}")              endforeach()          endif() @@ -227,16 +240,38 @@ macro(ecm_find_package_handle_library_components module_name)              ${module_name}_${ecm_fpwc_comp}_INCLUDE_DIR          ) -        if(${module_name}_${ecm_fpwc_comp}_FOUND AND NOT TARGET ${module_name}::${ecm_fpwc_comp}) -            add_library(${module_name}::${ecm_fpwc_comp} UNKNOWN IMPORTED) -            set_target_properties(${module_name}::${ecm_fpwc_comp} PROPERTIES -                IMPORTED_LOCATION "${${module_name}_${ecm_fpwc_comp}_LIBRARY}" -                INTERFACE_COMPILE_OPTIONS "${PKG_${module_name}_${ecm_fpwc_comp}_DEFINITIONS}" -                INTERFACE_INCLUDE_DIRECTORIES "${${module_name}_${ecm_fpwc_comp}_INCLUDE_DIR}" -                INTERFACE_LINK_LIBRARIES "${ecm_fpwc_dep_libs}" -            ) -            list(APPEND ${module_name}_LIBRARIES "${module_name}::${ecm_fpwc_comp}") +        if(${module_name}_${ecm_fpwc_comp}_FOUND) +            list(APPEND ${module_name}_LIBRARIES +                        "${${module_name}_${ecm_fpwc_comp}_LIBRARY}") +            list(APPEND ${module_name}_INCLUDE_DIRS +                        "${${module_name}_${ecm_fpwc_comp}_INCLUDE_DIR}") +            set(${module_name}_DEFINITIONS +                    ${${module_name}_DEFINITIONS} +                    ${PKG_${module_name}_${ecm_fpwc_comp}_DEFINITIONS}) +            if(NOT TARGET ${module_name}::${ecm_fpwc_comp}) +                add_library(${module_name}::${ecm_fpwc_comp} UNKNOWN IMPORTED) +                set_target_properties(${module_name}::${ecm_fpwc_comp} PROPERTIES +                    IMPORTED_LOCATION "${${module_name}_${ecm_fpwc_comp}_LIBRARY}" +                    INTERFACE_COMPILE_OPTIONS "${PKG_${module_name}_${ecm_fpwc_comp}_DEFINITIONS}" +                    INTERFACE_INCLUDE_DIRECTORIES "${${module_name}_${ecm_fpwc_comp}_INCLUDE_DIR}" +                    INTERFACE_LINK_LIBRARIES "${ecm_fpwc_dep_targets}" +                ) +            endif() +            list(APPEND ${module_name}_TARGETS +                        "${module_name}::${ecm_fpwc_comp}")          endif()      endforeach() +    if(${module_name}_LIBRARIES) +        list(REMOVE_DUPLICATES ${module_name}_LIBRARIES) +    endif() +    if(${module_name}_INCLUDE_DIRS) +        list(REMOVE_DUPLICATES ${module_name}_INCLUDE_DIRS) +    endif() +    if(${module_name}_DEFINITIONS) +        list(REMOVE_DUPLICATES ${module_name}_DEFINITIONS) +    endif() +    if(${module_name}_TARGETS) +        list(REMOVE_DUPLICATES ${module_name}_TARGETS) +    endif()  endmacro() | 
