## Internal objects
# Basic objects and interface
add_library(fortran_cli OBJECT)
target_link_libraries(fortran_cli PRIVATE Octopus_base)

# Dependent objects
set(OctopusDependentObjects "")
list(APPEND OctopusDependentObjects
		basic_mpi # Depends on mpi (optional)
		dftbplus_dftb # Depends on dftbplus (optional)
		electrons_v_ks # Depends on dftd3 (bundled)
		ions_symmetries # Depends on spglib (bundled)
		math_blas # Depends on blas (required)
		math_bpdn # Depends on bpdn (bundled)
		math_fft # Depends on FFT libraries (various)
		math_lapack # Depends on lapack libraries (required)
		math_metis # Depends on metis (bundled)
		math_qshep # Depends on qshep (bundled)
		output_berkeleygw # Depends on berkeleygw (optional)
		species_rapidxml # Depends on rapidxml (bundled)
		# Breaks naming convention, but this one is all over the place
		xc_oct # Depends on libxc (required)
		)
# Folder based objects
set(OctopusFolderObjects "")
list(APPEND OctopusFolderObjects
		basic
		basis_set
		boxes
		classical
		communication
		electrons
		grid
		hamiltonian
		interactions
		ions
		math
		maxwell
		modelmb
		multisystem
		opt_control
		output
		photons
		poisson
		scf
		species
		states
		sternheimer
		td
		xc
		)

foreach (subdir IN LISTS OctopusFolderObjects)
	add_subdirectory(${subdir})
endforeach ()
# Leftover directories
add_subdirectory(dftbplus)
add_subdirectory(include)
add_subdirectory(library)
add_subdirectory(main)
add_subdirectory(utils)

if (OCTOPUS_NATIVE)
	foreach (lang IN ITEMS C CXX Fortran)
		if (CMAKE_${lang}_COMPILER_ID MATCHES "Intel")
			target_compile_options(Octopus_lib PRIVATE $<$<COMPILE_LANGUAGE:${lang}>:-xHost>)
		else ()
			if (NOT CMAKE_${lang}_COMPILER_ID MATCHES "(^GNU|^CLANG|LLVM)")
				message(WARNING "Unknown compiler flags for ${lang}: ${CMAKE_${lang}_COMPILER_ID}. Using -march=native")
			endif ()
			target_compile_options(Octopus_lib PRIVATE $<$<COMPILE_LANGUAGE:${lang}>:-march=native>)
		endif ()
	endforeach ()
endif ()


if (OCTOPUS_INSTALL)
	install(CODE [===[
			if (DEFINED CACHE{CMAKE_INSTALL_PREFIX} AND NOT OCTOPUS_INSTALL_OTHER_PREFIX)
				message(FATAL_ERROR
					"Overwriting install location with `cmake --install --prefix` is not supported.\n"
					"Please re-run the configure/build/install with CMAKE_INSTALL_PREFIX set to desired location.\n"
					"If you know what you're doing and want to use `cmake --install --prefix`, "
					"search for `OCTOPUS_INSTALL_OTHER_PREFIX`"
					)
			endif ()
	]===]
	)
endif ()

## Special treatment

# Integration tests. These are run as part of Octopus_lib and must be built
# TODO (Alex). Issue #1194 Move test_integrations/ to the octopus root
# once autotools is removed
add_subdirectory(test_integrations)

## Unused sources
# boxes/box_intersection.F90
# electrons/pert.F90
# grid/operate_inc.c
# scf/mixing_metric.F90
