Skip to content
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

Set LINK_LIBRARIES_ONLY_TARGETS=TRUE by default and verify Trilinos is clean with CMake 3.23+ #10081

Open
bartlettroscoe opened this issue Jan 13, 2022 · 12 comments
Labels
DO_NOT_AUTOCLOSE This issue should be exempt from auto-closing by the GitHub Actions bot. PA: Framework Issues that fall under the Trilinos Framework Product Area type: enhancement Issue is an enhancement, not a bug

Comments

@bartlettroscoe
Copy link
Member

bartlettroscoe commented Jan 13, 2022

As discussed in TriBITSPub/TriBITS#299 (comment), CMake 3.23 will learn the target property LINK_LIBRARIES_ONLY_TARGETS that if set to TRUE, will help catch errors when linking against undefined targets. With the updated TriBITS, raw library names for external packages/TPLs are no longer directly passed to target_link_libraries() and therefore, unless people are directly calling target_link_libraries() against raw lib names in Trilinos CMakeLists.txt files, we should be able to set LINK_LIBRARIES_ONLY_TARGETS to true with Trilinos.

But before I felt confident about that, Trilinos would need to upgrade its minimum CMake version to CMake 3.23+ and all of the Trilinos PR and ATDM Trilinos builds would need to be tested with this option enabled with the upgraded CMake.

@bartlettroscoe bartlettroscoe added PA: Framework Issues that fall under the Trilinos Framework Product Area TriBITS Issues with the TriBITS framework itself, not usage of the TriBITS framework type: enhancement Issue is an enhancement, not a bug labels Jan 13, 2022
@bartlettroscoe bartlettroscoe removed the TriBITS Issues with the TriBITS framework itself, not usage of the TriBITS framework label Mar 17, 2022
@github-actions
Copy link

This issue has had no activity for 365 days and is marked for closure. It will be closed after an additional 30 days of inactivity.
If you would like to keep this issue open please add a comment and/or remove the MARKED_FOR_CLOSURE label.
If this issue should be kept open even with no activity beyond the time limits you can add the label DO_NOT_AUTOCLOSE.
If it is ok for this issue to be closed, feel free to go ahead and close it. Please do not add any comments or change any labels or otherwise touch this issue unless your intention is to reset the inactivity counter for an additional year.

@github-actions github-actions bot added the MARKED_FOR_CLOSURE Issue or PR is marked for auto-closure by the GitHub Actions bot. label Mar 18, 2023
@bartlettroscoe
Copy link
Member Author

@sebrowne, now that Trilinos is requiring CMake 3.23+, we can pull the trigger on this one. This will make the CMakeLists.txt files more robust and will be critical when refactoring to use raw library linking as listed in:

@github-actions github-actions bot removed the MARKED_FOR_CLOSURE Issue or PR is marked for auto-closure by the GitHub Actions bot. label Apr 12, 2023
@sebrowne
Copy link
Contributor

sebrowne commented Apr 26, 2023

So to clarify, this will turn "nonexistant" targets called with target_link_libaries(myTarget <TYPE> someBadTarget) into configure errors instead of doing lld: error: -lsomeBadTarget not found at link time?

@bartlettroscoe bartlettroscoe added the DO_NOT_AUTOCLOSE This issue should be exempt from auto-closing by the GitHub Actions bot. label Apr 26, 2023
@bartlettroscoe
Copy link
Member Author

So to clarify, this will turn "nonexistant" targets called with target_link_libaries(myTarget <TYPE> someBadTarget) into configure errors instead of doing lld: error: -lsomeBadTarget not found at link time?

@sebrowne, yes. From LINK_LIBRARIES_ONLY_TARGETS:

Enforce that link items that can be target names are actually existing targets.

Otherwise, if someone makes a mistake, you get a build-time error about a missing dependency (which is confusing for some people to figure out). That does not happen much with current TriBITS due to auto-linking between dependent package libraries but if Trilinos moves to manual linking (see TriBITSPub/TriBITS#569) then this will happen all of the time.

@sebrowne
Copy link
Contributor

I've already encountered this in my work on SIERRA's new build system, and like this behavior much better. Fully in favor.

@bartlettroscoe
Copy link
Member Author

FYI: The recent refactoring of the TriBITS legacy TPL system that creates proper CMake IMPORTED targets will allow Trilinos (and TriBITS) to set LINK_LIBRARIES_ONLY_TARGETS to TRUE by default and that will not break Trilinos configure scripts that are passing in raw library names.

@bartlettroscoe
Copy link
Member Author

@sebrowne, @ccober6, and @jwillenbring, this is another one that should be turned on for Trilinos 15.0.

@sebrowne
Copy link
Contributor

We'll get on it immediately (I'll write a small story and have the team take care of it prior to the release). Thanks for circling back!

