PROJECT(SwigWrap)

cmake_minimum_required(VERSION 2.6)

include_directories (${Matrices_SOURCE_DIR}
                    "../matrices")
link_directories(${Matrices_BINARY_DIR})

if(WIN32)
	add_defines(MATRICES_EXPORTS)	
endif(WIN32)

if(UNIX)
    add_definitions(-DLINUX)
endif(UNIX)

FIND_PACKAGE(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})

find_package(PythonLibs)
find_package(PythonInterp)
# idea taken from pyplot build system 
execute_process(
	COMMAND
	${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; print sysconfig.get_python_lib(1,0,prefix='${CMAKE_INSTALL_EXEC_PREFIX}')"
	OUTPUT_VARIABLE PYTHON_INSTDIR
	OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "INFO: " "python lib: ${PYTHON_INSTDIR}" )

INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})

SET(CMAKE_SWIG_FLAGS "")
SET_SOURCE_FILES_PROPERTIES(pymatrices.i PROPERTIES CPLUSPLUS ON)
SET_SOURCE_FILES_PROPERTIES(pymatrices.i PROPERTIES SWIG_FLAGS "-includeall" )
SWIG_ADD_MODULE(pymatrices python pymatrices.i )
SWIG_LINK_LIBRARIES(pymatrices ${PYTHON_LIBRARIES} matrices)

include_directories(${Comparator_SOURCE_DIR}
                    "../comparator")
link_directories(${Comparator_BINARY_DIR})
SET_SOURCE_FILES_PROPERTIES(pycomparator.i PROPERTIES CPLUSPLUS ON)
SET_SOURCE_FILES_PROPERTIES(pycomparator.i PROPERTIES SWIG_FLAGS "-includeall" )
SWIG_ADD_MODULE(pycomparator python pycomparator.i comparator_utils.cpp )
SWIG_LINK_LIBRARIES(pycomparator ${PYTHON_LIBRARIES} matrices comparator )


set_target_properties(
	_pymatrices
	PROPERTIES
	INSTALL_NAME_DIR "${PYTHON_INSTDIR}"
)

set(PERM_SCRIPTS
	OWNER_READ
	OWNER_WRITE
	OWNER_EXECUTE
	GROUP_READ
	GROUP_EXECUTE
	WORLD_READ
	WORLD_EXECUTE
)
install(
	TARGETS _pymatrices _pycomparator
	LIBRARY
	DESTINATION ${PYTHON_INSTDIR}
	PERMISSIONS ${PERM_SCRIPTS}
)
install(
	FILES ${CMAKE_CURRENT_BINARY_DIR}/pymatrices.py
	${CMAKE_CURRENT_BINARY_DIR}/pycomparator.py
	DESTINATION ${PYTHON_INSTDIR}
	PERMISSIONS ${PERM_SCRIPTS}
)
