Printing "Found <package>..." message in config mode

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Printing "Found <package>..." message in config mode

Sebastián Mancilla
Normally, find modules call FIND_PACKAGE_HANDLE_STANDARD_ARGS, which in turn calls FIND_PACKAGE_MESSAGE, to print a nice message about the location and version of the dependency.

But I haven't found any way or example to do the same when using the CONFIG mode of find_package. And I really want to see some output about where the dependencies are located. So I came up with this:

    # Prints a message with the location and version of a package
    # found in config mode, similar to the message printed by module files.
    # When multiple configurations are installed, this tries to print
    # the location to the same library selected by the CMake generator.
    #
    # TODO: handle configuration mapping (?)
    function(find_package_config_message _package _target _version)
      # The location matching the same build configuration as downstream
      # is selected when linking to the library
      set(_build_type ${CMAKE_BUILD_TYPE})
      if (_build_type)
        string(TOUPPER "IMPORTED_LOCATION_${_build_type}" _location_prop)
        get_target_property(_location_path ${_target} ${_location_prop})
      endif()
      # If downstream has no build configuration set,
      # or the installed package has no matching configuration,
      # the first listed configuration is used to get the location to the library
      if(NOT _location_path)
        get_target_property(_target_configurations ${_target} IMPORTED_CONFIGURATIONS)
        if(_target_configurations)
          list(GET _target_configurations 0 _build_type)
          get_target_property(_location_path ${_target} "IMPORTED_LOCATION_${_build_type}")
        endif()
        if (NOT _location_path)
          message(SEND_ERROR "No imported location for target ${_target}")
        endif()
      endif()
    
      set(_message "Found ${_package}")
      set(_details "[${_build_type}]")
      if(_location_path)
        set(_message "${_message}: ${_location_path}")
        set(_details "[${_location_path}]${_details}")
      endif()
      if(_version)
        set(_message "${_message} (found version \"${_version}\")")
        set(_details "[${_version}]${_details}")
      endif()
      find_package_message(${_package} ${_message} ${_details})
    endfunction()

I think I got it right, based on the observed behavior while experimenting with different values for CMAKE_BUILD_TYPE on both upstream and downstream, and it works fine for most common cases.

I would use in the FooConfig.cmake like this (the function would be in FooHelpers.cmake):

    if(NOT TARGET Foo::Foo)
      include("${CMAKE_CURRENT_LIST_DIR}/FooTargets.cmake")
      include("${CMAKE_CURRENT_LIST_DIR}/FooHelpers.cmake")
      find_package_config_message(Foo Foo::Foo "@PROJECT_VERSION@")
    endif()

Any thoughts/comments?

--
Sebastian Mancilla

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Printing "Found <package>..." message in config mode

Hendrik Sattler


Am 14. August 2018 22:08:36 MESZ schrieb "Sebastián Mancilla" <[hidden email]>:
>Normally, find modules call FIND_PACKAGE_HANDLE_STANDARD_ARGS, which in
>turn calls FIND_PACKAGE_MESSAGE, to print a nice message about the
>location
>and version of the dependency.

You can do that with FIND_PACKAGE_HANDLE_STANDARD_ARGS, just use module name and CONFIG_MODE as arguments.

HS
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Printing "Found <package>..." message in config mode

Sebastián Mancilla
Ah, I see that FIND_PACKAGE_HANDLE_STANDARD_ARGS prints

   -- Find Foo: <path to FooConfig.cmake> (found version "<version>")

I guess my function is not necessary, I can just put inside FooConfig.cmake

    find_package_message(Foo
      "Found Foo: ${CMAKE_CURRENT_LIST_FILE} (found version \"@PACKAGE_VERSION@\")"
      "[${CMAKE_CURRENT_LIST_FILE}][@PACKAGE_VERSION@]")


El mar., 14 de ago. de 2018 a la(s) 19:36, Hendrik Sattler ([hidden email]) escribió:


