#!/bin/bash
cmake_script=$(mktemp)
int_size_default=$(python3 -c 'import numpy; print(numpy.arange(1).dtype)' | sed -e 's#.*\([0-9]\{2\}\)#\1#')
echo " # integer config
if(DEFINED ENV{INTSIZE})
  set(INTSIZE \$ENV{INTSIZE})
else()
  set(INTSIZE $int_size_default)
endif()
# scotch/ptscotch config
if(DEFINED ENV{PTSCOTCH})
  if("\$ENV{PTSCOTCH}" STREQUAL "ON")
    set(PTSCOTCH ON)
    set(PACKAGE_NAME ptscotchpy)
    set(DEPENDENCIES \"dependencies = [ \\\"numpy\\\" , \\\"pytest\\\", \\\"mpy4py\\\"]\")
    set(BEFORE_ALL \"before-all = \\\"yum -y install flex && yum -y install bison && yum -y install openmpi-devel\\\"\")
  endif()
else()
  set(PTSCOTCH OFF)
  set(PACKAGE_NAME scotchpy)
  set(DEPENDENCIES \"dependencies = [ \\\"numpy\\\" , \\\"pytest\\\"]\")
  set(BEFORE_ALL \"before-all = \\\"yum -y install flex && yum -y install bison\\\"\")
endif()
set(PACKAGE_NAME  \${PACKAGE_NAME}\${INTSIZE})
configure_file(pyproject.toml.in pyproject.toml)
" >$cmake_script
cmake -P $cmake_script
rm $cmake_script
