swig test needs to check version

Bug #801869 reported by Andreas Metzler
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Hugin
Fix Released
Critical
Unassigned

Bug Description

According to 2011.2.0_beta1 README hsi has specific version requirements on swig:

        SWIG >=2.0 - If Python >=3.2, SWIG must be >=2.0.4

However the CMake setup does not do any version checks.

FindPythonLibs seems to be one of the (imho very broken) cmake modules that does return any versioning info, making it impossible to completely express the abovementioned dependency without trickery. However FindSWIG can do version checks, making part1 (swig >= 2.0) easy as pie:

--- CMakeLists.txt.orig 2011-06-25 09:03:31.000000000 +0200
+++ CMakeLists.txt 2011-06-25 09:03:54.000000000 +0200
@@ -295,7 +295,7 @@
 OPTION(BUILD_HSI "Python Scripting Interface" OFF)
 IF(BUILD_HSI)
   find_program(SWIG_EXECUTABLE NAMES swig2.0 swig)
- FIND_PACKAGE(SWIG REQUIRED)
+ FIND_PACKAGE(SWIG 2.0 REQUIRED)
   INCLUDE(${SWIG_USE_FILE})

   FIND_PACKAGE(PythonLibs REQUIRED)

Revision history for this message
Yuv (yuv) wrote :

can you try with something along the following please? sorry I do not have time right now to do it myself.

OPTION(BUILD_HSI "Python Scripting Interface" OFF)
IF(BUILD_HSI)

  # find Python first because the version of SWIG required depends on the version of Python available

  FIND_PACKAGE(PythonLibs REQUIRED)
  INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
  ADD_DEFINITIONS(-DHUGIN_HSI)

  # get version of Python libs

  FILE(STRINGS "${PYTHON_INCLUDE_DIRS}/patchlevel.h"
      PY_DEF_MAJOR
      REGEX "#define[ \t]+PY_MAJOR_VERSION.*$")

  FILE(STRINGS "${PYTHON_INCLUDE_DIRS}/patchlevel.h"
      PY_DEF_MINOR
      REGEX "#define[ \t]+PY_MINOR_VERSION.*$")

  FILE(STRINGS "${PYTHON_INCLUDE_DIRS}/patchlevel.h"
      PY_DEF_MICRO
      REGEX "#define[ \t]+PY_MICRO_VERSION.*$")

  STRING(REGEX
        REPLACE "^.*VERSION[ \t]+([0-9]+).*" "\\1"
        PYTHON_VERSION_MAJOR
        "${PY_DEF_MAJOR}")

  STRING(REGEX
        REPLACE "^.*VERSION[ \t]+([0-9]+).*" "\\1"
        PYTHON_VERSION_MINOR
        "${PY_DEF_MINOR}")

  STRING(REGEX
        REPLACE "^.*VERSION[ \t]+([0-9]+).*" "\\1"
        PYTHON_VERSION_PATCH
        "${PY_DEF_MICRO}")

  # now we can find the right SWIG version
  FIND_PROGRAM(SWIG_EXECUTABLE NAMES swig2.0 swig)
  # unclean to test for Python 3, but the assumption is that by the time we have Python 4 this issue is long gone
  IF(${PYTHON_VERSION_MAJOR}==3)&&(${PYTHON_VERSION_MINOR}>=2))
    FIND_PACKAGE(SWIG 2.0.4 REQUIRED)
  ELSE()
    FIND_PACKAGE(SWIG 2.0 REQUIRED)
  ENDIF()
  INCLUDE(${SWIG_USE_FILE})

ENDIF()

Changed in hugin:
status: New → Confirmed
importance: Undecided → Critical
milestone: none → 2011.2.0
status: Confirmed → In Progress
Revision history for this message
Andreas Metzler (k-launchpad-downhill-at-eu-org) wrote : Re: [Bug 801869] Re: swig test needs to check version

On 2011-06-26 Yuv <email address hidden> wrote:
> can you try with something along the following please? sorry I do not
> have time right now to do it myself.
[...]

Hello,

seems to work with minor changes.

Comparing build logs against 2.6.7 and 3.2.1 (actually 2.6.7 with an
edited patchlevel.h file yields this:
-------------------------------------
--- Found SWIG: /usr/bin/swig2.0 (found suitable version "2.0.4", required is "2.0.4")
+-- Found SWIG: /usr/bin/swig2.0 (found suitable version "2.0.4", required is "2.0")
 -- Using shared internal libraries
--- Python libs version: 3.2.1
+-- Python libs version: 2.6.7
-------------------------------------

In the attached patch I have also dropped the (now duplicated) python
version parsing code in src/hugin_script_interface/CMakeLists.txt

thanks for the quick help,
cu andreas

Revision history for this message
Yuv (yuv) wrote :

thanks you for testing and making it work.

Changed in hugin:
status: In Progress → Fix Committed
Yuv (yuv)
Changed in hugin:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.