Am 14. August 2018 22:08:36 MESZ schrieb "Sebastián Mancilla" <[hidden email]>:
>Normally, find modules call FIND_PACKAGE_HANDLE_STANDARD_ARGS, which in
>turn calls FIND_PACKAGE_MESSAGE, to print a nice message about the
>location
>and version of the dependency.

You can do that with FIND_PACKAGE_HANDLE_STANDARD_ARGS, just use module name and CONFIG_MODE as arguments.

HS
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: https://urldefense.proofpoint.com/v2/url?u=http-3A__www.cmake.org_Wiki_CMake-5FFAQ&d=DwIGaQ&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=vNaw4PX_cjIs-mDa1mqBspuYYh8zccYAIC84tyoB0oA&s=RJEEiZ1k-XIjXM_90_6kyZ5FMVIYsSAiyQRThYB3iJ8&e=

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: https://urldefense.proofpoint.com/v2/url?u=http-3A__cmake.org_cmake_help_support.html&d=DwIGaQ&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=vNaw4PX_cjIs-mDa1mqBspuYYh8zccYAIC84tyoB0oA&s=LqUR8QOw8X5ya0FRtvJ3J9e40LyNK-gydGXOeaM80Ps&e=
CMake Consulting: https://urldefense.proofpoint.com/v2/url?u=http-3A__cmake.org_cmake_help_consulting.html&d=DwIGaQ&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=vNaw4PX_cjIs-mDa1mqBspuYYh8zccYAIC84tyoB0oA&s=N5TtfB9fCMuIe6ZcnAzVHEk5w4MnGzNdZ8hI-zyiU5Y&e=
CMake Training Courses: https://urldefense.proofpoint.com/v2/url?u=http-3A__cmake.org_cmake_help_training.html&d=DwIGaQ&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=vNaw4PX_cjIs-mDa1mqBspuYYh8zccYAIC84tyoB0oA&s=aBTzKuF0iyTKifZQ6madT0vT189WJsgYDDf8jDL_JxI&e=

Visit other Kitware open-source projects at https://urldefense.proofpoint.com/v2/url?u=http-3A__www.kitware.com_opensource_opensource.html&d=DwIGaQ&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=vNaw4PX_cjIs-mDa1mqBspuYYh8zccYAIC84tyoB0oA&s=Wu5CbQmwVaf6uE5Dp9OK_EASEZ6WS16W0hVEXN_3BAo&e=

Follow this link to subscribe/unsubscribe:
https://urldefense.proofpoint.com/v2/url?u=https-3A__cmake.org_mailman_listinfo_cmake&d=DwIGaQ&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=vNaw4PX_cjIs-mDa1mqBspuYYh8zccYAIC84tyoB0oA&s=QViykHUMgtj8XqForeqtw7j16bUM3hAp3JTzSse90b8&e=


--
Sebastian Mancilla Matta
CCTVal, UTFSM
Valparaíso, Chile

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Printing "Found <package>..." message in config mode

Cyril Boucher
Hi Sebastiàn,

Your question got me thinking and I also figured that way of doing it works:

set(<package>_CONFIG ${CMAKE_CURRENT_LIST_FILE})
find_package_handle_standard_args(<package> CONFIG_MODE)

This allows you to keep most of the nice logic inside FindPackageHandleStandardArgs.

Best regards,
Cyril

2018-08-15 22:13 GMT+02:00 Sebastián Mancilla <[hidden email]>:
Ah, I see that FIND_PACKAGE_HANDLE_STANDARD_ARGS prints

   -- Find Foo: <path to FooConfig.cmake> (found version "<version>")

I guess my function is not necessary, I can just put inside FooConfig.cmake

    find_package_message(Foo
      "Found Foo: ${CMAKE_CURRENT_LIST_FILE} (found version \"@PACKAGE_VERSION@\")"
      "[${CMAKE_CURRENT_LIST_FILE}][@PACKAGE_VERSION@]")


