cmake_minimum_required(VERSION 3.15.2)
# 设置项目名称与语言
project(GCTL_POTENTIAL VERSION 1.0)
# 添加配置配件编写的函数
include(CMakePackageConfigHelpers)

# 添加编译选项
option(GCTL_POTENTIAL_FFTW3 "Use the FFTW3 library" ON)
option(GCTL_POTENTIAL_TESS "Use the Tess library" ON)
option(GCTL_POTENTIAL_MAGTESS "Use the MagTess library" ON)
option(GCTL_POTENTIAL_OPENMP "Use the OpenMP library" ON)
option(GCTL_POTENTIAL_AUTODIFF "Use the autodiff library" ON)
option(GCTL_POTENTIAL_EXPRTK "Use the exprtk library." ON)
# 传递安装地址给编译期宏变量
option(GCTL_POTENTIAL_INSTALL_PREFIX "Pass the install directory." ON)
set(DIR_VAR ${CMAKE_INSTALL_PREFIX})

message(STATUS "Platform: " ${CMAKE_HOST_SYSTEM_NAME})
message(STATUS "Install prefix: " ${CMAKE_INSTALL_PREFIX})
message(STATUS "Processor: " ${CMAKE_HOST_SYSTEM_PROCESSOR})
message(STATUS "[GCTL_POTENTIAL] Use the FFTW3 library: " ${GCTL_POTENTIAL_FFTW3})
message(STATUS "[GCTL_POTENTIAL] Use the Tess library: " ${GCTL_POTENTIAL_TESS})
message(STATUS "[GCTL_POTENTIAL] Use the MagTess library: " ${GCTL_POTENTIAL_MAGTESS})
message(STATUS "[GCTL_POTENTIAL] Use the OpenMP library: " ${GCTL_POTENTIAL_OPENMP})
message(STATUS "[GCTL_POTENTIAL] Use the autodiff library: " ${GCTL_POTENTIAL_AUTODIFF})
message(STATUS "[GCTL_POTENTIAL] Use the exprtk library: " ${GCTL_POTENTIAL_EXPRTK})

find_package(GCTL REQUIRED)
include_directories(${GCTL_INC_DIR})

find_package(GCTL_MESH REQUIRED)
include_directories(${GCTL_MESH_INC_DIR})

find_package(GCTL_OPTIMIZATION REQUIRED)
include_directories(${GCTL_OPTIMIZATION_INC_DIR})

if(GCTL_POTENTIAL_FFTW3)
	if(NOT FFTW3_FOUND)
		find_package(FFTW3 REQUIRED)
		message(STATUS "Found FFTW3")
		include_directories(${FFTW3_INCLUDE_DIRS})
	endif()
endif()

if(GCTL_POTENTIAL_TESS)
	if(NOT LibTess_FOUND)
		find_package(LibTess REQUIRED)
		message(STATUS "Found LibTess")
		include_directories(${LibTess_INC_DIR})
	endif()
endif()

if(GCTL_POTENTIAL_MAGTESS)
	if(NOT LibMagTess_FOUND)
		find_package(LibMagTess REQUIRED)
		message(STATUS "Found LibMagTess")
		include_directories(${LibMagTess_INC_DIR})
	endif()
endif()

if(GCTL_POTENTIAL_AUTODIFF)
	if(NOT autodiff_FOUND)
		find_package(Eigen3 REQUIRED)
		if(EIGEN3_FOUND)
			message(STATUS "Eigen3 Found.")
			include_directories(${EIGEN3_INCLUDE_DIR})
		endif()

		find_package(autodiff REQUIRED)
		if(autodiff_FOUND)
			message(STATUS "autodiff Found.")
			include_directories(${autodiff_INCLUDE_DIR})
		endif()
	endif()
endif()

# 加入一个头文件配置，让cmake对源码进行操作
configure_file(
	"${PROJECT_SOURCE_DIR}/config.h.in"
	"${PROJECT_SOURCE_DIR}/lib/potential/gctl_potential_config.h"
	)

# 添加库源文件地址
add_subdirectory(lib)
add_subdirectory(example)
add_subdirectory(tool)