diff --git a/katabatic/CMakeLists.txt b/katabatic/CMakeLists.txt index fea9a8ef..18d8474b 100644 --- a/katabatic/CMakeLists.txt +++ b/katabatic/CMakeLists.txt @@ -17,6 +17,8 @@ set(QT_USE_QTXML "true") find_package(Qt4 REQUIRED) + find_package(PythonLibs REQUIRED) + find_package(PythonSitePackages REQUIRED) find_package(VLSISAPD REQUIRED) find_package(HURRICANE REQUIRED) find_package(CORIOLIS REQUIRED) @@ -27,9 +29,9 @@ add_subdirectory(src) add_subdirectory(cmake_modules) - if(BUILD_DOC AND DOXYGEN_FOUND) + if(BUILD_DOC AND DOXYGEN_FOUND AND IS_DIRECTORY doc) add_subdirectory(doc) - endif(BUILD_DOC AND DOXYGEN_FOUND) + endif(BUILD_DOC AND DOXYGEN_FOUND AND IS_DIRECTORY doc) if(CHECK_DATABASE) add_definitions(-DCHECK_DATABASE) diff --git a/katabatic/src/CMakeLists.txt b/katabatic/src/CMakeLists.txt index 19aeba08..5f30b779 100644 --- a/katabatic/src/CMakeLists.txt +++ b/katabatic/src/CMakeLists.txt @@ -10,6 +10,7 @@ endif ( CHECK_DETERMINISM ) ${HURRICANE_INCLUDE_DIR} ${CONFIGURATION_INCLUDE_DIR} ${Boost_INCLUDE_DIRS} + ${PYTHON_INCLUDE_PATH} ) set ( includes katabatic/Configuration.h katabatic/ChipTools.h @@ -43,32 +44,41 @@ endif ( CHECK_DETERMINISM ) LoadGrByNet.cpp NetConstraints.cpp NetOptimals.cpp - ChipTools.cpp KatabaticEngine.cpp GraphicKatabaticEngine.cpp ) + set ( pyCpps PyKatabatic.cpp ) qt4_wrap_cpp ( mocCpps ${mocIncludes} ) - add_library ( katabatic ${cpps} ${mocCpps} ) - set_target_properties ( katabatic PROPERTIES VERSION 1.0 SOVERSION 1 ) - target_link_libraries ( katabatic ${KNIK_LIBRARIES} - ${CORIOLIS_LIBRARIES} - ${HURRICANE_PYTHON_LIBRARIES} - ${HURRICANE_GRAPHICAL_LIBRARIES} - ${HURRICANE_LIBRARIES} - ${CONFIGURATION_LIBRARY} - ${CIF_LIBRARY} - ${AGDS_LIBRARY} - ${LEFDEF_LIBRARIES} - ${OA_LIBRARIES} - ${QT_LIBRARIES} - ${Boost_LIBRARIES} - ${LIBXML2_LIBRARIES} - ${PYTHON_LIBRARIES} -lutil + add_library ( katabatic ${cpps} ${mocCpps} ) + set_target_properties ( katabatic PROPERTIES VERSION 1.0 SOVERSION 1 ) + target_link_libraries ( katabatic ${KNIK_LIBRARIES} + ${CORIOLIS_LIBRARIES} + ${HURRICANE_PYTHON_LIBRARIES} + ${HURRICANE_GRAPHICAL_LIBRARIES} + ${HURRICANE_LIBRARIES} + ${CONFIGURATION_LIBRARY} + ${CIF_LIBRARY} + ${AGDS_LIBRARY} + ${LEFDEF_LIBRARIES} + ${OA_LIBRARIES} + ${QT_LIBRARIES} + ${Boost_LIBRARIES} + ${LIBXML2_LIBRARIES} + ${PYTHON_LIBRARIES} -lutil + ) + add_library ( pyKatabatic MODULE ${pyCpps} ) + set_target_properties ( pyKatabatic PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -D__PYTHON_MODULE__=1" + PREFIX "" + OUTPUT_NAME "Katabatic" + ) + target_link_libraries ( pyKatabatic katabatic + ${CORIOLIS_PYTHON_LIBRARIES} ) - install ( TARGETS katabatic DESTINATION lib${LIB_SUFFIX} ) + install ( TARGETS katabatic DESTINATION lib${LIB_SUFFIX} ) + install ( TARGETS pyKatabatic DESTINATION ${PYTHON_SITE_PACKAGES} ) install ( FILES ${includes} - ${mocIncludes} DESTINATION include/coriolis2/katabatic ) + ${mocIncludes} DESTINATION include/coriolis2/katabatic ) diff --git a/katabatic/src/PyKatabatic.cpp b/katabatic/src/PyKatabatic.cpp new file mode 100644 index 00000000..72af6825 --- /dev/null +++ b/katabatic/src/PyKatabatic.cpp @@ -0,0 +1,83 @@ + +// -*- C++ -*- +// +// This file is part of the Coriolis Software. +// Copyright (c) UPMC/LIP6 2012-2012, All Rights Reserved +// +// +-----------------------------------------------------------------+ +// | C O R I O L I S | +// | K i t e - D e t a i l e d R o u t e r | +// | | +// | Author : Jean-Paul CHAPUT | +// | E-mail : Jean-Paul.Chaput@asim.lip6.fr | +// | =============================================================== | +// | C++ Module : "./PyKatabatic.cpp" | +// +-----------------------------------------------------------------+ + + +#include "hurricane/isobar/PyHurricane.h" +#include "katabatic/KatabaticEngine.h" + + +namespace Katabatic { + + using std::cerr; + using std::endl; + using Hurricane::tab; + using Hurricane::in_trace; + using Isobar::__cs; + + +#if !defined(__PYTHON_MODULE__) + +// x=================================================================x +// | "PyKatabatic" Shared Library Code Part | +// x=================================================================x + + +# else // End of PyHurricane Shared Library Code Part. + + +// x=================================================================x +// | "PyKatabatic" Python Module Code Part | +// x=================================================================x + +extern "C" { + + + static PyMethodDef PyKatabatic_Methods[] = + { {NULL, NULL, 0, NULL} /* sentinel */ + }; + + + + + // --------------------------------------------------------------- + // Module Initialization : "initKatabatic ()" + + DL_EXPORT(void) initKatabatic () { + trace << "initKatabatic()" << endl; + + PyObject* module = Py_InitModule ( "Katabatic", PyKatabatic_Methods ); + if ( module == NULL ) { + cerr << "[ERROR]\n" + << " Failed to initialize Katabatic module." << endl; + return; + } + + PyObject* dictionnary = PyModule_GetDict(module); + PyObject* constant; + + LoadObjectConstant(dictionnary,LoadGrByNet ,"LoadGrByNet" ); + LoadObjectConstant(dictionnary,LoadGrByGCell ,"LoadGrByGCell" ); + LoadObjectConstant(dictionnary,LayerAssignByLength,"LayerAssignByLength"); + LoadObjectConstant(dictionnary,LayerAssignByTrunk ,"LayerAssignByTrunk" ); + LoadObjectConstant(dictionnary,NoNetLayerAssign ,"NoNetLayerAssign" ); + } + + +} // extern "C". + +#endif // End of Python Module Code Part. + +} // Katabatic namespace.