El mar., 14 de ago. de 2018 a la(s) 19:36, Hendrik Sattler ([hidden email]) escribió:


Am 14. August 2018 22:08:36 MESZ schrieb "Sebastián Mancilla" <[hidden email]>:
>Normally, find modules call FIND_PACKAGE_HANDLE_STANDARD_ARGS, which in
>turn calls FIND_PACKAGE_MESSAGE, to print a nice message about the
>location
>and version of the dependency.

You can do that with FIND_PACKAGE_HANDLE_STANDARD_ARGS, just use module name and CONFIG_MODE as arguments.

HS
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: https://urldefense.proofpoint.com/v2/url?u=http-3A__www.cmake.org_Wiki_CMake-5FFAQ&d=DwIGaQ&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=vNaw4PX_cjIs-mDa1mqBspuYYh8zccYAIC84tyoB0oA&s=RJEEiZ1k-XIjXM_90_6kyZ5FMVIYsSAiyQRThYB3iJ8&e=

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: https://urldefense.proofpoint.com/v2/url?u=http-3A__cmake.org_cmake_help_support.html&d=DwIGaQ&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=vNaw4PX_cjIs-mDa1mqBspuYYh8zccYAIC84tyoB0oA&s=LqUR8QOw8X5ya0FRtvJ3J9e40LyNK-gydGXOeaM80Ps&e=
CMake Consulting: https://urldefense.proofpoint.com/v2/url?u=http-3A__cmake.org_cmake_help_consulting.html&d=DwIGaQ&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=vNaw4PX_cjIs-mDa1mqBspuYYh8zccYAIC84tyoB0oA&s=N5TtfB9fCMuIe6ZcnAzVHEk5w4MnGzNdZ8hI-zyiU5Y&e=
CMake Training Courses: https://urldefense.proofpoint.com/v2/url?u=http-3A__cmake.org_cmake_help_training.html&d=DwIGaQ&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=vNaw4PX_cjIs-mDa1mqBspuYYh8zccYAIC84tyoB0oA&s=aBTzKuF0iyTKifZQ6madT0vT189WJsgYDDf8jDL_JxI&e=

Visit other Kitware open-source projects at https://urldefense.proofpoint.com/v2/url?u=http-3A__www.kitware.com_opensource_opensource.html&d=DwIGaQ&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=vNaw4PX_cjIs-mDa1mqBspuYYh8zccYAIC84tyoB0oA&s=Wu5CbQmwVaf6uE5Dp9OK_EASEZ6WS16W0hVEXN_3BAo&e=

Follow this link to subscribe/unsubscribe:
https://urldefense.proofpoint.com/v2/url?u=https-3A__cmake.org_mailman_listinfo_cmake&d=DwIGaQ&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=vNaw4PX_cjIs-mDa1mqBspuYYh8zccYAIC84tyoB0oA&s=QViykHUMgtj8XqForeqtw7j16bUM3hAp3JTzSse90b8&e=


--
Sebastian Mancilla Matta
CCTVal, UTFSM
Valparaíso, Chile

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake



--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Printing "Found <package>..." message in config mode

Sebastián Mancilla
Thanks, Cyril

I did try find_package_handle_standard_args but it failed. It didn't occur to me that I needed to set <package_CONFIG before.

Now it is much better.

El jue., 16 de ago. de 2018 a la(s) 09:24, Cyril Boucher ([hidden email]) escribió:
Hi Sebastiàn,

Your question got me thinking and I also figured that way of doing it works:

set(<package>_CONFIG ${CMAKE_CURRENT_LIST_FILE})
find_package_handle_standard_args(<package> CONFIG_MODE)

This allows you to keep most of the nice logic inside FindPackageHandleStandardArgs.

Best regards,
Cyril

