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

remove custom netcdf find function #19

Merged
merged 2 commits into from
Dec 4, 2024

Conversation

jedwards4b
Copy link
Collaborator

Remove the custom code used to find netcdf and use pkg_config instead.

@haampie
Copy link
Contributor

haampie commented Dec 4, 2024

I've used this PR plus the following diff

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 330c0fb..0404289 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -76,19 +76,19 @@ foreach (SRC_FILE IN LISTS CPRNC_GenF90_SRCS)
 endforeach ()
 
 #===== NetCDF =====
-pkg_check_modules(NetCDF REQUIRED netcdf)
+pkg_check_modules(NetCDF REQUIRED IMPORTED_TARGET netcdf)
 
 #===== NetCDF-Fortran =====
-pkg_check_modules(NetCDF_Fortran REQUIRED netcdf-fortran)
+pkg_check_modules(NetCDF_Fortran REQUIRED IMPORTED_TARGET netcdf-fortran)
 add_executable (cprnc ${CPRNC_Fortran_SRCS} ${CPRNC_GenF90_SRCS})
-target_include_directories(cprnc PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${NetCDF_Fortran_INCLUDE_DIRS})
+target_include_directories(cprnc PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
 
 add_dependencies (cprnc genf90)
 
 # Always use -fPIC
 set_property(TARGET cprnc PROPERTY POSITION_INDEPENDENT_CODE ON)
 target_link_libraries (cprnc
-    PUBLIC ${NetCDF_Fortran_LIBRARIES} ${NetCDF_LIBRARIES})
+    PUBLIC PkgConfig::NetCDF_Fortran PkgConfig::NetCDF)
 
 # We do not want cprnc injecting ctests into parent projects
 if (CPRNC_STANDALONE)

and verified that CMAKE_INSTALL_RPATH_USE_LINK_PATH works.

The upside of IMPORTED_TARGET is you need target_link_libraries only once, and it accounts for all cflags / ldflags.

@jedwards4b
Copy link
Collaborator Author

I also ran the cime test_self_build_cprnc:(test_sys_cime_case.TestCimeCase) ... ok

@jedwards4b jedwards4b requested review from jgfouca and removed request for jasonb5 December 4, 2024 17:02
Copy link
Contributor

@jgfouca jgfouca left a comment

Choose a reason for hiding this comment

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

This is a great change, thanks!

@jedwards4b jedwards4b merged commit 0b326fd into ESMCI:main Dec 4, 2024
1 check passed
@jedwards4b jedwards4b deleted the add_pkg_config branch December 4, 2024 17:40
@@ -74,17 +75,20 @@ foreach (SRC_FILE IN LISTS CPRNC_GenF90_SRCS)
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FILE}.in genf90)
endforeach ()

#===== NetCDF =====
pkg_check_modules(NetCDF REQUIRED IMPORTED_TARGET netcdf)

Choose a reason for hiding this comment

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

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

Successfully merging this pull request may close these issues.

4 participants