MantisBT - CMake
View Issue Details
0014359CMakeModulespublic2013-08-14 18:492014-06-02 08:37
Michel Zou 
jschueller 
normalminoralways
closedduplicate 
CMake 2.8.11.2 
 
0014359: [FindSWIG] SWIG detection fails when cross-compiling
The detection of swig fails when cross-compiling, here's why:

When cross-compiling, we do not want find_path to find files in the host tree, so we set the root path to the target libs and includes:
set ( CMAKE_FIND_ROOT_PATH /usr/i386-mingw32 )
set ( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )

but we never want cmake to find utils (like swig, awk, bc, etc...) in the target tree but in the host prefix:
set ( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )

Swig uses 'swig -swiglib' to determine the location of it's internal library:
  execute_process(COMMAND ${SWIG_EXECUTABLE} -swiglib
    OUTPUT_VARIABLE SWIG_swiglib_output)

Then it uses find-path to check the library macros presence:
find_path(SWIG_DIR swig.swg PATHS ${SWIG_swiglib_output})

But with CMAKE_FIND_ROOT_PATH_MODE_INCLUDE set to ONLY, the path cannot be found in the host paths, and the required SWIG_DIR is not found ; the detection fails:
-- Could NOT find SWIG (missing: SWIG_DIR)





Try to find swig while crosscompiling:

- in CMakeLists:
find_package(SWIG)

- in ToolChain-i386-mingw32:
set ( CMAKE_SYSTEM_NAME Windows )
set ( CMAKE_C_COMPILER i386-mingw32-gcc )
set ( CMAKE_FIND_ROOT_PATH /usr/i386-mingw32 )
set ( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
set ( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
set ( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
We could also search in the host paths by passing CMAKE_FIND_ROOT_PATH_BOTH to find_file:
find_path(SWIG_DIR swig.swg PATHS ${SWIG_swiglib_output} CMAKE_FIND_ROOT_PATH_BOTH)

See the embedded path, tested with and without cross-compilation.

Regards,

M.
No tags attached.
duplicate of 0013449closed jschueller [CROSS-CC] FindSWIG.cmake does not work when CMAKE_FIND_ROOT is redefined and CMAKE_FIND_ROOT_PATH_MODE_INCLUDE is set to ONLY 
patch cmake-swig-cross-compilation.patch (683) 2013-08-14 18:49
https://public.kitware.com/Bug/file/4852/cmake-swig-cross-compilation.patch
Issue History
2013-08-14 18:49Michel ZouNew Issue
2013-08-14 18:49Michel ZouFile Added: cmake-swig-cross-compilation.patch
2013-08-15 07:01Michel ZouNote Added: 0033719
2013-09-03 05:48Michel ZouNote Added: 0033775
2013-11-25 09:21jschuellerRelationship addedduplicate of 0013449
2013-11-25 09:21jschuellerStatusnew => resolved
2013-11-25 09:21jschuellerResolutionopen => duplicate
2013-11-25 09:21jschuellerAssigned To => jschueller
2014-06-02 08:37Robert MaynardNote Added: 0036038
2014-06-02 08:37Robert MaynardStatusresolved => closed

Notes
(0033719)
Michel Zou   
2013-08-15 07:01   
It is all the more blocking since SWIG_DIR is reset each time:
set(SWIG_DIR SWIG_DIR-NOTFOUND)
find_path(SWIG_DIR swig.swg PATHS ${SWIG_swiglib_output})
, and we cannot provide an additional location by passing explicitely the correct location, maybe a HINTS variable could also be passed ?

Moreover SWIG_DIR and SWIG_VERSION should be marked:
mark_as_advanced ( SWIG_VERSION SWIG_DIR )
(0033775)
Michel Zou   
2013-09-03 05:48   
I think it's a duplicate of http://public.kitware.com/Bug/view.php?id=13449 [^]

From a year ago... C'mon guys :!
(0036038)
Robert Maynard   
2014-06-02 08:37   
Closing resolved issues that have not been updated in more than 4 months.