cmake_minimum_required(VERSION 3.9.0)

if (POLICY CMP0048)
  cmake_policy(SET CMP0048 NEW)
endif()

#If the user/superbuild hasn't explicitly stated what c++ standard to use
#require C++11
if(NOT DEFINED CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 11)
  set(CMAKE_CXX_STANDARD_REQUIRED True)
  set(CMAKE_CXX_EXTENSIONS FALSE)
endif()

option(BUILD_SHARED_LIBS "Build aeva using shared libraries" ON)

################################################################################
# aeva version number
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/aevaVersion.cmake)

project(aeva VERSION ${aeva_version})
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

include(GNUInstallDirs)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}")

# aeva does not require SMTK to be built but if SMTK is included it provides
# the locations for ParaView and Qt
find_package(smtk QUIET)

find_package(ParaView REQUIRED)
find_package(Qt5 REQUIRED COMPONENTS Core Widgets)

foreach (plugin_dependency IN LISTS AEVA_EXTRA_SMTK_PLUGINS)
  find_package("${plugin_dependency}" REQUIRED)
endforeach ()

include(aevaPreamble) # Determine architecture, set up build-output directories.
include(aevaTesting) # Add an option to enable testing and set up pointers to the test data.
include(aevaCoverage) # Add options for performing code coverage tests.
include(aevaSanitize) # Add options for performing code sanitization.

# Do not report some warnings from generated code to the dashboard:
configure_file(
  "${CMAKE_CURRENT_SOURCE_DIR}/CTestCustom.cmake.in"
  "${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake")

set(aeva_plugin_paths
  "${aeva_plugin_paths}"
  "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}"
  CACHE STRING "Semi-colon separated paths for testing plugins."
)
mark_as_advanced(aeva_plugin_paths)

add_subdirectory(thirdparty)
add_subdirectory(plugins) # Plugins must be built before the app so .plugins file will be correct.
add_subdirectory(aeva)

option(aeva_enable_documentation "Include targets Sphinx-generated documentation" OFF)
if (aeva_enable_documentation)
  find_package(Sphinx)
  add_subdirectory(doc)
endif()

# Add rules to build packages
include(aevaPackaging)