2018-08-15 22:13 GMT+02:00 Sebastián Mancilla <[hidden email]>:
Ah, I see that FIND_PACKAGE_HANDLE_STANDARD_ARGS prints

   -- Find Foo: <path to FooConfig.cmake> (found version "<version>")

I guess my function is not necessary, I can just put inside FooConfig.cmake

    find_package_message(Foo
      "Found Foo: ${CMAKE_CURRENT_LIST_FILE} (found version \"@PACKAGE_VERSION@\")"
      "[${CMAKE_CURRENT_LIST_FILE}][@PACKAGE_VERSION@]")


El mar., 14 de ago. de 2018 a la(s) 19:36, Hendrik Sattler ([hidden email]) escribió:


Am 14. August 2018 22:08:36 MESZ schrieb "Sebastián Mancilla" <[hidden email]>:
>Normally, find modules call FIND_PACKAGE_HANDLE_STANDARD_ARGS, which in
>turn calls FIND_PACKAGE_MESSAGE, to print a nice message about the
>location
>and version of the dependency.

You can do that with FIND_PACKAGE_HANDLE_STANDARD_ARGS, just use module name and CONFIG_MODE as arguments.

HS
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: https://urldefense.proofpoint.com/v2/url?u=http-3A__www.cmake.org_Wiki_CMake-5FFAQ&d=DwIGaQ&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=vNaw4PX_cjIs-mDa1mqBspuYYh8zccYAIC84tyoB0oA&s=RJEEiZ1k-XIjXM_90_6kyZ5FMVIYsSAiyQRThYB3iJ8&e=

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: https://urldefense.proofpoint.com/v2/url?u=http-3A__cmake.org_cmake_help_support.html&d=DwIGaQ&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=vNaw4PX_cjIs-mDa1mqBspuYYh8zccYAIC84tyoB0oA&s=LqUR8QOw8X5ya0FRtvJ3J9e40LyNK-gydGXOeaM80Ps&e=
CMake Consulting: https://urldefense.proofpoint.com/v2/url?u=http-3A__cmake.org_cmake_help_consulting.html&d=DwIGaQ&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=vNaw4PX_cjIs-mDa1mqBspuYYh8zccYAIC84tyoB0oA&s=N5TtfB9fCMuIe6ZcnAzVHEk5w4MnGzNdZ8hI-zyiU5Y&e=
CMake Training Courses: https://urldefense.proofpoint.com/v2/url?u=http-3A__cmake.org_cmake_help_training.html&d=DwIGaQ&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=vNaw4PX_cjIs-mDa1mqBspuYYh8zccYAIC84tyoB0oA&s=aBTzKuF0iyTKifZQ6madT0vT189WJsgYDDf8jDL_JxI&e=

Visit other Kitware open-source projects at https://urldefense.proofpoint.com/v2/url?u=http-3A__www.kitware.com_opensource_opensource.html&d=DwIGaQ&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=vNaw4PX_cjIs-mDa1mqBspuYYh8zccYAIC84tyoB0oA&s=Wu5CbQmwVaf6uE5Dp9OK_EASEZ6WS16W0hVEXN_3BAo&e=

Follow this link to subscribe/unsubscribe:
https://urldefense.proofpoint.com/v2/url?u=https-3A__cmake.org_mailman_listinfo_cmake&d=DwIGaQ&c=lz9TcOasaINaaC3U7FbMev2lsutwpI4--09aP8Lu18s&r=8hmSv9ww5s9qu3iT8h5WMi8-YcKXaJvelxT3fMih7S4&m=vNaw4PX_cjIs-mDa1mqBspuYYh8zccYAIC84tyoB0oA&s=QViykHUMgtj8XqForeqtw7j16bUM3hAp3JTzSse90b8&e=


--
Sebastian Mancilla Matta
CCTVal, UTFSM
Valparaíso, Chile

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake




--
Sebastian Mancilla Matta
CCTVal, UTFSM
Valparaíso, Chile

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake