TriBITSPub / TriBITS

TriBITS: Tribal Build, Integrate, and Test System,
http://tribits.org
Other
36 stars 46 forks source link

Export informational variables to `<Package>Config.cmake` files for downstream CMake projects #516

Closed bartlettroscoe closed 2 years ago

bartlettroscoe commented 2 years ago

Parent Issue

Description

It is often the case that downstream CMake projects need to know how an upstream CMake project was configured and what features it supports. For example:

Proposed solution

The proposed solution is to provide an easy mechanism for a TriBITS packages to make sure that the values of select cache vars are set in the generated <Package>Config.cmake file. For example, TriBITS could provide the function:

tribits_pkg_export_cache_var(<cacheVarName>)

such that when called, the variable <cacheVarName> and its value would get written into the <Package>Config.cmake files for the package and its subpackages (if the package has subpackages). There would be code in tribits_pkg_export_cache_var() that asserted that the cache variable <cacheVarName> existing and it was indeed a cache var (so that internal downstream packages can already see the value).

Then many of the standard TriBITS variables like tribits_add_option_and_define(<userOptionName> <macroDefineName> ...) would call tribits_pkg_export_cache_var(<userOptionName>) and tribits_pkg_export_cache_var(<macroDefineName>) (when those functions are called with a package scope). Other examples of standard TriBITS option-setting functions that would call tribits_pkg_export_cache_var() are tribits_add_debug_option(), ???.

And to avoid duplication, we could provide TriBITS functions tribits_pkg_set_option_and_export(<optionName> <defaultVal>) and tribits_pkg_set_and_export(<varName> <defaultVal> CACHE <type> "<doc>") and packages could refactor that currently calls option(<optionName> <defaultVal>) and set(<varName> <defaultVal> CACHE <type> "<doc>"), respectively.

NOTE: The precedent of exporting <Package>_ENABLE_<something> variables into <Package>Config.cmake files has already been done for the direct upstream dependencies of a TriBITS package to tell downstream CMake projects what upstream dependencies are enabled for a given packages. An example of this is in TribitsExampleApp2:

https://github.com/TriBITSPub/TriBITS/blob/4c184b45cdf73b14da2c026e97203238c65f87f4/tribits/examples/TribitsExampleApp2/AppHelperFuncs.cmake#L144-L162

bartlettroscoe commented 2 years ago

With the merge of PRs #520 and #521, I think enough of this scope is done. I will defer the implementation of the macros tribits_pkg_set_option_and_export(<optionName> <defaultVal>) and tribits_pkg_set_and_export(<varName> <defaultVal> CACHE <type> "<doc>") until later, if they are needed.

I will put in review for now.

bartlettroscoe commented 2 years ago

Irina Tezaur confirmed that this works for the Anasazi_ENABLE_RBGen case described above.

Closing as complete.