# ####################################################################
# complete build chain for cmake.
#
# Copyright, 2018-2024, IMCCE, CNRS, Observatoire de Paris, PSL.
#
# ####################################################################

cmake_minimum_required(VERSION 3.0.0...3.28.0)
project(openfa VERSION 20231011.0.2 LANGUAGES C)

# ABI version number
# follow  rules : http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
set(OPENFA_SOVERSION_COMPAT 1)
set(OPENFA_SOVERSION_FULL ${OPENFA_SOVERSION_COMPAT}.${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})

set(OPENFA_CONTACT_EMAIL "Mickael.Gastineau@obspm.fr")
set(OPENFA_MAINTAINER_NAME "Mickaël Gastineau")

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

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

# ####################################################################
# set the options
# ####################################################################
option(OPENFA_INSTALL "Enable the generation of install target" ON)

# ####################################################################
# set the compiler flags
# ####################################################################
IF("${CMAKE_C_COMPILER_ID}" STREQUAL "Intel")
  MESSAGE(STATUS "Add the option '-fp-model precise' for the Intel compilers")
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fp-model precise ")
ENDIF()

if (WIN32)
  if (BUILD_SHARED_LIBS)
	  if (MINGW OR MSYS OR CYGWIN)
	  # only for the microsoft compiler
	  elseif (CMAKE_C_COMPILER_ID STREQUAL "MSVC")
		MESSAGE(STATUS "Exporting all symbols on windows")
		set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
	  endif()
  endif()
endif()

# the math library is not required with microsoft compilers or MinGW
if(WIN32)
  set(LIBM_LIBRARIES "")
else(WIN32)
  if(MINGW)
    set(LIBM_LIBRARIES "")
  else(MINGW)
    find_library(LIBM_LIBRARIES m)
  endif(MINGW)
endif(WIN32)

# ####################################################################
# set the directories
# ####################################################################
if(UNIX)
  include(GNUInstallDirs)
else()
  set(CMAKE_INSTALL_LIBDIR "lib")
  set(CMAKE_INSTALL_DATADIR "share")
  set(CMAKE_INSTALL_DOCDIR "share/doc/openfa")
  set(CMAKE_INSTALL_INCLUDEDIR "include")
  set(CMAKE_INSTALL_BINDIR "bin")
  set(CMAKE_INSTALL_LIBEXECDIR "libexec")
endif()

add_subdirectory("extra")
add_subdirectory("src")

# ####################################################################
# enable the tests
# ####################################################################
enable_testing()
add_subdirectory("tests")

# ####################################################################
# add the packaging
# ####################################################################
include(toolchain/packing.cmake)

export(TARGETS openfa FILE "${PROJECT_BINARY_DIR}/openfaTargets.cmake")

# Export the package for use from the build-tree
# (this registers the build-tree with a global CMake-registry)
export(PACKAGE openfa)

# ####################################################################
# create the developpment package file ...cmake
# ####################################################################
include(toolchain/devconfig.cmake)