sebrowne added a commit to sebrowne/Trilinos that referenced this issue Oct 4, 2023
As per trilinos#10081.

User Support Ticket(s) or Story Referenced: TRILFRAME-601
@bartlettroscoe
Copy link
Member Author

bartlettroscoe commented Oct 9, 2023

@sebrowne, FYI, I had to revert the merge of the PR:

with the revert PR:

because it was breaking the installed ZoltanConfig.cmake file, see:

First, we need to beef up the test TrilinosInstallTests_find_package_Trilinos defined at:

tribits_add_advanced_test(find_package_Trilinos

and:

cmake_minimum_required(VERSION 3.0)
# Disable Kokkos warning about not supporting C++ extensions
set(CMAKE_CXX_EXTENSIONS OFF)
project(find_package_Trilinos C CXX)
find_package(Trilinos REQUIRED)
message("Trilinos_FOUND = '${Trilinos_FOUND}'")
message("Trilinos_SELECTED_PACAKGES_LIST = '${Trilinos_SELECTED_PACAKGES_LIST}'")
message("Trilinos_LIBRARIES = '${Trilinos_LIBRARIES}'")

to try to expose this failure. I am surprised that test passed in all of the PR builds shown here before it was merged.

We should try adding a dummy executable as part of that dummy CMake project find_package_Trilinos and linking in the Trilinos libraries and see if it triggers that error reported in #12371.

As for setting CMAKE_LINK_LIBRARIES_ONLY_TARGETS=ON without causing these errors, there are a couple of options we can consider off the top of my head:

Option-1: Set the property LINK_LIBRARIES_ONLY_TARGETS=OFF just for those two targets that are linking in raw m.

Option-2: Create a new Trilinos TriBITS TPL MLib with the trivial file FindTPLMLib.cmake that defines the MLib TPL to just be TPL_MLib_LIBRARIES=m and then make Zoltan and SuiteSparse depend on MLib.

Option-1 involves less code but it seems like kind of a hack. Option-2 involves a little more overhead (in a new file FindTPLMLib.cmake and installing a file MLibConfig.cmake that has to be included in downstream <Package>Config.cmake files) but it very clean consistent with how the rest of TriBITS TPLs work.

NOTE: One option not to try to export the created imported target because CMake does not support that :-(

sebrowne added a commit to sebrowne/Trilinos that referenced this issue Oct 10, 2023
Add a dummy executable that depends on all of the built Trilinos
libraries to attempt to exercise some more failure cases.

Specifically, this is to try and make visible the failure where imported
toolchain libraries (e.g. libm) will not work in downstream builds due
to incomplete install logic.

User Support Ticket(s) or Story Referenced: TRILFRAME-601 trilinos#10081
@sebrowne
Copy link
Contributor

@bartlettroscoe I added that case to the test and tested it, it does work and catch the issue.

@bartlettroscoe
Copy link
Member Author

@sebrowne, now the question is how to deal with the m library. See options above.

But note that the current TriBITS implementation already checks that valid targets are used so that is why this issue with m was the only problem flagged when setting CMAKE_LINK_LIBRARIES_ONLY_TARGETS=TRUE.

sebrowne added a commit to sebrowne/Trilinos that referenced this issue Oct 11, 2023
Add a dummy executable that depends on all of the built Trilinos
libraries to attempt to exercise some more failure cases.

Specifically, this is to try and make visible the failure where imported
toolchain libraries (e.g. libm) will not work in downstream builds due
to incomplete install logic.

User Support Ticket(s) or Story Referenced: TRILFRAME-601 trilinos#10081
@bartlettroscoe
Copy link
Member Author

For now, we can put this back into the backlog since this is not worth fixing for now. If we get Trilinos internal packages using raw CMake, then we may want to try harder to turn this on and address the issue with the m library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DO_NOT_AUTOCLOSE This issue should be exempt from auto-closing by the GitHub Actions bot. PA: Framework Issues that fall under the Trilinos Framework Product Area type: enhancement Issue is an enhancement, not a bug
Projects
Development

No branches or pull requests

2 participants