If you directly include netcdf-c in another CMake project, it fails to configure properly as it looks for several things in CMAKE_SOURCE_DIR which will be the parent CMake project's source directory, not the netcdf-c's source directory. This can be simply fixed by replacing it with CMAKE_CURRENT_SOURCE_DIR. The same applies for CMAKE_BINARY_DIR.
In order to quickly reproduce this issue, create a simple CMake project and add the following lines:
include(FetchContent)
FetchContent_Declare(
netcdf
GIT_REPOSITORY https://github.com/Unidata/netcdf-c.git
GIT_TAG v4.7.2
)
FetchContent_MakeAvailable(netcdf)
If you directly include netcdf-c in another CMake project, it fails to configure properly as it looks for several things in CMAKE_SOURCE_DIR which will be the parent CMake project's source directory, not the netcdf-c's source directory. This can be simply fixed by replacing it with CMAKE_CURRENT_SOURCE_DIR. The same applies for CMAKE_BINARY_DIR.
In order to quickly reproduce this issue, create a simple CMake project and add the following lines: