Skip to content

Target-based find_package information from the command line

The current cmake --find-package does not support extracting information from imported targets. It would be nice to have a new mode which only supported imported targets so that we can get all of the proper information from them (find modules not using imported targets have lots of logic that go with them to figure out what variables are "important" that I'd like to avoid in the new mode). This also means that we still don't need to support try_compile and try_run in the new mode since generated config modules should not need those commands anyways.

Required information in order to do this:

  • languages to enable
  • components to pass
  • the compiler ID
  • what information to extract
  • the targets to extract information about

The skeleton code executed by the mode would be:

cmake_minimum_required(VERSION ${CMAKE_VERSION})

foreach (lang IN LISTS requested_languages)
  enable_language(${lang})
endforeach ()

find_package(${package} ${version} COMPONENTS ${components})

if (NOT targets)
  # This property does not exist; it'd be done in the C++ code.
  get_property(targets GLOBAL CMAKE_ALL_TARGETS)
endif ()

foreach (target IN LISTS target)
  # Also C++ code; multiple formats might be wanted, including:
  #   - JSON
  #   - command line (compile and link)
  target_dump(${target})
endforeach ()

The first step would be to add code for prototyping out target_dump on existing projects to ensure that we're getting the information we need. Then the "do the find_package" bit can be implemented afterwards and merged.

Cc: @brad.king @chuck.atkins

Edited by Ben Boeckel
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information