target_sources(Octopus_lib PRIVATE
		accel_blas.F90
		basis_vectors.F90
		blas.F90
                chebyshev_coefficients.F90
		checksum.c
		checksum_interface.F90
		compressed_sensing.F90
		cufft.cc
		dablas.c
		fft.F90
		fftw.F90
		fftw_low.c
		gauss_legendre.F90
		helmholtz_decomposition.F90
		helmholtz_decomposition_test.F90
		lalg_adv.F90
		lalg_basic.F90
		lapack.F90
		loct_math.F90
		math.F90
		maxwell_function.F90
		metis.F90
		metis_f.c
		minimizer.F90
		minimizer_tests.F90
		minimizer_low.c
		nfft.F90
		nfft_f.c
		oct_gsl_f.c
		pblas.F90
		permutations.F90
		pfft.F90
		pnfft.F90
		qshep.F90
		quickrnd.F90
		root_solver.F90
		scalapack.F90
		sgfft.F90
		solvers.F90
		sparskit.F90
		spline_filter.F90
		spline_low.cc
		splines.F90
		symm_op.F90
		tdfunction.F90
		ylm.c
		)

## External libraries
if (TARGET MKL::MKL)
	target_link_libraries(Octopus_lib PRIVATE MKL::MKL)
	# FFTW interface for mkl is not automatically set
	target_include_directories(Octopus_lib PRIVATE ${MKL_ROOT}/include/fftw)
	if (TARGET MKL::${MKL_SCALAPACK})
		target_link_libraries(Octopus_lib PRIVATE MKL::${MKL_SCALAPACK})
	endif ()
	if (OCTOPUS_ScaLAPACK AND NOT TARGET MKL::${MKL_SCALAPACK})
		message(FATAL_ERROR "Missing MKL ScaLAPACK target")
	endif ()
else ()
	target_link_libraries(Octopus_lib PRIVATE BLAS::BLAS)
	target_link_libraries(Octopus_lib PRIVATE LAPACK::LAPACK)
	if (HAVE_FFTW3_THREADS)
		# FFTW::OpenMP/Threads only contain small wrapper functions for the threading. Linking to the main library is
		# still necessary here
		if (TARGET FFTW::DoubleOpenMP)
			target_link_libraries(Octopus_lib PRIVATE FFTW::DoubleOpenMP)
		elseif ()
			target_link_libraries(Octopus_lib PRIVATE FFTW::DoubleThreads)
		endif ()
		target_link_libraries(Octopus_lib PRIVATE FFTW::Double)
	else ()
		target_link_libraries(Octopus_lib PRIVATE FFTW::Double)
	endif ()
	if (OCTOPUS_ScaLAPACK)
		target_link_libraries(Octopus_lib PRIVATE SCALAPACK::scalapack)
	endif ()
endif ()
if (TARGET ELPA::OpenMP)
	target_link_libraries(Octopus_lib PRIVATE ELPA::OpenMP)
elseif (TARGET ELPA::elpa)
	target_link_libraries(Octopus_lib PRIVATE ELPA::elpa)
endif ()
if (TARGET NLopt::nlopt)
	target_link_libraries(Octopus_lib PRIVATE NLopt::nlopt)
endif ()
if (TARGET nfft::nfft)
	target_link_libraries(Octopus_lib PRIVATE nfft::nfft)
endif ()
if (TARGET pfft::pfft)
	# Cannot link to FFTW-MPI when using MKL. See https://gitlab.com/octopus-code/octopus/-/issues/1167
	if (OCTOPUS_FFTW)
	# pfft requires FFTW::DoubleMPI but the external project's build system does not
	# find/link to it. See https://github.com/mpip/pfft/issues/40. As such, we do the linking.
	# Imported targets cannot be modified, so link FFTW::DoubleMPI directly to Octopus_lib
	# Alternatively one could create an interface target for pfft.
	    target_link_libraries(Octopus_lib PRIVATE pfft::pfft FFTW::DoubleMPI)
	endif ()    
endif ()
if (TARGET pnfft::pnfft)
	target_link_libraries(Octopus_lib PRIVATE pnfft::pnfft)
endif ()
if (TARGET METIS::metis)
	target_link_libraries(Octopus_lib PRIVATE METIS::metis)
	if (TARGET METIS::parmetis)
		target_link_libraries(Octopus_lib PRIVATE METIS::parmetis)
	endif ()
endif ()
if (TARGET SPARSKIT::sparskit)
	target_link_libraries(Octopus_lib PRIVATE SPARSKIT::sparskit)
endif ()
target_link_libraries(Octopus_lib PRIVATE qshep)
target_link_libraries(Octopus_lib PRIVATE bpdn)
