cmake_minimum_required(VERSION 2.6)
enable_language (Fortran)
project(packmol)

# Build for release or debug purposes?
SET(CMAKE_BUILD_TYPE release)
# Default flags for release and debug
set(CMAKE_Fortran_FLAGS_RELEASE "-Wall")
set(CMAKE_Fortran_FLAGS_DEBUG "-Wall -Werror")

option(USE_OPENMP "Compile OpenMP enabled version?" OFF)
if(USE_OPENMP)
 # Find OpenMP and add to flags
 find_package( OpenMP )
 # Check if we have special Fortran flag
 if("${OpenMP_Fortran_FLAGS}" STREQUAL "")
  set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_C_FLAGS}")
 else()
  set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}")
 endif()
endif()

# Common sources
SET(srcall cenmass.f90 gencan.f pgencan.f90 initial.f90 io.f90 fgcommon.f90 packmol.f90
polartocart.f90 heuristics.f90 sizes.f90 usegencan.f90 molpa.f90)
# Serial-only sources
SET(srcserial ${src} feasy.f90 geasy.f90)
# Parallel-only sources
SET(srcparallel feasyparallel.f90 geasyparallel.f90 compindexes.f90)

if(USE_OPENMP)
 # Compile
 add_executable(ppackmol ${srcall} ${srcparallel})
else(USE_OPENMP)
 # Build the serial executable.
 add_executable(packmol ${srcall} ${srcserial})
endif(USE_OPENMP)
