X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=gdcmPython%2FCMakeLists.txt;h=9581048645b7eb5fbe33a89a3c34b0901ed01338;hb=2e1f797ea8181180ebba6a48f0a4463bf43acedc;hp=ab3030844462afd0722df5ce4882b637cbc248a0;hpb=7b90a94638699fec1143d1928f6a6b6f3c769d54;p=gdcm.git diff --git a/gdcmPython/CMakeLists.txt b/gdcmPython/CMakeLists.txt index ab303084..95810486 100644 --- a/gdcmPython/CMakeLists.txt +++ b/gdcmPython/CMakeLists.txt @@ -1,77 +1,164 @@ -#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 $@ $< +# gdcm Python wrapping stuff: INCLUDE_DIRECTORIES( ${GDCM_SOURCE_DIR}/src + ${PYTHON_INCLUDE_PATH} + ${GDCM_BINARY_DIR}/ ) -SET(GDCM_INC - ${GDCM_SOURCE_DIR}/src -# -I$(top_builddir) -) - -SET(SWIG_INC - ${PYTHON_INCLUDES} - ${GDCM_INC} -) - - -SET(GDCM_PYTHON_SOURCES - gdcm_wrap.cxx -) - -SET_SOURCE_FILES_PROPERTIES(gdcm_wrap.cxx GENERATED) - -ADD_CUSTOM_COMMAND( -SOURCE ${GDCM_SOURCE_DIR}/gdcmPython/gdcm.i -COMMAND swig -ARGS -python -c++ -I${GDCM_SOURCE_DIR}/src -o gdcm_wrap.cxx ${GDCM_SOURCE_DIR}/gdcmPython/gdcm.i -OUTPUTS gdcm_wrap.cxx -TARGET pygdcm -) - -ADD_LIBRARY(pygdcm ${GDCM_PYTHON_SOURCES}) - +#----------------------------------------------------------------------------- +# SWIG Wrapping +# + +# CMake 2.0 will fully support Swig wrapping so split based on cmake version: + +# We need to pass that to swig to be sure all modules are generated in the proper dir +SET(CMAKE_SWIG_FLAGS "-outdir ${GDCM_BINARY_DIR}/gdcmPython") +# Looks like a bug to me in cmake 2.0.x: +SEPARATE_ARGUMENTS(CMAKE_SWIG_FLAGS) + +FIND_PACKAGE(SWIG REQUIRED) +INCLUDE(${SWIG_USE_FILE}) + +SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES CPLUSPLUS ON) +# Setting SWIG_FLAGS to "-includeall" at the following line looks like +# a bad idea since swig tries to recursively include all the referenced +# files, "including" the C++ , , ... Of course swig +# has no way of finding the path to those files (unless it is told by +# cmake) since they are related to the compiler installation layout. +# Anyhow, since this inclusion recursion is not necessary, just don't +# do it. +# Note: apparently the line is required in order to avoid a NOTFOUND +# as argument of swig on invocation of make. +SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES SWIG_FLAGS "") +SWIG_ADD_MODULE(gdcm python gdcm.i) #gdcm_wrap.cxx +SWIG_LINK_LIBRARIES(gdcm gdcm ${PYTHON_LIBRARIES}) + +# Get rid of -Wall / -W / -pedantic if exist +#SET(CMAKE_CXX_FLAGS "") +# I guess I need to put them back on the this file: +#SET_SOURCE_FILES_PROPERTIES(${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx +# PROPERTIES COMPILE_FLAGS "") +ADD_DEPENDENCIES( + ${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx + ${GDCM_SOURCE_DIR}/gdcmConfigure.h + ) +INSTALL_TARGETS(/lib/gdcm/ _gdcm) +#----------------------------------------------------------------------------- +# VTK Wrapping +# IF(GDCM_VTK) -# INCLUDE_DIRECTORIES( -# ${GDCM_SOURCE_DIR}/vtk -# ) + # Include the VTK library + INCLUDE(${VTK_USE_FILE}) + + INCLUDE_DIRECTORIES( + ${GDCM_SOURCE_DIR}/vtk + ) SET(vtkgdcmPython_la_SOURCES -# vtkGdcmReaderPython.cxx -# vtkGdcmInit.cxx ${GDCM_SOURCE_DIR}/vtk/vtkGdcmReader.cxx + ${GDCM_SOURCE_DIR}/vtk/vtkGdcmWriter.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 + IF(NOT VTK_WRAP_PYTHON) + MESSAGE(FATAL_ERROR "Can't build gdcm python wrapping if VTK_WRAP_PYTHON is OFF" ) + ENDIF(NOT VTK_WRAP_PYTHON) + VTK_WRAP_PYTHON2(vtkgdcmPython gdcmWrapSOURCES ${vtkgdcmPython_la_SOURCES}) - ADD_LIBRARY(vtkgdcmPython SHARED ${gdcmfoo}) + # The C++ files must be made into a C++ library + ADD_LIBRARY(vtkgdcmPython SHARED ${gdcmWrapSOURCES}) #MODULE on apple ? + # set the libraries to link against + #SET_TARGET_PROPERTIES(${foobar} PROPERTIES PREFIX "") + + #GET_TARGET_PROPERTY(swig_gdcm_fullpath "${SWIG_MODULE_gdcm_REAL_NAME}" LOCATION) TARGET_LINK_LIBRARIES (vtkgdcmPython - pygdcm - vtkgdcm - vtkCommonPython - vtkIOPython) + vtkgdcm + vtkCommonPython + vtkIOPython) + INSTALL_TARGETS(/lib/gdcm/ vtkgdcmPython) + ENDIF (GDCM_WRAP_PYTHON) ENDIF(GDCM_VTK) + +# generate a setup.py according to VTK installation +# put it in subdir in order to not override old one +# +#GET_FILENAME_COMPONENT(VTKPATH ${VTK_DIR}/../../ ABSOLUTE) +#CONFIGURE_FILE( +# ${GDCM_SOURCE_DIR}/gdcmPython/setup.py.in +# ${GDCM_BINARY_DIR}/setup.py +#) + +#----------------------------------------------------------------------------- +# Python package configuration +FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmVersion.py + "gdcmVERSION=\"${GDCM_VERSION}\"\n" + ) + +FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/__init__.py + "__all__ = [\"core\",\n" + " \"vtk\",\n" + " ]\n" + ) + +FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/core.py + "from gdcmVersion import *\n" + "import gdcm\n" + "GDCM_DATA_ROOT = \"${GDCM_DATA_ROOT}\"\n" + ) + +IF(GDCM_VTK) + FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/vtk.py + "import os\n" + "from gdcmVersion import *\n" + "if os.name == 'posix':\n" + " from libvtkgdcmPython import *\n" + "else:\n" + " from vtkgdcmPython import *\n" + "GDCM_DATA_ROOT = \"${GDCM_DATA_ROOT}\"\n" + ) +ENDIF(GDCM_VTK) + +#----------------------------------------------------------------------------- +# Python installation +IF(WIN32) + FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmPython.pth + "${GDCM_BINARY_DIR}\n" + "${GDCM_BINARY_DIR}/bin/release\n" + ) +ELSE(WIN32) + FILE(WRITE ${GDCM_BINARY_DIR}/gdcmPython/gdcmPython.pth + "${CMAKE_INSTALL_PREFIX}/lib/gdcm\n" + ) +ENDIF(WIN32) +FIND_PATH(PYTHON_INSTALL "site-packages" + [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.4\\InstallPath] + [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.3\\InstallPath] + [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.2\\InstallPath] + [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.1\\InstallPath] + [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.0\\InstallPath] + [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\1.6\\InstallPath] + [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\1.5\\InstallPath] + /usr/lib/python2.4 + /usr/lib/python2.3 + /usr/lib/python2.2 + /usr/lib/python2.1 + /usr/lib/python2.0 + /usr/lib/python1.6 + /usr/lib/python1.5 +) +STRING(REGEX REPLACE "/usr(.*)/config.*" "\\1" PYTHON_INSTALL ${PYTHON_LIBRARY}) + +INSTALL_FILES(${PYTHON_INSTALL}/site-packages "\\.pth$") +INSTALL_FILES(/lib/gdcm/gdcmPython "\\.py$") +INSTALL_FILES(/lib/gdcm/gdcmPython FILES "gdcm.py") + +#----------------------------------------------------------------------------- +# Add test from demo subdir: + +SUBDIRS(demo)