-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add, use, and document new function tribits_external_package_create_imported_all_libs_target_and_config_file() (#299) #493
Conversation
I think this needs to be a CMake code formatting guideline. It makes the code more readable since CMake lacks commas to seprate arguments.
…nd_config_file() (TriBITSPub#299) This is a reusable function that can be used with many other such FindTPL<tplName>.cmake files that call find_package(<externalPkg>) that defines imported targets.
…Pub#299) Now all of the TribitsExampleProject2 TPLs Tpl1, Tpl2, Tpl3, and Tpl4 all can call: tribits_external_package_create_imported_all_libs_target_and_config_file() to be able to use the externally generated `<externalPkg>Config.cmake` files. I also updated the tests for TribitsExampleProject2 and TribitsExampleApp2 to ensure that find_package() is being called (by grepping the output). I feel pretty good about these tests. TribitsExampleProject2
…SPub#299) It just points to the maintainers guide for now. May need a local users guide reference for this.
…nabledTpl.cmake (TriBITSPub#299) This makes it so that individual FindTPL<tplName>.cmake files don't need to include this module.
I noticed this while working on TriBITSPub#299 so I decided to just fix this.
I did several things here: * Updated howto for creating TriBITS FindTPL<tplName>.cmake files to cover all cases with more examples. This also covers the new function tribits_external_package_create_imported_all_libs_target_and_config_file() * Changed section name from "Addtional Topics" to "Miscellaneous Topics" * Changes section name from "TriBITS TPL" to "TriBITS External Package/TPL" but provided anchor `TriBITS TPL`_ so I did not have to update all of the references. * Provided subsections for TriBITS External Package/TPL files and variables * Moved detailed material on tricky aspects of find_package() and <tplName>Config.cmake files to a new section "Tricky considerations for TriBITS-generated <tplName>Config.cmake files". * Added references to documentation for the functions in the module TribitsExternalPackageWriteConfigFile.cmake.
…nd_config_file() (TriBITSPub/TriBITS#299) This uses the new function tribits_external_package_create_imported_all_libs_target_and_config_file() added in the TriBITS PR TriBITSPub/TriBITS#493 to work correctly with new TriBITS.
I am going to go ahead and merge so we can get the updated documentation built and deployed. Then I will request a post-merge review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Going to merge so we can see the updated documentation and so we can update TriBITS in sandialabs/seacas#317, the merge sandialabs/seacas#322 and verify that the problem is resolved.
I will then request a post-merge review.
Hello @KyleFromKitware, can you please do a post-merge review of this PR? Please see the notes above in the section "Notes to post-merge reviewers". Hello @gsjaardema, can you please look over the updated documentation related to writing and upgrading and especially in the section: ? That should solve the problem with |
FYI @keitat |
@@ -15,6 +15,13 @@ understand the internals of TriBITS. | |||
@MACRO: tribits_adjust_package_enables() + | |||
@FUNCTION: tribits_append_forward_dep_packages() + | |||
@MACRO: tribits_assert_read_dependency_vars() + | |||
@FUCNTION: tribits_external_package_append_upstream_target_link_libraries_get_name_and_vis() + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be @FUNCTION
, not @FUCNTION
@@ -15,6 +15,13 @@ understand the internals of TriBITS. | |||
@MACRO: tribits_adjust_package_enables() + | |||
@FUNCTION: tribits_append_forward_dep_packages() + | |||
@MACRO: tribits_assert_read_dependency_vars() + | |||
@FUCNTION: tribits_external_package_append_upstream_target_link_libraries_get_name_and_vis() + | |||
@FUNCTION: tribits_external_package_add_find_upstream_dependencies_str() + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the difficulties I often have with reviewing TriBITS is the very long names of functions. Because there's no Prefix_CamelCase
or prefix__snake_case
, there's not a clear distinction between the prefix and the function name. I know public-facing functions can't be changed due to backwards compatibility, but it would be nice if internal functions used some clearer naming, like ExternalProject_Add
which CMake has.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CC: @keitat
Yea, I see the problem. I will need to think about how to resolve this. How about going with the concept of collections of functions and using a prefix with CamelCase like TribitisExtPkg_add_find_upstream_dependencies_str()
instead of tribits_external_package_add_find_upstream_dependencies_str()
? If you go with CamelCase, you could do TribitisExtPkg_addFindUpstreamDependenciesStr()
. An issue with CMake is that command calls are case insensitive so people could call that as tribitisextpkg_addfindupstreamdependenciesstr()
which is completely unreadable. I guess all things considered, I would rather type and read TribitisExtPkg_addFindUpstreamDependenciesStr()
than tribits_external_package_add_find_upstream_dependencies_str()
. And we can use case-insensitive greps to find all occurrences of a function.
If you look at most of the public-facing TriBITS functions worth documenting at TriBITS Macros and Functions, you will see that some of them are grouped as:
tribits_package_xxx()
tribits_tpl_xxx()
so those could become:
TribitsPkg_xxx()
TribitsExtPkg_xxx()
(because we are changing the name from "TPL" to "External Package" as part of #63).
There is a desire to break TriBITS up into smaller collections of reusable software components (i.e. #368) and we could give each of these "components" a single prefix, such as TribitsTesting_
for all of the testing-related functions and macros.
What we need is a CMake coding standards guide for larger software collections written in CMake that helps to address problems like this and other issues since CMake lacks core language features that other languages have (like module scoping).
As for backward compatibility, this is now the time to break that and we could support function renaming with deprecated wrappers (i.e. #429) or with renaming scripts that clients can run on their code when they upgrade. (The former is more work but is a better path.)
But I would like to hold off on a major renaming of TriBITS functions until we get the epic #367 completed while trying to avoid breaking backward compatibility as much as possible. But after that epic is complete, we need to set our sights on the larger refactorings to further componentize TriBITS Core (i.e. #368) and modernize it (i.e. #411).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KyleFromKitware, also note that the function:
tribits_external_package_append_upstream_target_link_libraries_get_name_and_vis()
is being renamed to:
tribits_external_package_get_dep_name_and_vis()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you go with CamelCase, you could do TribitisExtPkg_addFindUpstreamDependenciesStr(). An issue with CMake is that command calls are case insensitive so people could call that as tribitisextpkg_addfindupstreamdependenciesstr() which is completely unreadable.
Yes, and the answer to this problem is "don't do that".
FWIW, I would use UpperCamelCase_UpperCamelCase
rather than UpperCamelCase_lowerCamelCase
. That's the convention used by ExternalProject
and FetchContent
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a short-term compromise, how about I change the long prefix tribits_external_package_
to the shorter prefix tribits_extpkg_
? As these are new functions that have not been technically synced to Trilinos yet, it is fine to change the name now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds fine to me - it's ultimately up to you on how to name it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I would use
UpperCamelCase_UpperCamelCase
rather thanUpperCamelCase_lowerCamelCase
. That's the convention used byExternalProject
andFetchContent
.
I am just so used to coding conventions where proper nouns for package names, namespaces, and modules use UpperCamelCase
but verbs for function and macro names use lowerCamelCase()
. In C++, the function would be named TribitisExtPkg::addFindUpstreamDependenciesStr()
. So a direct mapping to CMake would be to replace :
with _
with TribitisExtPkg_addFindUpstreamDependenciesStr()
. I guess to make this more clear/formal we could use a double underscore __
to replace :
so it would be TribitisExtPkg__addFindUpstreamDependenciesStr()
. It is all what you are used to I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could support function renaming with deprecated wrappers (i.e. #429)
If you're using a new enough CMake, here's a convenient way to add deprecated aliases for functions:
function(add_deprecated_alias alias name)
cmake_language(EVAL CODE "
macro(${alias})
message(DEPRECATION \"${alias} is deprecated - use ${name} instead\")
${name}(\${ARGN})
endmacro()")
endfunction()
Note that this doesn't get you perfect argument forwarding, which unfortunately is impossible with the current state of CMake.
This adds the new module TribitsExternalPackageFindTplHelpers.cmake with the new function tribits_external_package_create_imported_all_libs_target_and_config_file(). This makes it very smooth and easy to use
find_package(<externalPkg>)
that creates proper IMPORTED targets.Using the new function will fix the problem with
FindTPLGTest.cmake
reported in sandialabs/seacas#317 (comment).Things done here:
Added new module
TribitsExternalPackageFindTplHelpers.cmake
and functiontribits_external_package_create_imported_all_libs_target_and_config_file()
and used it to upgrade theFindTPL<tplName>.cmake
modules for TribitsExampleProject2 (and updated tests to make sure they work).Updated documentation and howto for adding a new TriBITS TPL and write the
FindTPL<tplName>.cmake
file. (Hopefully this new documentation will be easier to find the code example that a particularFindTPL<tplName>.cmake
file should follow.)Notes to post-merge reviewers