cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
project(AvogadroLibsTest LANGUAGES CXX)

include(CTest)
enable_testing()

if(PROJECT_IS_TOP_LEVEL)
  # Enable build of standalone tests
  # testing against AvogadroLibs already installed on the system.

  # QT_VERSION not previously defined when building tests only
  set(QT_VERSION 6)

  find_package(AvogadroLibs REQUIRED)
endif()

include_directories("${AvogadroLibs_BINARY_DIR}/avogadro/core")

# find google test
find_package(GTest REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(Qt${QT_VERSION} COMPONENTS Widgets Network Concurrent REQUIRED)
# Add both as "system headers" to avoid warnings generated by them with
# compilers that support that notion.
include_directories(SYSTEM
  ${GTEST_INCLUDE_DIRS}
  ${EIGEN3_INCLUDE_DIR})

include(CheckIncludeFileCXX)
include(CheckCXXSymbolExists)
check_include_file_cxx("gtest/gtest.h" HAVE_GTEST_HPP)
if(HAVE_GTEST_HPP)
  check_cxx_symbol_exists(GTEST_HAS_PTHREAD "gtest/gtest.h" GTEST_HAS_PTHREAD)
  check_cxx_symbol_exists(GTEST_IS_THREADSAFE "gtest/gtest.h" GTEST_IS_THREADSAFE)
endif()

if(GTEST_HAS_PTHREAD)
  message(STATUS "GTest claims it has pthreads, we need to link to it.")
  find_package(Threads)
  set(EXTRA_LINK_LIB ${CMAKE_THREAD_LIBS_INIT})
else()
  set(EXTRA_LINK_LIB "")
endif()

find_path(AVOGADRO_DATA_ROOT .avogadro.data
  ${AvogadroLibs_SOURCE_DIR}/../avogadrodata
  $ENV{AVOGADRO_DATA_ROOT}
  DOC "The repository for data used for testing."
  )
mark_as_advanced(AVOGADRO_DATA_ROOT)

# Add the tests for each module.

add_subdirectory(calc)

add_subdirectory(core)
add_subdirectory(io)
add_subdirectory(quantumio)
if(USE_QT)
  add_subdirectory(qtgui)
endif()
if(USE_OPENGL)
  add_subdirectory(rendering)
endif()
