X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=gdcmPython%2FCMakeLists.txt;h=20d5f4c37bb03d56afe67812dd6a977527835faf;hb=267b089c621d7117829d7c701619db8d24887d35;hp=c8cb8da3f01dcc323f7ec6adaeda47c881c8d73f;hpb=ec5c97e570cd68bd66ccf41b61e96d11c87bbd5b;p=gdcm.git diff --git a/gdcmPython/CMakeLists.txt b/gdcmPython/CMakeLists.txt index c8cb8da3..20d5f4c3 100644 --- a/gdcmPython/CMakeLists.txt +++ b/gdcmPython/CMakeLists.txt @@ -1,101 +1,154 @@ -#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 - +# gdcm Python wrapping stuff: INCLUDE_DIRECTORIES( ${GDCM_SOURCE_DIR}/src ${PYTHON_INCLUDE_PATH} + ${GDCM_BINARY_DIR}/ ) -SET(GDCM_INC - ${GDCM_SOURCE_DIR}/src -) +#----------------------------------------------------------------------------- +# SWIG Wrapping +# -SET(SWIG_INC - ${PYTHON_INCLUDES} - ${GDCM_INC} -) +# CMake 2.0 will fully support Swig wrapping so split based on cmake version: -ADD_CUSTOM_TARGET(mathieu ALL) +# 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) -SET(GDCM_PYTHON_SOURCES - gdcm_wrap.cxx -) +FIND_PACKAGE(SWIG REQUIRED) +IF(SWIG_FOUND) + INCLUDE(${SWIG_USE_FILE}) +ENDIF(SWIG_FOUND) -SET_SOURCE_FILES_PROPERTIES(gdcm_wrap.cxx GENERATED) -ADD_LIBRARY(pygdcm ${GDCM_PYTHON_SOURCES}) -#http://www.cmake.org/pipermail/cmake/2003-August/004190.html -#SET_TARGET_PROPERTIES(pygdcm PROPERTIES PREFIX "") -TARGET_LINK_LIBRARIES(pygdcm - ${PYTHON_LIBRARY} - gdcm -) +SET_SOURCE_FILES_PROPERTIES(gdcm.i PROPERTIES CPLUSPLUS ON) +SWIG_ADD_MODULE(gdcm python gdcm.i) #gdcm_wrap.cxx, or gdcmPYTHON_wrap.cxx +SWIG_LINK_LIBRARIES(gdcm gdcm ${PYTHON_LIBRARIES}) -#----------------------------------------------------------------------------- -# As of 09/10/2003 there was no FindSWIG.cmake -# later we should use SWIG instead of swig -# Build our custom command : -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 pygdcm - OUTPUTS ${GDCM_BINARY_DIR}/gdcmPython/gdcm_wrap.cxx -) +# 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( + ${swig_generated_file_fullname} + PROPERTIES COMPILE_FLAGS "") +INSTALL_TARGETS(/lib/gdcm/ _gdcm) + +#----------------------------------------------------------------------------- +# VTK Wrapping +# IF(GDCM_VTK) + # Include the VTK library + INCLUDE(${VTK_USE_FILE}) + INCLUDE_DIRECTORIES( ${GDCM_SOURCE_DIR}/vtk ) SET(vtkgdcmPython_la_SOURCES ${GDCM_SOURCE_DIR}/vtk/vtkGdcmReader.cxx + ${GDCM_SOURCE_DIR}/vtk/vtkGdcmWriter.cxx ) SET_SOURCE_FILES_PROPERTIES(vtkGdcmReaderPython.cxx GENERATED) - # 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) - - #generate a setup.py according to VTK installation - #put it in subdir in order to not override old one - CONFIGURE_FILE( - ${GDCM_SOURCE_DIR}/gdcmPython/setup.py.in - ${GDCM_BINARY_DIR}/gdcmPython/setup.py - ) +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) -#I should install in path of PYTHON_LIBRARY -#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) - -# 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 +#----------------------------------------------------------------------------- +# 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)