X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=gdcmPython%2FCMakeLists.txt;h=9581048645b7eb5fbe33a89a3c34b0901ed01338;hb=2e1f797ea8181180ebba6a48f0a4463bf43acedc;hp=a718595ec9b7baf0d2656a12cd1b7b2f9f1f5493;hpb=993abd8da219c4c06ebef8d92bfeb17f5e41f9d5;p=gdcm.git diff --git a/gdcmPython/CMakeLists.txt b/gdcmPython/CMakeLists.txt index a718595e..95810486 100644 --- a/gdcmPython/CMakeLists.txt +++ b/gdcmPython/CMakeLists.txt @@ -1,6 +1,4 @@ -# 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 @@ -8,124 +6,159 @@ INCLUDE_DIRECTORIES( ${GDCM_BINARY_DIR}/ ) -#----------------------------------------------------------------------------- -# Create the gdcmVersion.py file: -FILE(WRITE ${GDCM_BINARY_DIR}/gdcmVersion.py - "gdcmVERSION=\"${GDCM_VERSION_FULL}\"" - ) - #----------------------------------------------------------------------------- # SWIG Wrapping # # CMake 2.0 will fully support Swig wrapping so split based on cmake version: -IF(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 1.9) - - FIND_PACKAGE(SWIG REQUIRED) - INCLUDE(${SWIG_USE_FILE}) - - #INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) - - #SET(CMAKE_SWIG_FLAGS "") - - 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) - - ADD_LIBRARY(pygdcm gdcm_wrap.cxx) - - # 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( - TARGET pygdcm - COMMAND swig - 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" +# 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 ) - # 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) - - 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) +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) # 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}) # The C++ files must be made into a C++ library - ADD_LIBRARY(vtkgdcmPython SHARED ${gdcmfoo}) + 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) + 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 - # 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) +# 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") + #----------------------------------------------------------------------------- -# 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 +# Add test from demo subdir: + +SUBDIRS(demo)