# 
# alps-python cmake configuration script.
# 

cmake_minimum_required (VERSION 2.8.12)

# define project name
project (alps-python CXX)
message ("\nALPSCore module : ${PROJECT_NAME}\n")

# add common modules from ../common/cmake
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../common/cmake)

# add common definitions
include(ALPSCommonModuleDefinitions)

gen_documentation()

if (DocumentationOnly)
  return()
endif (DocumentationOnly)

# enable mpi
include(ALPSEnableMPI)
# search for python
find_package(PythonLibs)
if (NOT PYTHONLIBS_FOUND)
  message(FATAL_ERROR " Python libraries not found")
else(NOT PYTHONLIBS_FOUND)
  set(ALPS_HAVE_PYTHON True)
endif (NOT PYTHONLIBS_FOUND)
# find numpy
find_package(NumPy REQUIRED)
include_directories(${NUMPY_INCLUDE_DIRS})
# Boost
#set(Boost_USE_STATIC_LIBS        ON)
#set(Boost_USE_STATIC_RUNTIME    OFF)
set(BOOST_LIBRARY_LIST chrono program_options filesystem system)
if(ENABLE_MPI)
  list(APPEND BOOST_LIBRARY_LIST mpi)
endif(ENABLE_MPI)
if(ALPS_HAVE_PYTHON)
  list(APPEND BOOST_LIBRARY_LIST python)
endif(ALPS_HAVE_PYTHON)
add_boost(${BOOST_LIBRARY_LIST})

add_hdf5()
add_alps_package(alps-utilities alps-hdf5 alps-params alps-accumulators alps-mc)

set (libs_ "")
foreach (name    
        pyrandom01 
	pyhdf5
	api
	pymcbase)
    
    add_library(${name}_c MODULE src/${name}.cpp src/import_numpy.cpp)
    list(APPEND libs_ ${name}_c)

    # (FIXME) This requires a newer CMake (2.8.12 ?):
    # target_compile_definitions(${name}_c PUBLIC "${ALPS_SHARED_CPPFLAGS}") # FIXME: public or private?
    # so it is replaced with:
    set_target_properties(${name}_c PROPERTIES COMPILE_DEFINITIONS "${ALPS_SHARED_CPPFLAGS}"
                                               INTERFACE_COMPILE_DEFINITIONS "${ALPS_SHARED_CPPFLAGS}")

    set_target_properties(${name}_c PROPERTIES PREFIX "")
    target_link_libraries(${name}_c ${PYTHON_LIBRARIES} ${LINK_ALL})
    include_directories(${PYTHON_INCLUDE_DIRS})

    install(TARGETS ${name}_c 
            EXPORT ${PROJECT_NAME}
            DESTINATION python)
    # (FIXME) with the newer CMake, the following will go to install(TARGETS) above (INCLUDE DIRS include):
    set_target_properties(${name}_c PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_INSTALL_PREFIX}/include)
    
endforeach(name)
install(EXPORT ${PROJECT_NAME} NAMESPACE alps:: DESTINATION share/${PROJECT_NAME})

add_this_package(${libs_})

add_testing()

gen_pkg_config()
#gen_find_module(alps/utilities/boost_python.hpp HEADER_ONLY) 
