# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
F i n d S W I G
- - - - - - - -
F i n d t h e S i m p l i f i e d W r a p p e r a n d I n t e r f a c e Generator ( SWIG_ ) e x e c u t a b l e .
T h i s m o d u l e f i n d s a n i n s t a l l e d S W I G a n d d e t e r m i n e s i t s v e r s i o n .
. . v e r s i o n a d d e d : : 3 . 1 8
I f a ` ` C O M P O N E N T S ` ` o r ` ` O P T I O N A L _ C O M P O N E N T S ` ` a r g u m e n t i s g i v e n t o t h e
: c o m m a n d : ` f i n d _ p a c k a g e ` c o m m a n d , i t w i l l a l s o d e t e r m i n e s u p p o r t e d t a r g e t
l a n g u a g e s .
. . v e r s i o n a d d e d : : 3 . 1 9
W h e n a v e r s i o n i s r e q u e s t e d , i t c a n b e s p e c i f i e d a s a s i m p l e v a l u e o r a s a
r a n g e . F o r a d e t a i l e d d e s c r i p t i o n o f v e r s i o n r a n g e u s a g e a n d c a p a b i l i t i e s ,
r e f e r t o t h e : c o m m a n d : ` f i n d _ p a c k a g e ` c o m m a n d .
T h e m o d u l e d e f i n e s t h e f o l l o w i n g v a r i a b l e s :
` ` S W I G _ F O U N D ` `
W h e t h e r S W I G a n d a n y r e q u i r e d c o m p o n e n t s w e r e f o u n d o n t h e s y s t e m .
` ` S W I G _ E X E C U T A B L E ` `
P a t h t o t h e S W I G e x e c u t a b l e .
` ` S W I G _ D I R ` `
P a t h t o t h e i n s t a l l e d S W I G ` ` L i b ` ` directory ( result of ``swig -swiglib`` ) .
` ` S W I G _ V E R S I O N ` `
S W I G e x e c u t a b l e version ( result of ``swig -version`` ) .
` ` S W I G _ < l a n g > _ F O U N D ` `
I f ` ` C O M P O N E N T S ` ` o r ` ` O P T I O N A L _ C O M P O N E N T S ` ` a r e r e q u e s t e d , e a c h a v a i l a b l e
t a r g e t l a n g u a g e ` ` < l a n g > ` ` ( l o w e r c a s e ) w i l l b e s e t t o T R U E .
A n y ` ` C O M P O N E N T S ` ` g i v e n t o ` ` f i n d _ p a c k a g e ` ` s h o u l d b e t h e n a m e s o f s u p p o r t e d
t a r g e t l a n g u a g e s a s p r o v i d e d t o t h e L A N G U A G E a r g u m e n t o f ` ` s w i g _ a d d _ l i b r a r y ` ` ,
s u c h a s ` ` p y t h o n ` ` o r ` ` p e r l 5 ` ` . L a n g u a g e n a m e s * m u s t * b e l o w e r c a s e .
A l l i n f o r m a t i o n i s c o l l e c t e d f r o m t h e ` ` S W I G _ E X E C U T A B L E ` ` , s o t h e v e r s i o n
t o b e f o u n d c a n b e c h a n g e d f r o m t h e c o m m a n d l i n e b y m e a n s o f s e t t i n g
` ` S W I G _ E X E C U T A B L E ` ` .
E x a m p l e u s a g e r e q u i r i n g S W I G 4 . 0 o r h i g h e r a n d P y t h o n l a n g u a g e s u p p o r t , w i t h
o p t i o n a l F o r t r a n s u p p o r t :
. . c o d e - b l o c k : : c m a k e
find_package ( SWIG 4.0 COMPONENTS python OPTIONAL_COMPONENTS fortran )
if ( SWIG_FOUND )
message ( "SWIG found: ${SWIG_EXECUTABLE}" )
if ( NOT SWIG_fortran_FOUND )
message ( WARNING "SWIG Fortran bindings cannot be generated" )
endif ( )
endif ( )
. . _ S W I G : h t t p s : / / s w i g . o r g
#]=======================================================================]
include ( ${ CMAKE_CURRENT_LIST_DIR } /FindPackageHandleStandardArgs.cmake )
function ( _swig_get_version _swig_executable _swig_version )
unset ( ${ _swig_version } PARENT_SCOPE )
# Determine SWIG version
execute_process ( COMMAND "${_swig_executable}" -version
O U T P U T _ V A R I A B L E _ s w i g _ o u t p u t
E R R O R _ V A R I A B L E _ s w i g _ o u t p u t
R E S U L T _ V A R I A B L E _ s w i g _ r e s u l t )
if ( _swig_result )
set_property ( CACHE _SWIG_REASON_FAILURE PROPERTY VALUE "Cannot use the executable \" ${ _swig_executable } \"")
if ( _swig_output )
set_property ( CACHE _SWIG_REASON_FAILURE APPEND_STRING PROPERTY VALUE ": ${_swig_output}" )
endif ( )
else ( )
string ( REGEX REPLACE ".*SWIG Version[^0-9.]*\([0-9.]+\).*" "\\1"
_ s w i g _ o u t p u t " $ { _ s w i g _ o u t p u t } " )
set ( ${ _swig_version } ${ _swig_output } PARENT_SCOPE )
endif ( )
endfunction ( )
function ( _swig_validate_find_executable status executable )
_swig_get_version ( "${executable}" _swig_find_version )
if ( NOT _swig_find_version )
# executable is unusable
set ( ${ status } FALSE PARENT_SCOPE )
return ( )
endif ( )
if ( NOT SWIG_FIND_VERSION )
return ( )
endif ( )
find_package_check_version ( ${ _swig_find_version } _swig_version_is_valid HANDLE_VERSION_RANGE )
if ( _swig_version_is_valid )
unset ( _SWIG_REASON_FAILURE CACHE )
else ( )
set ( ${ status } FALSE PARENT_SCOPE )
set_property ( CACHE _SWIG_REASON_FAILURE PROPERTY VALUE "Could NOT find SWIG: Found unsuitable version \" ${ _swig_find_version } \" for the executable \"${executable}\"")
endif ( )
endfunction ( )
unset ( _SWIG_REASON_FAILURE )
set ( _SWIG_REASON_FAILURE CACHE INTERNAL "SWIG reason failure" )
# compute list of possible names
unset ( _SWIG_NAMES )
if ( SWIG_FIND_VERSION_RANGE )
foreach ( _SWIG_MAJOR IN ITEMS 4 3 2 )
if ( _SWIG_MAJOR VERSION_GREATER_EQUAL SWIG_FIND_VERSION_MIN_MAJOR
AND ( ( SWIG_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND _SWIG_MAJOR VERSION_LESS_EQUAL SWIG_FIND_VERSION_MAX )
OR ( SWIG_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND _SWIG_MAJOR VERSION_LESS SWIG_FIND_VERSION_MAX ) ) )
list ( APPEND _SWIG_NAMES swig ${ _SWIG_MAJOR } .0 )
endif ( )
endforeach ( )
elseif ( SWIG_FIND_VERSION )
if ( SWIG_FIND_VERSION_EXACT )
set ( _SWIG_NAMES swig ${ SWIG_FIND_VERSION_MAJOR } .0 )
else ( )
foreach ( _SWIG_MAJOR IN ITEMS 4 3 2 )
if ( _SWIG_MAJOR VERSION_GREATER_EQUAL SWIG_FIND_VERSION_MAJOR )
list ( APPEND _SWIG_NAMES swig ${ _SWIG_MAJOR } .0 )
endif ( )
endforeach ( )
endif ( )
else ( )
set ( _SWIG_NAMES swig4.0 swig3.0 swig2.0 )
endif ( )
if ( NOT _SWIG_NAMES )
# try to find any version
set ( _SWIG_NAMES swig4.0 swig3.0 swig2.0 )
endif ( )
find_program ( SWIG_EXECUTABLE NAMES ${ _SWIG_NAMES } swig NAMES_PER_DIR
V A L I D A T O R _ s w i g _ v a l i d a t e _ f i n d _ e x e c u t a b l e )
unset ( _SWIG_NAMES )
if ( SWIG_EXECUTABLE AND NOT SWIG_DIR )
# Find default value for SWIG library directory
execute_process ( COMMAND "${SWIG_EXECUTABLE}" -swiglib
O U T P U T _ V A R I A B L E _ s w i g _ o u t p u t
E R R O R _ V A R I A B L E _ s w i g _ e r r o r
R E S U L T _ V A R I A B L E _ s w i g _ r e s u l t )
if ( _swig_result )
set ( _msg "Command \" ${ SWIG_EXECUTABLE } -swiglib\ " failed with output:\n${_swig_error}" )
if ( SWIG_FIND_REQUIRED )
message ( SEND_ERROR "${_msg}" )
else ( )
message ( STATUS "${_msg}" )
endif ( )
unset ( _msg )
else ( )
string ( REGEX REPLACE "[\n\r]+" ";" _SWIG_LIB ${ _swig_output } )
endif ( )
# Find SWIG library directory
find_path ( SWIG_DIR swig.swg PATHS ${ _SWIG_LIB } NO_CMAKE_FIND_ROOT_PATH )
unset ( _SWIG_LIB )
endif ( )
if ( SWIG_EXECUTABLE AND SWIG_DIR AND NOT SWIG_VERSION )
# Determine SWIG version
_swig_get_version ( "${SWIG_EXECUTABLE}" _swig_output )
set ( SWIG_VERSION ${ _swig_output } CACHE STRING "Swig version" FORCE )
endif ( )
if ( SWIG_EXECUTABLE AND SWIG_FIND_COMPONENTS )
execute_process ( COMMAND "${SWIG_EXECUTABLE}" -help
O U T P U T _ V A R I A B L E _ s w i g _ o u t p u t
E R R O R _ V A R I A B L E _ s w i g _ e r r o r
R E S U L T _ V A R I A B L E _ s w i g _ r e s u l t )
if ( _swig_result )
message ( SEND_ERROR "Command \" ${ SWIG_EXECUTABLE } -help\ " failed with output:\n${_swig_error}" )
else ( )
string ( REPLACE "\n" ";" _swig_output "${_swig_output}" )
foreach ( SWIG_line IN LISTS _swig_output )
if ( SWIG_line MATCHES "-([A-Za-z0-9_]+) +- *Generate.*wrappers" )
set ( SWIG_ ${ CMAKE_MATCH_1 } _FOUND TRUE )
endif ( )
endforeach ( )
endif ( )
endif ( )
find_package_handle_standard_args (
S W I G H A N D L E _ C O M P O N E N T S
R E Q U I R E D _ V A R S S W I G _ E X E C U T A B L E S W I G _ D I R
V E R S I O N _ V A R S W I G _ V E R S I O N
H A N D L E _ V E R S I O N _ R A N G E
F A I L _ M E S S A G E " $ { _ S W I G _ R E A S O N _ F A I L U R E } " )
unset ( _swig_output )
unset ( _swig_error )
unset ( _swig_result )
unset ( _SWIG_REASON_FAILURE CACHE )
if ( SWIG_FOUND )
set ( SWIG_USE_FILE "${CMAKE_CURRENT_LIST_DIR}/UseSWIG.cmake" )
endif ( )
mark_as_advanced ( SWIG_DIR SWIG_VERSION SWIG_EXECUTABLE )