X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=gdcmPython%2FCMakeLists.txt;h=d1afeda1f982e5f31848d713d8bdf52a394e2f18;hb=c877c5a7c0996f7f90732f6be9b27caa235e05ba;hp=986c920146f46f6dd00f1290f237a2e17a7377e9;hpb=188d74e401f34b35abc5585844e8c42ada54cba5;p=gdcm.git diff --git a/gdcmPython/CMakeLists.txt b/gdcmPython/CMakeLists.txt index 986c9201..d1afeda1 100644 --- a/gdcmPython/CMakeLists.txt +++ b/gdcmPython/CMakeLists.txt @@ -1,85 +1,138 @@ -#IF(GDCM_WRAP_PYTHON) -#If we reach this dir we have selected this option - - -#TODO -#http://www.cmake.org/pipermail/cmake/2003-August/004185.html -#http://www.cmake.org/pipermail/cmake/2003-January/001092.html - -#As of 09/10/2003 there was no FindSWIG.cmake - -#gdcm_wrap.cxx: $(srcdir)/gdcm.i -# $(SWIG) -python -c++ $(SWIG_INC) -o $@ $< +# TODO +# http://www.cmake.org/pipermail/cmake/2003-August/004185.html +# http://www.cmake.org/pipermail/cmake/2003-January/001092.html INCLUDE_DIRECTORIES( ${GDCM_SOURCE_DIR}/src ${PYTHON_INCLUDE_PATH} + ${GDCM_BINARY_DIR}/ ) -SET(GDCM_INC - ${GDCM_SOURCE_DIR}/src -# -I$(top_builddir) -) +#----------------------------------------------------------------------------- +# Create the gdcmVersion.py file: +FILE(WRITE ${GDCM_BINARY_DIR}/gdcmVersion.py + "gdcmVERSION=\"${GDCM_VERSION_FULL}\"" + ) -SET(SWIG_INC - ${PYTHON_INCLUDES} - ${GDCM_INC} -) +#----------------------------------------------------------------------------- +# SWIG Wrapping +# -ADD_CUSTOM_TARGET(mathieu ALL) +# CMake 2.0 will fully support Swig wrapping so split based on cmake version: -SET(GDCM_PYTHON_SOURCES - gdcm_wrap.cxx -) +IF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9) -SET_SOURCE_FILES_PROPERTIES(gdcm_wrap.cxx GENERATED) + FIND_PACKAGE(SWIG REQUIRED) + INCLUDE(${SWIG_USE_FILE}) -ADD_LIBRARY(pygdcm ${GDCM_PYTHON_SOURCES}) -TARGET_LINK_LIBRARIES(pygdcm - ${PYTHON_LIBRARY} - gdcm -) + #INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) + #SET(CMAKE_SWIG_FLAGS "") -ADD_CUSTOM_COMMAND( -SOURCE ${GDCM_SOURCE_DIR}/gdcmPython/gdcm.i -COMMAND swig -ARGS -python -c++ -I${GDCM_SOURCE_DIR}/src -o ${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx ${GDCM_SOURCE_DIR}/gdcmPython/gdcm.i -TARGET mathieu -OUTPUTS ${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx -) + SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES CPLUSPLUS ON) + SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES SWIG_FLAGS "-includeall") + SWIG_ADD_MODULE(gdcm python + gdcm.i gdcm_wrap.cxx) + SWIG_LINK_LIBRARIES(gdcm ${PYTHON_LIBRARIES}) + TARGET_LINK_LIBRARIES(_gdcm gdcm) +ELSE(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9) + # As of 09/10/2003 there was no FindSWIG.cmake + # later we should use SWIG instead of swig + FIND_PROGRAM(SWIG_EXECUTABLE + NAMES swig-1.3 swig + ) + + IF(NOT SWIG_EXECUTABLE) + MESSAGE(FATAL_ERROR "Swig could not be found wrapping is impossible") + ENDIF(NOT SWIG_EXECUTABLE) + + # Build our custom command : + ADD_CUSTOM_COMMAND( + TARGET pygdcm + COMMAND ${SWIG_EXECUTABLE} + ARGS -python -c++ -I${GDCM_SOURCE_DIR}/src -o + ${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx + ${GDCM_SOURCE_DIR}/gdcmPython/gdcm.i + SOURCE ${GDCM_SOURCE_DIR}/gdcmPython/gdcm.i + OUTPUTS ${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx + COMMENT "Generating gdcm_wrap.cxx/gdcm.py based on gdcm.i" + ) + # This swig command will also outputs gdcm.py : + SET_SOURCE_FILES_PROPERTIES(gdcm.py GENERATED) + # Since the file gdcm_wrap.cxx does not exist, mark it as GENERATED: + SET_SOURCE_FILES_PROPERTIES(gdcm_wrap.cxx GENERATED) + + ADD_LIBRARY(pygdcm gdcm_wrap.cxx) + TARGET_LINK_LIBRARIES(pygdcm + ${PYTHON_LIBRARY} + gdcm + ) + # http://www.cmake.org/pipermail/cmake/2003-August/004190.html + SET_TARGET_PROPERTIES(pygdcm PROPERTIES PREFIX "_") +ENDIF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9) + +#----------------------------------------------------------------------------- +# VTK Wrapping +# IF(GDCM_VTK) INCLUDE_DIRECTORIES( ${GDCM_SOURCE_DIR}/vtk ) SET(vtkgdcmPython_la_SOURCES -# vtkGdcmReaderPython.cxx -# vtkGdcmInit.cxx ${GDCM_SOURCE_DIR}/vtk/vtkGdcmReader.cxx ) SET_SOURCE_FILES_PROPERTIES(vtkGdcmReaderPython.cxx GENERATED) - #vtkWrapPythonInit.c - # The C++ files must be made into a C++ library - #ADD_LIBRARY ( vtkgdcmPython ${vtkgdcmPython_la_SOURCES}) - - # set the libraries to link against - #TARGET_LINK_LIBRARIES(vtkgdcmPython vtkCommon) - # Configure Python module, which is the plugin itself IF (GDCM_WRAP_PYTHON) VTK_WRAP_PYTHON2(vtkgdcmPython gdcmfoo ${vtkgdcmPython_la_SOURCES}) + # The C++ files must be made into a C++ library ADD_LIBRARY(vtkgdcmPython SHARED ${gdcmfoo}) + # set the libraries to link against TARGET_LINK_LIBRARIES (vtkgdcmPython - pygdcm - vtkgdcm - vtkCommonPython - vtkIOPython) + #_pygdcm + vtkgdcm + vtkCommonPython + vtkIOPython) ENDIF (GDCM_WRAP_PYTHON) + + #generate a setup.py according to VTK installation + #put it in subdir in order to not override old one + # as it is a pain...override existing file... + + GET_FILENAME_COMPONENT(VTKPATH ${VTK_DIR}/../../ ABSOLUTE) + CONFIGURE_FILE( + ${GDCM_SOURCE_DIR}/gdcmPython/setup.py.in + ${GDCM_BINARY_DIR}/setup.py + ) + #MESSAGE(STATUS ${VTKPATH}) ENDIF(GDCM_VTK) + +#----------------------------------------------------------------------------- +# Install stuff: + +#Should install in path of PYTHON_LIBRARY and not the default CMAKE_INSTALL_PREFIX + +GET_FILENAME_COMPONENT(PYTHON_LIB_INSTALL ${PYTHON_LIBRARY} PATH) +GET_FILENAME_COMPONENT(SITEPACKAGE + ${PYTHON_LIB_INSTALL}/../site-packages ABSOLUTE) +#MESSAGE(STATUS ${SITEPACKAGE}) +#INSTALL_FILES(/include "\\.h$") +#INSTALL_TARGETS(/lib/ gdcm) + +# gdcm.py is a file generated by swig +# then from python you can do import gdcm, and it will load _gdcm.so +#INSTALL_TARGETS(/lib/ gdcm.py) +#INSTALL_PROGRAMS(/lib/ gdcm.py) +#INSTALL_FILES(/lib/ .py gdcm.py) + +# When installing swig-generated python module one should pay attention +# to library naming convention, see here for more detail: +# http://www.swig.org/Doc1.3/Python.html#n6 +# even with the $swig -module mylib, there is always a trailing underscore added