Closed brhillman closed 3 years ago
Hi @brhillman, I have a PR open that should fix this -- please can you check if #100 works for you? It also exports the targets and makes sure a namespaced-alias is also created, which should allow your users to either build netcdf-cxx4 as part of your model build, or use an existing build. We use it like:
option(BOUT_DOWNLOAD_NETCDF_CXX4 "Download and build netCDF-cxx4" OFF)
if (BOUT_DOWNLOAD_NETCDF_CXX4)
include(FetchContent)
FetchContent_Declare(
netcdf-cxx4
GIT_REPOSITORY https://github.com/ZedThree/netcdf-cxx4
GIT_TAG "ad3e50953190615cb69dcc8a4652f9a88a8499cf"
)
# Don't build the netcdf tests, they have lots of warnings
set(NCXX_ENABLE_TESTS OFF CACHE BOOL "" FORCE)
# Use our own FindnetCDF module which uses nc-config
find_package(netCDF REQUIRED)
FetchContent_MakeAvailable(netcdf-cxx4)
else()
find_package(netCDFCxx REQUIRED)
endif()
target_link_libraries(bout++ PUBLIC netCDF::netcdf-cxx4)
@ZedThree yup that fixes it. Thank you! And thank you for the example usage! I'll close this issue.
We would like to use netcdf-cxx4 within a model that needs to run on a variety of large machines. In order to avoid maintaining modules that include netcdf-cxx4 on all of these machines, and because the library builds quickly, we would like to build netcdf-cxx4 as part of the model build. However, it appears that the use of
CMAKE_SOURCE_DIR
in the top-level CMakeLists.txt for netcdf-cxx4 to define the configure and tests paths prevents building the library viaadd_subdirectory
in a higher-level CMakeLists.txt. Changing occurrences ofCMAKE_SOURCE_DIR
toPROJECT_SOURCE_DIR
, however, fixes the problem, and seems to capture the intent of these lines in the CMakeLists.txt for netcdf-cxx4. That is, the following changes are sufficient:This is with current master (c244f2de7818d9562eeadee548811872d4ac2975) and should apply to all environments.