
include_directories (${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
                     ${ZLIB_INCLUDE_DIR})

if (NETCDF_FOUND)
  include_directories (${NETCDF_INCLUDE_DIR})
endif (NETCDF_FOUND)

set (ALL_ARTS_LIBRARIES
  artscore
  methods
  matpack
  )

file (GLOB HEADERFILES "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
add_custom_target(UtilityHeadersArts SOURCES ${HEADERFILES})

if (ENABLE_GUI)
  include (${QT_USE_FILE})
  add_definitions (${QT_DEFINITIONS})

  list (APPEND ALL_ARTS_LIBRARIES artsgui ${QT_LIBRARIES})
  include_directories ("gui")
endif (ENABLE_GUI)

if (ENABLE_DISORT)
  list (APPEND ALL_ARTS_LIBRARIES disort)
endif (ENABLE_DISORT)

########### target to extract version number from ChangeLog ###############

add_custom_target (auto_version_h DEPENDS auto_version.h)
add_dependencies (auto_version_h UpdateAutoVersion)

add_custom_command (
  OUTPUT auto_version.h
  COMMAND ${CMAKE_COMMAND} -D "ARTS_BINARY_DIR:STRING=\"${CMAKE_BINARY_DIR}\"" -D "ARTS_SOURCE_DIR:STRING=\"${CMAKE_SOURCE_DIR}\"" -P ${CMAKE_SOURCE_DIR}/cmake/scripts/update_auto_version_h.cmake
  DEPENDS ${CMAKE_BINARY_DIR}/auto_version.txt
)

########### next target ###############

add_executable (arts main.cc)
add_dependencies (arts auto_version_h)

target_link_libraries (arts ${ALL_ARTS_LIBRARIES})

install (TARGETS arts RUNTIME DESTINATION bin)

if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG)
  set_source_files_properties (continua.cc PROPERTIES
                               COMPILE_FLAGS "-fno-strict-aliasing")
  set_source_files_properties (binio.cc PROPERTIES
                               COMPILE_FLAGS "-fno-strict-aliasing")
  set_source_files_properties (methods.cc PROPERTIES COMPILE_FLAGS "-O0")
  set_source_files_properties (partition_function_data.cc PROPERTIES
                               COMPILE_FLAGS "-O0")
  set_source_files_properties (species_data.cc PROPERTIES COMPILE_FLAGS "-O0")
endif (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG)

########### next target ###############

add_executable (make_auto_workspace_h
	arts.cc
	file.cc
  make_auto_workspace_h.cc
	messages.cc
	parameters.cc
	)

target_link_libraries (make_auto_workspace_h matpack methods)

add_custom_command (
	OUTPUT auto_workspace.h
	COMMAND make_auto_workspace_h
	DEPENDS make_auto_workspace_h
	)

add_custom_target (BuildAutoSources DEPENDS auto_workspace.h auto_md.h
                   auto_md.cc)

########### next target ###############

add_executable (make_auto_md_h
	agenda_record.cc
	arts.cc
  auto_workspace.h
	file.cc
	globals_2.cc
	make_auto_md_h.cc
	messages.cc
	parameters.cc
	workspace.cc
	workspace_ng.cc
	)

target_link_libraries (make_auto_md_h methods matpack)

add_custom_command (
	OUTPUT auto_md.h
	COMMAND make_auto_md_h
	DEPENDS make_auto_md_h
)

########### next target ###############

add_executable (make_auto_md_cc
	agenda_record.cc
	arts.cc
  auto_workspace.h
	file.cc
	globals_2.cc
	make_auto_md_cc.cc
	messages.cc
	parameters.cc
	workspace.cc
	workspace_ng.cc
	)

target_link_libraries (make_auto_md_cc methods matpack)

add_custom_command (
	OUTPUT auto_md.cc
	COMMAND make_auto_md_cc
	DEPENDS make_auto_md_cc
	)

########### next target ###############

set (ARTSCORE_EXTRA_SOURCES)
if (NOT HAVE_GETOPT_H)
  list (APPEND ARTSCORE_EXTRA_SOURCES
    arts_getopt.c arts_getopt1.c)
endif (NOT HAVE_GETOPT_H)

add_library (artscore STATIC
	auto_md.h
	auto_md.cc
	auto_workspace.h
  ${ARTSCORE_EXTRA_SOURCES}
  abs_species_tags.cc
  absorption.cc
  agenda_class.cc
  agenda_record.cc
  arts.cc
  arts_omp.cc
  bifstream.cc
  binio.cc
  bofstream.cc
  check_input.cc
  cloudbox.cc
  constants.cc
  continua.cc
  disort.cc
  docserver.cc
  doit.cc
  fastem.cc
  file.cc
  gas_abs_lookup.cc
  geomag_calc.cc
  globals_2.cc
  gridded_fields.cc
  gzstream.cc
  interpolation.cc
  interpolation_poly.cc
  jacobian.cc
  legendre.cc
  lin_alg.cc
  lineshapes.cc
  m_abs.cc
  m_abs_lookup.cc
  m_agenda.cc
  m_atmosphere.cc
  m_basic_types.cc
  m_batch.cc
  m_cloudbox.cc
  m_disort.cc
  m_doit.cc
  m_fos.cc
  m_general.cc
  m_jacobian.cc
  m_montecarlo.cc
  m_optproperties.cc
  m_physics.cc
  m_ppath.cc
  m_refraction.cc
  m_rte.cc
  m_sensor.cc
  m_surface.cc
  math_funcs.cc
  mc_antenna.cc
  mc_interp.cc
  messages.cc
  montecarlo.cc
  nc_io.cc
  nc_io_array_types.cc
  nc_io_basic_types.cc
  nc_io_compound_types.cc
  optproperties.cc
  parameters.cc
  parser.cc
  partition_function_data.cc
  physics_funcs.cc
  poly_roots.cc
  ppath.cc
  refraction.cc
  rng.cc
  rte.cc
  sensor.cc
  sourcetext.cc
  special_interp.cc
  species_data.cc
  token.cc
  workspace.cc
  workspace_ng.cc
  xml_io.cc
  xml_io_array_types.cc
  xml_io_basic_types.cc
  xml_io_compound_types.cc
	)
add_dependencies (artscore auto_version_h)

target_link_libraries (artscore ${ZLIB_LIBRARIES})

if (NETCDF_FOUND)
  target_link_libraries (artscore ${NETCDF_LIBRARIES})
endif (NETCDF_FOUND)

if (ENABLE_DOCSERVER)
  target_link_libraries (artscore microhttpd)
endif (ENABLE_DOCSERVER)

########### next target ###############

add_library (matpack STATIC
	complex.cc
	logic.cc
	make_vector.cc
	matpackI.cc
	matpackII.cc
	matpackIII.cc
	matpackIV.cc
	matpackV.cc
	matpackVI.cc
	matpackVII.cc
	)

########### next target ###############

add_library (methods STATIC
	agendas.cc
	methods.cc
	methods_aux.cc
	groups.cc
	)

########### next target ###############

if (ENABLE_DISORT)
  add_library (disort STATIC
    disort_D1MACH.c
    disort_DISORT.c
    disort_ErrPack.c
    disort_FAKEMAIN.c
    disort_LINPAK.c
    disort_R1MACH.c
    )
  target_link_libraries (disort f2c)

  ########### testcase ###############

  add_executable (test_disort disort_DISOTEST.c)

  target_link_libraries (test_disort disort)
endif (ENABLE_DISORT)

########### testcases ###############

add_executable (test_binaryio test_binaryio.cc)

target_link_libraries (test_binaryio ${ALL_ARTS_LIBRARIES})

########### next testcase ###############

add_executable (test_gridded_fields
  gridded_fields.cc
  test_gridded_fields.cc)

target_link_libraries (test_gridded_fields matpack)

########### next testcase ###############

add_executable (test_interpolation test_interpolation.cc)
target_link_libraries (test_interpolation ${ALL_ARTS_LIBRARIES})

########### next testcase ###############

add_executable (test_legendre
  constants.cc
  math_funcs.cc
  legendre.cc
  test_legendre.cc)

target_link_libraries (test_legendre matpack)

########### next testcase ###############

add_executable (test_linalg
  constants.cc
  make_vector.cc
  lin_alg.cc
  test_linalg.cc)

target_link_libraries (test_linalg ${ALL_ARTS_LIBRARIES})

########### next testcase ###############

add_executable (test_integration
  constants.cc
  math_funcs.cc
  test_integration.cc)

target_link_libraries (test_integration matpack)

########### next testcase ###############

add_executable (test_poly poly_roots.h poly_roots.cc test_poly.cc)
target_link_libraries (test_poly matpack)

########### next testcase ###############

add_executable (test_tensor test_tensor.cc)
target_link_libraries (test_tensor matpack)

########### next testcase ###############

add_executable (test_matpack describe.h describe.cc test_matpack.cc)
target_link_libraries (test_matpack matpack)

########### next testcase ###############

add_executable (test_sparse test_sparse.cc)
target_link_libraries (test_sparse ${ALL_ARTS_LIBRARIES})

########### next testcase ###############

add_executable (test_xml test_xml.cc)
target_link_libraries (test_xml ${ALL_ARTS_LIBRARIES})

########### next testcase ###############

add_executable (test_complex test_complex.cc)
target_link_libraries (test_complex matpack)

########### next testcase ###############

add_executable (test_sorting sorting.h test_sorting.cc)
target_link_libraries (test_sorting matpack)

########### next testcase ###############

add_executable (test_readpp test_readpp.cc)
target_link_libraries (test_readpp ${ALL_ARTS_LIBRARIES})

########### subdirs ###############

add_subdirectory (libmicrohttpd)

if (WITH_GUI)
  add_subdirectory (gui)
endif (WITH_GUI)

