add_library(molden2resp blockhrr1.F90 blockhrr50.F90 blockhrr55.F90 boysfunc.F90 ean.F90 
            eanvrr.F90 hrr.F90 molden2resp.F90)

# GCC spends tens of minutes applying -O3 to several generated, very large
# integral sources. -O1 keeps source installs practical while retaining basic
# optimization for the arithmetic kernels.
if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
  target_compile_options(molden2resp PRIVATE -O1)
endif()

if(ENABLE_MKL)
  list(APPEND CMAKE_MODULE_PATH "${CMAKEINC}") 

  if(ENABLE_64BIT_INTEGERS)
    set(Fortran_INT_SIZE 8)
  else()
    set(Fortran_INT_SIZE 4)
  endif()

  if(MKL_FLAG MATCHES Sequential)
     set(MKL_THREAD_LAYER "Sequential")
  else()
     if(MKL_Fortran_COMPILER_ID MATCHES GNU)
        set(MKL_THREAD_LAYER "GNU OpenMP")
     else(MKL_Fortran_COMPILER_ID MATCHES Intel)
        set(MKL_THREAD_LAYER "Intel OpenMP")
     endif()
  endif()
 
  find_package(mkl REQUIRED)
endif()

add_executable(molden2resp.x main.F90)
if(ENABLE_MKL)
  if(${BUILD_SHARED_LIBS})
    target_link_libraries(molden2resp.x PRIVATE molden2resp MKL::Shared)
  else()
    target_link_libraries(molden2resp.x PRIVATE molden2resp MKL::Static)
  endif()
  message("MKL enabled ")
else()
  target_link_libraries(molden2resp.x PRIVATE molden2resp ${MOLDEN2RESP_MATH_LIBRARIES})
endif()
