Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions components/cmake/build_model.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -263,19 +263,31 @@ macro(build_model COMP_CLASS COMP_NAME)
add_executable(${TARGET_NAME})
target_sources(${TARGET_NAME} PRIVATE ${REAL_SOURCES})

# driver-mct/main sources (e.g. cime_comp_mod.F90) use netcdf directly, but
# the component libraries only link netcdf PRIVATEly (via csm_share), so
# its usage requirements (e.g. include dirs for netcdf.mod) do not
# propagate up to this exe target. Find/link it explicitly here too.
find_package(NETCDF REQUIRED)
target_link_libraries(${TARGET_NAME} netcdf)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This was needed to build on GCE and is the subject of a separate PR #8655

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll wait for #8655 to be resolved and then rebase this or just remove this change.

foreach(ITEM IN LISTS COMP_CLASSES)
if (NOT ITEM STREQUAL "cpl")
target_link_libraries(${TARGET_NAME} ${ITEM})
endif()
endforeach()

# driver-mct/main sources (e.g. cime_comp_mod.F90) use netcdf directly, but
# the component libraries only link netcdf PRIVATEly (via csm_share), so
# its usage requirements (e.g. include dirs for netcdf.mod) do not
# propagate up to this exe target. Pull in just the include dirs here.
#
# Deliberately NOT using target_link_libraries(${TARGET_NAME} netcdf):
# CMake treats "netcdf" as a single graph node, so linking it directly to
# this executable pins its (and PnetCDF's) position to wherever it's
# first encountered, ahead of the component libraries below that also
# transitively link it via csm_share -> spio. But piof/pioc (also pulled
# in via csm_share -> spio) reference PnetCDF symbols, so libpnetcdf.a
# must come after them on the link line, or the linker drops its symbols
# before piof/pioc need them. Only requesting the include dirs avoids
# adding that extra, mis-ordering link edge, while the link libraries
# still reach this target correctly ordered via csm_share -> spio.
find_package(NETCDF REQUIRED)
get_target_property(NETCDF_INTERFACE_INCLUDE_DIRS netcdf INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(${TARGET_NAME} PRIVATE ${NETCDF_INTERFACE_INCLUDE_DIRS})

if (USE_MOAB)
target_link_libraries(${TARGET_NAME} ${MOAB_LIBRARIES})
target_include_directories(${TARGET_NAME} PRIVATE ${MOAB_INCLUDE_DIRS})
Expand Down
Loading