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

CMake: Improve dependency management for mct and csm_share #5964

Merged
merged 23 commits into from
Oct 5, 2023

Conversation

jgfouca
Copy link
Member

@jgfouca jgfouca commented Sep 27, 2023

Neither of these packages are cmake packages, so we have to roll our own Find$package.cmake modules. These can be pretty simple for e3sm since we build them ourselves (no worries about version or not found etc).

Also, remove a lot of unused for special handling of clm and stuff for pio building.

[BFB]

@jgfouca jgfouca added Land BFB PR leaves answers BFB CMake build system labels Sep 27, 2023
@jgfouca jgfouca self-assigned this Sep 27, 2023
@jgfouca jgfouca mentioned this pull request Sep 27, 2023
49 tasks
Copy link
Contributor

@bartgol bartgol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly good. I have some suggestions, you can decide what's worth adding.

Btw, are you thinking of changing share/util/CMakeLists.txt to actually be a cmake project, rather than whatever it is now?

add_library(mct INTERFACE)
target_link_libraries(mct INTERFACE ${MCT_LIB} ${MPEU_LIB})
target_include_directories(mct INTERFACE ${INSTALL_SHAREDPATH}/include)
target_compile_definitions(mct INTERFACE "MCT_INTERFACE")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I grepped for MCT_INTERFACE in the whole repo+submodules, and I can't see where it is used. I see it set in the CPPDEFS var, but never used. Maybe we can get rid of this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also not sure where this is use but there is code in CIME to allow MCT or MOAB to be used as the coupler. We need to keep that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean we need to keep ability to use MOAB, not "keep MCT_INTERFACE in CPPDEFS", right?

Also, is there an example in e3sm of a compset using moab instead of mct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's what I mean.

Its not in master yet but you can run a moab case on this branch (on Chrysalis only for now) https://github.com/sarich/E3SM/tree/sarich/moab/update-moab-driver
e.g. ./create_test SMS_Vmoab.ne4pg2_oQU480.WCYCL1850NS

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MCT_INTERFACE does not appear to be used in CIME either, but there's not much harm in keeping it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imho, if something is unused (and pointless), it should be removed. Pointless code tends to pile up, until we have no idea of what is actually needed/used. I vote for pruning it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are right.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rljacob , I looked at Sarich's Moab branch and he's not using this cppdef there either.

components/cmake/modules/FindCsmShare.cmake Outdated Show resolved Hide resolved
@jgfouca
Copy link
Member Author

jgfouca commented Sep 28, 2023

Hmm, it looks like the CI build fails with a link error for the case it tries to build. The same case builds fine on mappy so I may have some digging to do.

@@ -29,7 +29,7 @@ endif()

# Create the interface library, and set target properties
add_library (csm_share INTERFACE)
target_link_libraries (csm_share INTERFACE ${CSM_SHARE_LIB};mct;${PIOLIBS})
target_link_libraries (csm_share INTERFACE ${CSM_SHARE_LIB};mct;spio)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we maybe to the same thing we did for MCT also for spio? That is, adding

find_package(PIO)

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, did exactly that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant adding it inside the FindCsmShare.cmake module.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. Yes let me do that.

# Have to do this here for now because the macros must be loaded in order for
# the netcdf cmake variables to be set. Once scorpio has a good package-config,
# this won't be necessary
if (NOT TARGET netcdf)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this if guard. subsequent calls to find_package will do nothing if the package was already found...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that depends on the implementation, but I'm not sure. I wanted to keep the findX modules as simple as possible, so they don't set or check XX_FOUND

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think CMake states it clearly

Once one of the calls succeeds the result variable will be set and stored in the cache so that no call will search again.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could be for find_package when it does things the "normal" way, IE loading the package-config.cmake. When you are rolling your own find module, I don't think this is true. The example FindXXX.cmake guidance in the documentation has all that stuff explicit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, no big deal. I think the logic for skipping second calls works regardless of search mode (provided that FindXXX.cmake sets <PackageName>_FOUND=TRUE). But I am not entirely sure, so let's not stop progress based on this detail.

components/cmake/modules/FindNETCDF.cmake Outdated Show resolved Hide resolved
components/cmake/modules/FindNETCDF.cmake Outdated Show resolved Hide resolved
components/cmake/modules/FindPIO.cmake Show resolved Hide resolved
components/cmake/modules/FindNETCDF.cmake Outdated Show resolved Hide resolved
@jgfouca jgfouca requested a review from bartgol September 28, 2023 22:13
jgfouca added a commit that referenced this pull request Sep 29, 2023
CMake: Improve dependency management for mct and csm_share

Neither of these packages are cmake packages, so we have to roll our
own Find$package.cmake modules. These can be pretty simple for e3sm
since we build them ourselves (no worries about version or not found
etc).

Also, remove a lot of unused for special handling of clm and stuff for
pio building.

[BFB]
jgfouca added a commit that referenced this pull request Oct 2, 2023
Second merge to next for this PR.

[BFB]
jgfouca added a commit that referenced this pull request Oct 2, 2023

# Create the interface library, and set target properties
add_library(netcdf INTERFACE)
target_link_libraries(netcdf INTERFACE ${pnetcdf_lib};${netcdf_c_lib};${netcdf_f_lib})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
target_link_libraries(netcdf INTERFACE ${pnetcdf_lib};${netcdf_c_lib};${netcdf_f_lib})
target_link_libraries(netcdf INTERFACE ${pnetcdf_lib};${netcdf_f_lib};${netcdf_c_lib})

jgfouca added a commit that referenced this pull request Oct 3, 2023
Fourth merge to next for this PR.

[BFB]
jgfouca added a commit that referenced this pull request Oct 4, 2023
@jgfouca jgfouca merged commit 2ff3742 into master Oct 5, 2023
2 checks passed
@jgfouca jgfouca deleted the jgfouca/cmake_mct_csm_share branch October 5, 2023 17:47
@rljacob
Copy link
Member

rljacob commented Oct 5, 2023

This branch looks like it did a lot of work on the netcdf/pnetcdf dependency but that's not mentioned in the title or description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants