cmake_minimum_required(VERSION 3.15...3.31)

project(pestel LANGUAGES CXX)

if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
endif()

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

####################
# executables
####################
set(PESTEL_EXECUTABLES pestel pg2gpg pg2randgpg hoa2pg)

foreach(name IN LISTS PESTEL_EXECUTABLES)
  add_executable(${name} src/${name}.cpp)
  target_include_directories(${name} PRIVATE ${PROJECT_SOURCE_DIR}/lib)
  # cpphoafparser is included as a system header (same as -isystem in the Makefile)
  target_include_directories(${name} SYSTEM PRIVATE ${PROJECT_SOURCE_DIR})
  if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
    target_compile_options(${name} PRIVATE -Wall -Wextra -Wno-unknown-pragmas)
  endif()
endforeach()

####################
# installation
####################
# When built by pip (scikit-build-core), the executables are installed into the
# scripts directory of the Python environment, which is on the PATH.
if(DEFINED SKBUILD_SCRIPTS_DIR)
  set(PESTEL_INSTALL_BINDIR "${SKBUILD_SCRIPTS_DIR}")
else()
  include(GNUInstallDirs)
  set(PESTEL_INSTALL_BINDIR "${CMAKE_INSTALL_BINDIR}")
endif()

install(TARGETS ${PESTEL_EXECUTABLES} RUNTIME DESTINATION "${PESTEL_INSTALL_BINDIR}")
