message("Configuring NUMPY:\n@NUMPY_binary@")
set(ENV{LD_LIBRARY_PATH} "@python_install@/lib")
set(ENV{VS_UNICODE_OUTPUT} "")

if(APPLE)
  set(ENV{CFLAGS} "-arch x86_64 -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk")
endif()

# As explained in site.cfg.example - See http://projects.scipy.org/numpy/browser/trunk/site.cfg.example
# Directories listed in variable such as library_dirs or source_dirs should be separated using os.pathsep
# On windows, the separator is ";" and ":" on unix-like platform
set(path_sep ":")
if(WIN32)
  set(path_sep ";")
endif()

# As explained in site.cfg.example, the library name without the prefix "lib" should be used.
# Nevertheless, on windows, only "libf2c" leads to a successful configuration and
# installation of NUMPY
set(f2c_libname "f2c")
if(WIN32)
  set(f2c_libname "libf2c")
endif()

# setup the site.cfg file
file(WRITE "@NUMPY_binary@/site.cfg"
"
[blas]
library_dirs = "@NUMPY_LAPACK_binary@/BLAS/SRC/${CONFIG_TYPE}/${path_sep}@NUMPY_LAPACK_binary@/F2CLIBS/libf2c/${CONFIG_TYPE}/"
libraries = blas,${f2c_libname}

[lapack]
library_dirs = "@NUMPY_LAPACK_binary@/SRC/${CONFIG_TYPE}/"
lapack_libs = lapack
")

execute_process(
  COMMAND "@PYTHON_EXECUTABLE@" setup.py config
  WORKING_DIRECTORY "@NUMPY_binary@"
  RESULT_VARIABLE res
  )

if(NOT ${res} EQUAL 0)
  message(FATAL_ERROR "Error in config of NUMPY")
endif()
message("Numpy config worked.")
