Non-library entities added to NC_FLIBS (CMakeLists.txt)
jtfrey opened this issue · comments
Versions: 4.5.4, 4.6.0
The CMake build system creates the list of library dependencies in NC_FLIBS
by looping over the link libraries associated with the netcdff
target:
get_target_property(ALL_TLL_LIBS netcdff LINK_LIBRARIES)
FOREACH(_LIB ${ALL_TLL_LIBS})
:
One item in the LINK_LIBRARIES
list is the netcdff_c
library — which is declared as an OBJECT library in fortran/CMakeLists.txt
. An OBJECT library does not produce a STATIC or SHARED library, just a set of object files. Nevertheless, -lnetcdff_c
gets added to NC_FLIBS
and ends up in the nf-config
script. For builds using MPI, an additional non-library dependency MPI::MPI_Fortran
exists in LINK_LIBRARIES
and gets added as -lMPI::MPI_Fortran
to nf-config
.
The result is that any build system using nf-config
to generate a library dependency list includes these non-library components that cannot be resolved by the linker:
$ nf-config --flibs
-L/opt/shared/netcdf-fortran/4.5.4/lib -lnetcdff -lnetcdf -lnetcdf -lnetcdff_c
and
$ nf-config --flibs
-L/opt/shared/netcdf-fortran/4.5.4-openmpi/lib -lnetcdff -lnetcdf -lnetcdf -lnetcdff_c -lMPI::MPI_Fortran
Thanks; let me take a look at how to clean this up!