MantisBT - CMake
View Issue Details
0011782CMakeCMakepublic2011-02-01 10:592011-03-28 12:28
Brian Panneton 
Mathieu Malaterre 
normalminoralways
closedfixed 
LinuxCentOS2.16.0
CMake 2.8.3 
 
0011782: Issue with UseSWIG.cmake and parallel builds
I have found an issue with UseSWIG.cmake during parallel builds. If you are swigging Python and Java using the SWIG_ADD_MODULE and SWIG_LINK_LIBRARIES macros you could run into this issue.

When you run through CMake, the macro SWIG_GET_EXTRA_OUTPUT_FILES sets the variable SWIG_EXTRA_GENERATED_FILES. This variable is used by a custom command as an output. When CMaking, it never gets reset. Thus if you start with swigging Python, the file module.py is appended to it. Then when swigging Java, the same file remains as an output.

If you are running in parallel, the output file is claimed by both Java and Python. Somehow this makes it so the Python lib might not get fully built on the first try.

To solve this issue on the user side we need to reset SWIG_EXTRA_GENERATED_FILES right before you call the macro SWIG_ADD_MODULE, like such:

set(swig_extra_generated_files "")
swig_add_module(${module_name} python module.i)

To solve this issue on the UseSWIG.cmake side add SET(${outfiles} "") to the first line of the macro SWIG_GET_EXTRA_OUTPUT_FILES, like such:

MACRO(SWIG_GET_EXTRA_OUTPUT_FILES language outfiles generatedpath infile)
  SET(${outfiles} "")
  GET_SOURCE_FILE_PROPERTY(SWIG_GET_EXTRA_OUTPUT_FILES_module_basename
    ${infile} SWIG_MODULE_NAME)

I am pretty sure this would solve the issue. Please let me know if this is the correct way to go about it.

Thanks,
Brian Panneton
No tags attached.
tar test.tar (184,320) 2011-02-03 12:47
https://public.kitware.com/Bug/file/3674/test.tar
Issue History
2011-02-01 10:59Brian PannetonNew Issue
2011-02-01 11:01Mathieu MalaterreAssigned To => Mathieu Malaterre
2011-02-01 11:01Mathieu MalaterreStatusnew => assigned
2011-02-03 12:47Brian PannetonFile Added: test.tar
2011-02-03 12:49Brian PannetonNote Added: 0025244
2011-03-28 12:28Mathieu MalaterreNote Added: 0025936
2011-03-28 12:28Mathieu MalaterreStatusassigned => closed
2011-03-28 12:28Mathieu MalaterreResolutionopen => fixed

Notes
(0025244)
Brian Panneton   
2011-02-03 12:49   
I have uploaded a tarball of a simple test that shows the issue. I am using CMake 2.8.3, SWIG 2.0.0, Python 2.6.4, and Java JDK6. Unpack it and just run "cmake ." to see ${swig_extra_generated_files} before and after each swigging. Either of the above solutions fix this.
(0025936)
Mathieu Malaterre   
2011-03-28 12:28   
$ git push stage HEAD
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 402 bytes, done.
Total 4 (delta 3), reused 0 (delta 0)
To git@cmake.org:stage/cmake.git
 * [new branch] HEAD -> fixbug_0011782