UseSWIG.cmake 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. UseSWIG
  5. -------
  6. This file provides support for ``SWIG``. It is assumed that :module:`FindSWIG`
  7. module has already been loaded.
  8. Defines the following command for use with ``SWIG``:
  9. .. command:: swig_add_library
  10. Define swig module with given name and specified language::
  11. swig_add_library(<name>
  12. [TYPE <SHARED|MODULE|STATIC|USE_BUILD_SHARED_LIBS>]
  13. LANGUAGE <language>
  14. [NO_PROXY]
  15. [OUTPUT_DIR <directory>]
  16. [OUTFILE_DIR <directory>]
  17. SOURCES <file>...
  18. )
  19. Targets created with the ``swig_add_library`` command have the same
  20. capabilities as targets created with the :command:`add_library` command, so
  21. those targets can be used with any command expecting a target (e.g.
  22. :command:`target_link_libraries`).
  23. .. note::
  24. This command creates a target with the specified ``<name>`` when
  25. policy :policy:`CMP0078` is set to ``NEW``. Otherwise, the legacy
  26. behavior will choose a different target name and store it in the
  27. ``SWIG_MODULE_<name>_REAL_NAME`` variable.
  28. .. note::
  29. For multi-config generators, this module does not support
  30. configuration-specific files generated by ``SWIG``. All build
  31. configurations must result in the same generated source file.
  32. .. note::
  33. For Make-based generators, ``swig_add_library`` does not track file
  34. dependencies, so depending on the ``<name>_swig_compilation`` custom target
  35. is required for targets which require the ``swig``-generated files to
  36. exist. Other generators may depend on the source files that would be
  37. generated by SWIG.
  38. ``TYPE``
  39. ``SHARED``, ``MODULE`` and ``STATIC`` have the same semantic as for the
  40. :command:`add_library` command. If ``USE_BUILD_SHARED_LIBS`` is specified,
  41. the library type will be ``STATIC`` or ``SHARED`` based on whether the
  42. current value of the :variable:`BUILD_SHARED_LIBS` variable is ``ON``. If
  43. no type is specified, ``MODULE`` will be used.
  44. ``LANGUAGE``
  45. Specify the target language.
  46. ``NO_PROXY``
  47. Prevent the generation of the wrapper layer (swig ``-noproxy`` option).
  48. ``OUTPUT_DIR``
  49. Specify where to write the language specific files (swig ``-outdir``
  50. option). If not given, the ``CMAKE_SWIG_OUTDIR`` variable will be used.
  51. If neither is specified, the default depends on the value of the
  52. ``UseSWIG_MODULE_VERSION`` variable as follows:
  53. * If ``UseSWIG_MODULE_VERSION`` is 1 or is undefined, output is written to
  54. the :variable:`CMAKE_CURRENT_BINARY_DIR` directory.
  55. * If ``UseSWIG_MODULE_VERSION`` is 2, a dedicated directory will be used.
  56. The path of this directory can be retrieved from the
  57. ``SWIG_SUPPORT_FILES_DIRECTORY`` target property.
  58. ``OUTFILE_DIR``
  59. Specify an output directory name where the generated source file will be
  60. placed (swig ``-o`` option). If not specified, the ``SWIG_OUTFILE_DIR``
  61. variable will be used. If neither is specified, ``OUTPUT_DIR`` or
  62. ``CMAKE_SWIG_OUTDIR`` is used instead.
  63. ``SOURCES``
  64. List of sources for the library. Files with extension ``.i`` will be
  65. identified as sources for the ``SWIG`` tool. Other files will be handled in
  66. the standard way. This behavior can be overridden by specifying the variable
  67. ``SWIG_SOURCE_FILE_EXTENSIONS``.
  68. .. note::
  69. If ``UseSWIG_MODULE_VERSION`` is set to 2, it is **strongly** recommended
  70. to use a dedicated directory unique to the target when either the
  71. ``OUTPUT_DIR`` option or the ``CMAKE_SWIG_OUTDIR`` variable are specified.
  72. The output directory contents are erased as part of the target build, so
  73. to prevent interference between targets or losing other important files,
  74. each target should have its own dedicated output directory.
  75. .. command:: swig_link_libraries
  76. Link libraries to swig module::
  77. swig_link_libraries(<name> <item>...)
  78. This command has same capabilities as :command:`target_link_libraries`
  79. command.
  80. .. note::
  81. If variable ``UseSWIG_TARGET_NAME_PREFERENCE`` is set to ``STANDARD``, this
  82. command is deprecated and :command:`target_link_libraries` command must be
  83. used instead.
  84. Source file properties on module files **must** be set before the invocation
  85. of the ``swig_add_library`` command to specify special behavior of SWIG and
  86. ensure generated files will receive the required settings.
  87. ``CPLUSPLUS``
  88. Call SWIG in c++ mode. For example:
  89. .. code-block:: cmake
  90. set_property(SOURCE mymod.i PROPERTY CPLUSPLUS ON)
  91. swig_add_library(mymod LANGUAGE python SOURCES mymod.i)
  92. ``INCLUDE_DIRECTORIES``, ``COMPILE_DEFINITIONS`` and ``COMPILE_OPTIONS``
  93. Add custom flags to SWIG compiler and have same semantic as properties
  94. :prop_sf:`INCLUDE_DIRECTORIES`, :prop_sf:`COMPILE_DEFINITIONS` and
  95. :prop_sf:`COMPILE_OPTIONS`.
  96. ``USE_TARGET_INCLUDE_DIRECTORIES``
  97. If set to ``TRUE``, contents of target property
  98. :prop_tgt:`INCLUDE_DIRECTORIES` will be forwarded to ``SWIG`` compiler.
  99. If set to ``FALSE`` target property :prop_tgt:`INCLUDE_DIRECTORIES` will be
  100. ignored. If not set, target property ``SWIG_USE_TARGET_INCLUDE_DIRECTORIES``
  101. will be considered.
  102. ``GENERATED_INCLUDE_DIRECTORIES``, ``GENERATED_COMPILE_DEFINITIONS`` and ``GENERATED_COMPILE_OPTIONS``
  103. Add custom flags to the C/C++ generated source. They will fill, respectively,
  104. properties :prop_sf:`INCLUDE_DIRECTORIES`, :prop_sf:`COMPILE_DEFINITIONS` and
  105. :prop_sf:`COMPILE_OPTIONS` of generated C/C++ file.
  106. ``DEPENDS``
  107. Specify additional dependencies to the source file.
  108. ``SWIG_MODULE_NAME``
  109. Specify the actual import name of the module in the target language.
  110. This is required if it cannot be scanned automatically from source
  111. or different from the module file basename. For example:
  112. .. code-block:: cmake
  113. set_property(SOURCE mymod.i PROPERTY SWIG_MODULE_NAME mymod_realname)
  114. .. note::
  115. If policy :policy:`CMP0086` is set to ``NEW``, ``-module <module_name>``
  116. is passed to ``SWIG`` compiler.
  117. ``OUTPUT_DIR``
  118. Specify where to write the language specific files (swig ``-outdir`` option)
  119. for the considered source file. If not specified, the other ways to define
  120. the output directory applies (see ``OUTPUT_DIR`` option of
  121. ``swig_add_library()`` command).
  122. ``OUTFILE_DIR``
  123. Specify an output directory where the generated source file will be placed
  124. (swig ``-o`` option) for the considered source file. If not specified,
  125. ``OUTPUT_DIR`` source property will be used. If neither are specified, the
  126. other ways to define output file directory applies (see ``OUTFILE_DIR``
  127. option of ``swig_add_library()`` command).
  128. Target library properties can be set to apply same configuration to all SWIG
  129. input files.
  130. ``SWIG_INCLUDE_DIRECTORIES``, ``SWIG_COMPILE_DEFINITIONS`` and ``SWIG_COMPILE_OPTIONS``
  131. These properties will be applied to all SWIG input files and have same
  132. semantic as target properties :prop_tgt:`INCLUDE_DIRECTORIES`,
  133. :prop_tgt:`COMPILE_DEFINITIONS` and :prop_tgt:`COMPILE_OPTIONS`.
  134. .. code-block:: cmake
  135. set (UseSWIG_TARGET_NAME_PREFERENCE STANDARD)
  136. swig_add_library(mymod LANGUAGE python SOURCES mymod.i)
  137. set_property(TARGET mymod PROPERTY SWIG_COMPILE_DEFINITIONS MY_DEF1 MY_DEF2)
  138. set_property(TARGET mymod PROPERTY SWIG_COMPILE_OPTIONS -bla -blb)
  139. ``SWIG_USE_TARGET_INCLUDE_DIRECTORIES``
  140. If set to ``TRUE``, contents of target property
  141. :prop_tgt:`INCLUDE_DIRECTORIES` will be forwarded to ``SWIG`` compiler.
  142. If set to ``FALSE`` or not defined, target property
  143. :prop_tgt:`INCLUDE_DIRECTORIES` will be ignored. This behavior can be
  144. overridden by specifying source property ``USE_TARGET_INCLUDE_DIRECTORIES``.
  145. ``SWIG_GENERATED_INCLUDE_DIRECTORIES``, ``SWIG_GENERATED_COMPILE_DEFINITIONS`` and ``SWIG_GENERATED_COMPILE_OPTIONS``
  146. These properties will populate, respectively, properties
  147. :prop_sf:`INCLUDE_DIRECTORIES`, :prop_sf:`COMPILE_DEFINITIONS` and
  148. :prop_sf:`COMPILE_FLAGS` of all generated C/C++ files.
  149. ``SWIG_DEPENDS``
  150. Add dependencies to all SWIG input files.
  151. The following target properties are output properties and can be used to get
  152. information about support files generated by ``SWIG`` interface compilation.
  153. ``SWIG_SUPPORT_FILES``
  154. This output property list of wrapper files generated during SWIG compilation.
  155. .. code-block:: cmake
  156. set (UseSWIG_TARGET_NAME_PREFERENCE STANDARD)
  157. swig_add_library(mymod LANGUAGE python SOURCES mymod.i)
  158. get_property(support_files TARGET mymod PROPERTY SWIG_SUPPORT_FILES)
  159. .. note::
  160. Only most principal support files are listed. In case some advanced
  161. features of ``SWIG`` are used (for example ``%template``), associated
  162. support files may not be listed. Prefer to use the
  163. ``SWIG_SUPPORT_FILES_DIRECTORY`` property to handle support files.
  164. ``SWIG_SUPPORT_FILES_DIRECTORY``
  165. This output property specifies the directory where support files will be
  166. generated.
  167. .. note::
  168. When source property ``OUTPUT_DIR`` is defined, multiple directories can be
  169. specified as part of ``SWIG_SUPPORT_FILES_DIRECTORY``.
  170. Some variables can be set to customize the behavior of ``swig_add_library``
  171. as well as ``SWIG``:
  172. ``UseSWIG_MODULE_VERSION``
  173. Specify different behaviors for ``UseSWIG`` module.
  174. * Set to 1 or undefined: Legacy behavior is applied.
  175. * Set to 2: A new strategy is applied regarding support files: the output
  176. directory of support files is erased before ``SWIG`` interface compilation.
  177. ``CMAKE_SWIG_FLAGS``
  178. Add flags to all swig calls.
  179. ``CMAKE_SWIG_OUTDIR``
  180. Specify where to write the language specific files (swig ``-outdir`` option).
  181. ``SWIG_OUTFILE_DIR``
  182. Specify an output directory name where the generated source file will be
  183. placed. If not specified, ``CMAKE_SWIG_OUTDIR`` is used.
  184. ``SWIG_MODULE_<name>_EXTRA_DEPS``
  185. Specify extra dependencies for the generated module for ``<name>``.
  186. ``SWIG_SOURCE_FILE_EXTENSIONS``
  187. Specify a list of source file extensions to override the default
  188. behavior of considering only ``.i`` files as sources for the ``SWIG``
  189. tool. For example:
  190. .. code-block:: cmake
  191. set(SWIG_SOURCE_FILE_EXTENSIONS ".i" ".swg")
  192. #]=======================================================================]
  193. cmake_policy(GET CMP0078 target_name_policy)
  194. cmake_policy(GET CMP0086 module_name_policy)
  195. cmake_policy (VERSION 3.12)
  196. if (target_name_policy)
  197. # respect user choice regarding CMP0078 policy
  198. cmake_policy(SET CMP0078 ${target_name_policy})
  199. endif()
  200. if (module_name_policy)
  201. # respect user choice regarding CMP0086 policy
  202. cmake_policy(SET CMP0086 ${module_name_policy})
  203. endif()
  204. unset(target_name_policy)
  205. unset(module_name_policy)
  206. set(SWIG_CXX_EXTENSION "cxx")
  207. set(SWIG_EXTRA_LIBRARIES "")
  208. set(SWIG_PYTHON_EXTRA_FILE_EXTENSIONS ".py")
  209. set(SWIG_JAVA_EXTRA_FILE_EXTENSIONS ".java" "JNI.java")
  210. set(SWIG_CSHARP_EXTRA_FILE_EXTENSIONS ".cs" "PINVOKE.cs")
  211. set(SWIG_MANAGE_SUPPORT_FILES_SCRIPT "${CMAKE_CURRENT_LIST_DIR}/UseSWIG/ManageSupportFiles.cmake")
  212. ##
  213. ## PRIVATE functions
  214. ##
  215. function (__SWIG_COMPUTE_TIMESTAMP name language infile workingdir __timestamp)
  216. get_filename_component(filename "${infile}" NAME_WE)
  217. set(${__timestamp}
  218. "${workingdir}/${filename}${language}.stamp" PARENT_SCOPE)
  219. # get_filename_component(filename "${infile}" ABSOLUTE)
  220. # string(UUID uuid NAMESPACE 9735D882-D2F8-4E1D-88C9-A0A4F1F6ECA4
  221. # NAME ${name}-${language}-${filename} TYPE SHA1)
  222. # set(${__timestamp} "${workingdir}/${uuid}.stamp" PARENT_SCOPE)
  223. endfunction()
  224. #
  225. # For given swig module initialize variables associated with it
  226. #
  227. macro(SWIG_MODULE_INITIALIZE name language)
  228. string(TOUPPER "${language}" SWIG_MODULE_${name}_LANGUAGE)
  229. string(TOLOWER "${language}" SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG)
  230. if (NOT DEFINED SWIG_MODULE_${name}_NOPROXY)
  231. set (SWIG_MODULE_${name}_NOPROXY FALSE)
  232. endif()
  233. if ("-noproxy" IN_LIST CMAKE_SWIG_FLAGS)
  234. set (SWIG_MODULE_${name}_NOPROXY TRUE)
  235. endif ()
  236. if (SWIG_MODULE_${name}_NOPROXY AND
  237. NOT ("-noproxy" IN_LIST CMAKE_SWIG_FLAGS OR "-noproxy" IN_LIST SWIG_MODULE_${name}_EXTRA_FLAGS))
  238. list (APPEND SWIG_MODULE_${name}_EXTRA_FLAGS "-noproxy")
  239. endif()
  240. if(SWIG_MODULE_${name}_LANGUAGE STREQUAL "UNKNOWN")
  241. message(FATAL_ERROR "SWIG Error: Language \"${language}\" not found")
  242. elseif(SWIG_MODULE_${name}_LANGUAGE STREQUAL "PERL" AND
  243. NOT "-shadow" IN_LIST SWIG_MODULE_${name}_EXTRA_FLAGS)
  244. list(APPEND SWIG_MODULE_${name}_EXTRA_FLAGS "-shadow")
  245. endif()
  246. endmacro()
  247. #
  248. # For a given language, input file, and output file, determine extra files that
  249. # will be generated. This is internal swig macro.
  250. #
  251. function(SWIG_GET_EXTRA_OUTPUT_FILES language outfiles generatedpath infile)
  252. set(files)
  253. get_source_file_property(module_basename
  254. "${infile}" SWIG_MODULE_NAME)
  255. if(NOT module_basename)
  256. # try to get module name from "%module foo" syntax
  257. if ( EXISTS "${infile}" )
  258. file ( STRINGS "${infile}" module_basename REGEX "[ ]*%module[ ]*[a-zA-Z0-9_]+.*" )
  259. endif ()
  260. if ( module_basename )
  261. string ( REGEX REPLACE "[ ]*%module[ ]*([a-zA-Z0-9_]+).*" "\\1" module_basename "${module_basename}" )
  262. else ()
  263. # try to get module name from "%module (options=...) foo" syntax
  264. if ( EXISTS "${infile}" )
  265. file ( STRINGS "${infile}" module_basename REGEX "[ ]*%module[ ]*\\(.*\\)[ ]*[a-zA-Z0-9_]+.*" )
  266. endif ()
  267. if ( module_basename )
  268. string ( REGEX REPLACE "[ ]*%module[ ]*\\(.*\\)[ ]*([a-zA-Z0-9_]+).*" "\\1" module_basename "${module_basename}" )
  269. else ()
  270. # fallback to file basename
  271. get_filename_component(module_basename "${infile}" NAME_WE)
  272. endif ()
  273. endif ()
  274. endif()
  275. foreach(it ${SWIG_${language}_EXTRA_FILE_EXTENSIONS})
  276. set(extra_file "${generatedpath}/${module_basename}${it}")
  277. if (extra_file MATCHES "\\.cs$" AND CMAKE_CSharp_COMPILER_LOADED)
  278. set_source_files_properties(${extra_file} PROPERTIES LANGUAGE "CSharp")
  279. else()
  280. # Treat extra outputs as plain files regardless of language.
  281. set_source_files_properties(${extra_file} PROPERTIES LANGUAGE "")
  282. endif()
  283. list(APPEND files "${extra_file}")
  284. endforeach()
  285. if (language STREQUAL "FORTRAN" AND CMAKE_Fortran_COMPILER_LOADED)
  286. # Process possible user-supplied extension in flags (obtained via parent
  287. # scope variable) to determine the source file name.
  288. list(FIND SWIG_COMPILATION_FLAGS "-fext" fext_idx)
  289. if (fext_idx EQUAL -1)
  290. # Default Fortran generated extension
  291. set(fext "f90")
  292. else()
  293. # Get extension from user-provided flag
  294. math(EXPR fext_idx "${fext_idx} + 1")
  295. list(GET SWIG_COMPILATION_FLAGS "${fext_idx}" fext)
  296. endif()
  297. set(extra_file "${generatedpath}/${module_basename}.${fext}")
  298. set_source_files_properties("${extra_file}" PROPERTIES LANGUAGE "Fortran")
  299. list(APPEND files "${extra_file}")
  300. endif()
  301. set (${outfiles} ${files} PARENT_SCOPE)
  302. endfunction()
  303. #
  304. # Take swig (*.i) file and add proper custom commands for it
  305. #
  306. function(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile)
  307. get_filename_component(swig_source_file_name_we "${infile}" NAME_WE)
  308. get_source_file_property(swig_source_file_cplusplus "${infile}" CPLUSPLUS)
  309. get_source_file_property(swig_source_file_outdir "${infile}" OUTPUT_DIR)
  310. get_source_file_property(swig_source_file_outfiledir "${infile}" OUTFILE_DIR)
  311. if (swig_source_file_outdir)
  312. # use source file property
  313. set(outdir "${swig_source_file_outdir}")
  314. if (NOT swig_source_file_outfiledir)
  315. set (swig_source_file_outfiledir "${outdir}")
  316. endif()
  317. elseif(CMAKE_SWIG_OUTDIR)
  318. set(outdir ${CMAKE_SWIG_OUTDIR})
  319. else()
  320. set(outdir ${CMAKE_CURRENT_BINARY_DIR})
  321. endif()
  322. if (swig_source_file_outfiledir)
  323. set (outfiledir "${swig_source_file_outfiledir}")
  324. elseif(SWIG_OUTFILE_DIR)
  325. set(outfiledir ${SWIG_OUTFILE_DIR})
  326. else()
  327. set(outfiledir ${outdir})
  328. endif()
  329. if(SWIG_WORKING_DIR)
  330. set (workingdir "${SWIG_WORKING_DIR}")
  331. else()
  332. set(workingdir "${outdir}")
  333. endif()
  334. if(SWIG_TARGET_NAME)
  335. set(target_name ${SWIG_TARGET_NAME})
  336. else()
  337. set(target_name ${name})
  338. endif()
  339. set (swig_source_file_flags ${CMAKE_SWIG_FLAGS})
  340. # handle various swig compile flags properties
  341. get_source_file_property (include_directories "${infile}" INCLUDE_DIRECTORIES)
  342. if (include_directories)
  343. list (APPEND swig_source_file_flags "$<$<BOOL:${include_directories}>:-I$<JOIN:${include_directories},$<SEMICOLON>-I>>")
  344. endif()
  345. set (property "$<TARGET_PROPERTY:${target_name},SWIG_INCLUDE_DIRECTORIES>")
  346. list (APPEND swig_source_file_flags "$<$<BOOL:${property}>:-I$<JOIN:$<TARGET_GENEX_EVAL:${target_name},${property}>,$<SEMICOLON>-I>>")
  347. set (property "$<TARGET_PROPERTY:${target_name},INCLUDE_DIRECTORIES>")
  348. get_source_file_property(use_target_include_dirs "${infile}" USE_TARGET_INCLUDE_DIRECTORIES)
  349. if (use_target_include_dirs)
  350. list (APPEND swig_source_file_flags "$<$<BOOL:${property}>:-I$<JOIN:${property},$<SEMICOLON>-I>>")
  351. elseif(use_target_include_dirs STREQUAL "NOTFOUND")
  352. # not defined at source level, rely on target level
  353. list (APPEND swig_source_file_flags "$<$<AND:$<BOOL:$<TARGET_PROPERTY:${target_name},SWIG_USE_TARGET_INCLUDE_DIRECTORIES>>,$<BOOL:${property}>>:-I$<JOIN:${property},$<SEMICOLON>-I>>")
  354. endif()
  355. set (property "$<TARGET_PROPERTY:${target_name},SWIG_COMPILE_DEFINITIONS>")
  356. list (APPEND swig_source_file_flags "$<$<BOOL:${property}>:-D$<JOIN:$<TARGET_GENEX_EVAL:${target_name},${property}>,$<SEMICOLON>-D>>")
  357. get_source_file_property (compile_definitions "${infile}" COMPILE_DEFINITIONS)
  358. if (compile_definitions)
  359. list (APPEND swig_source_file_flags "$<$<BOOL:${compile_definitions}>:-D$<JOIN:${compile_definitions},$<SEMICOLON>-D>>")
  360. endif()
  361. list (APPEND swig_source_file_flags "$<TARGET_GENEX_EVAL:${target_name},$<TARGET_PROPERTY:${target_name},SWIG_COMPILE_OPTIONS>>")
  362. get_source_file_property (compile_options "${infile}" COMPILE_OPTIONS)
  363. if (compile_options)
  364. list (APPEND swig_source_file_flags ${compile_options})
  365. endif()
  366. # legacy support
  367. get_source_file_property (swig_flags "${infile}" SWIG_FLAGS)
  368. if (swig_flags)
  369. list (APPEND swig_source_file_flags ${swig_flags})
  370. endif()
  371. get_filename_component(swig_source_file_fullname "${infile}" ABSOLUTE)
  372. if (NOT SWIG_MODULE_${name}_NOPROXY)
  373. set(SWIG_COMPILATION_FLAGS ${swig_source_file_flags})
  374. SWIG_GET_EXTRA_OUTPUT_FILES(${SWIG_MODULE_${name}_LANGUAGE}
  375. swig_extra_generated_files
  376. "${outdir}"
  377. "${swig_source_file_fullname}")
  378. endif()
  379. set(swig_generated_file_fullname
  380. "${outfiledir}/${swig_source_file_name_we}")
  381. # add the language into the name of the file (i.e. TCL_wrap)
  382. # this allows for the same .i file to be wrapped into different languages
  383. string(APPEND swig_generated_file_fullname
  384. "${SWIG_MODULE_${name}_LANGUAGE}_wrap")
  385. if(swig_source_file_cplusplus)
  386. string(APPEND swig_generated_file_fullname
  387. ".${SWIG_CXX_EXTENSION}")
  388. else()
  389. string(APPEND swig_generated_file_fullname
  390. ".c")
  391. endif()
  392. get_directory_property (cmake_include_directories INCLUDE_DIRECTORIES)
  393. list (REMOVE_DUPLICATES cmake_include_directories)
  394. set (swig_include_dirs)
  395. if (cmake_include_directories)
  396. set (swig_include_dirs "$<$<BOOL:${cmake_include_directories}>:-I$<JOIN:${cmake_include_directories},$<SEMICOLON>-I>>")
  397. endif()
  398. set(swig_special_flags)
  399. # default is c, so add c++ flag if it is c++
  400. if(swig_source_file_cplusplus)
  401. list (APPEND swig_special_flags "-c++")
  402. endif()
  403. cmake_policy(GET CMP0086 module_name_policy)
  404. if (module_name_policy STREQUAL "NEW")
  405. get_source_file_property(module_name "${infile}" SWIG_MODULE_NAME)
  406. if (module_name)
  407. list (APPEND swig_special_flags "-module" "${module_name}")
  408. endif()
  409. else()
  410. if (NOT module_name_policy)
  411. cmake_policy(GET_WARNING CMP0086 _cmp0086_warning)
  412. message(AUTHOR_WARNING "${_cmp0086_warning}\n")
  413. endif()
  414. endif()
  415. set (swig_extra_flags)
  416. if(SWIG_MODULE_${name}_LANGUAGE STREQUAL "CSHARP")
  417. if(NOT ("-dllimport" IN_LIST swig_source_file_flags OR "-dllimport" IN_LIST SWIG_MODULE_${name}_EXTRA_FLAGS))
  418. # This makes sure that the name used in the generated DllImport
  419. # matches the library name created by CMake
  420. list (APPEND SWIG_MODULE_${name}_EXTRA_FLAGS "-dllimport" "$<TARGET_FILE_PREFIX:${target_name}>$<TARGET_FILE_BASE_NAME:${target_name}>")
  421. endif()
  422. endif()
  423. if (SWIG_MODULE_${name}_LANGUAGE STREQUAL "PYTHON" AND NOT SWIG_MODULE_${name}_NOPROXY)
  424. if(SWIG_USE_INTERFACE AND
  425. NOT ("-interface" IN_LIST swig_source_file_flags OR "-interface" IN_LIST SWIG_MODULE_${name}_EXTRA_FLAGS))
  426. # This makes sure that the name used in the proxy code
  427. # matches the library name created by CMake
  428. list (APPEND SWIG_MODULE_${name}_EXTRA_FLAGS "-interface" "$<TARGET_FILE_PREFIX:${target_name}>$<TARGET_FILE_BASE_NAME:${target_name}>")
  429. endif()
  430. endif()
  431. list (APPEND swig_extra_flags ${SWIG_MODULE_${name}_EXTRA_FLAGS})
  432. # dependencies
  433. set (swig_dependencies ${SWIG_MODULE_${name}_EXTRA_DEPS} $<TARGET_PROPERTY:${target_name},SWIG_DEPENDS>)
  434. get_source_file_property(file_depends "${infile}" DEPENDS)
  435. if (file_depends)
  436. list (APPEND swig_dependencies ${file_depends})
  437. endif()
  438. if (UseSWIG_MODULE_VERSION VERSION_GREATER 1)
  439. # as part of custom command, start by removing old generated files
  440. # to ensure obsolete files do not stay
  441. set (swig_file_outdir "${workingdir}/${swig_source_file_name_we}.files")
  442. set (swig_cleanup_command COMMAND "${CMAKE_COMMAND}" "-DSUPPORT_FILES_WORKING_DIRECTORY=${swig_file_outdir}" "-DSUPPORT_FILES_OUTPUT_DIRECTORY=${outdir}" -DACTION=CLEAN -P "${SWIG_MANAGE_SUPPORT_FILES_SCRIPT}")
  443. set (swig_copy_command COMMAND "${CMAKE_COMMAND}" "-DSUPPORT_FILES_WORKING_DIRECTORY=${swig_file_outdir}" "-DSUPPORT_FILES_OUTPUT_DIRECTORY=${outdir}" -DACTION=COPY -P "${SWIG_MANAGE_SUPPORT_FILES_SCRIPT}")
  444. else()
  445. set (swig_file_outdir "${outdir}")
  446. unset (swig_cleanup_command)
  447. unset (swig_copy_command)
  448. endif()
  449. # IMPLICIT_DEPENDS below can not handle situations where a dependent file is
  450. # removed. We need an extra step with timestamp and custom target, see #16830
  451. # As this is needed only for Makefile generator do it conditionally
  452. if(CMAKE_GENERATOR MATCHES "Make")
  453. __swig_compute_timestamp(${name} ${SWIG_MODULE_${name}_LANGUAGE}
  454. "${infile}" "${workingdir}" swig_generated_timestamp)
  455. set(swig_custom_output "${swig_generated_timestamp}")
  456. set(swig_custom_products
  457. BYPRODUCTS "${swig_generated_file_fullname}" ${swig_extra_generated_files})
  458. set(swig_timestamp_command
  459. COMMAND ${CMAKE_COMMAND} -E touch "${swig_generated_timestamp}")
  460. else()
  461. set(swig_custom_output
  462. "${swig_generated_file_fullname}" ${swig_extra_generated_files})
  463. set(swig_custom_products)
  464. set(swig_timestamp_command)
  465. endif()
  466. add_custom_command(
  467. OUTPUT ${swig_custom_output}
  468. ${swig_custom_products}
  469. ${swig_cleanup_command}
  470. # Let's create the ${outdir} at execution time, in case dir contains $(OutDir)
  471. COMMAND "${CMAKE_COMMAND}" -E make_directory ${outdir} ${outfiledir}
  472. ${swig_timestamp_command}
  473. COMMAND "${CMAKE_COMMAND}" -E env "SWIG_LIB=${SWIG_DIR}" "${SWIG_EXECUTABLE}"
  474. "-${SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG}"
  475. "${swig_source_file_flags}"
  476. -outdir "${swig_file_outdir}"
  477. ${swig_special_flags}
  478. ${swig_extra_flags}
  479. "${swig_include_dirs}"
  480. -o "${swig_generated_file_fullname}"
  481. "${swig_source_file_fullname}"
  482. ${swig_copy_command}
  483. MAIN_DEPENDENCY "${swig_source_file_fullname}"
  484. DEPENDS ${swig_dependencies}
  485. IMPLICIT_DEPENDS CXX "${swig_source_file_fullname}"
  486. COMMENT "Swig compile ${infile} for ${SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG}"
  487. COMMAND_EXPAND_LISTS)
  488. set_source_files_properties("${swig_generated_file_fullname}" ${swig_extra_generated_files}
  489. PROPERTIES GENERATED 1)
  490. ## add all properties for generated file to various properties
  491. get_property (include_directories SOURCE "${infile}" PROPERTY GENERATED_INCLUDE_DIRECTORIES)
  492. set_property (SOURCE "${swig_generated_file_fullname}" PROPERTY INCLUDE_DIRECTORIES ${include_directories} $<TARGET_GENEX_EVAL:${target_name},$<TARGET_PROPERTY:${target_name},SWIG_GENERATED_INCLUDE_DIRECTORIES>>)
  493. get_property (compile_definitions SOURCE "${infile}" PROPERTY GENERATED_COMPILE_DEFINITIONS)
  494. set_property (SOURCE "${swig_generated_file_fullname}" PROPERTY COMPILE_DEFINITIONS $<TARGET_GENEX_EVAL:${target_name},$<TARGET_PROPERTY:${target_name},SWIG_GENERATED_COMPILE_DEFINITIONS>> ${compile_definitions})
  495. get_property (compile_options SOURCE "${infile}" PROPERTY GENERATED_COMPILE_OPTIONS)
  496. set_property (SOURCE "${swig_generated_file_fullname}" PROPERTY COMPILE_OPTIONS $<TARGET_GENEX_EVAL:${target_name},$<TARGET_PROPERTY:${target_name},SWIG_GENERATED_COMPILE_OPTIONS>> ${compile_options})
  497. if (SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG MATCHES "php")
  498. set_property (SOURCE "${swig_generated_file_fullname}" APPEND PROPERTY INCLUDE_DIRECTORIES "${outdir}")
  499. endif()
  500. set(${outfiles} "${swig_generated_file_fullname}" ${swig_extra_generated_files} PARENT_SCOPE)
  501. # legacy support
  502. set (swig_generated_file_fullname "${swig_generated_file_fullname}" PARENT_SCOPE)
  503. endfunction()
  504. #
  505. # Create Swig module
  506. #
  507. macro(SWIG_ADD_MODULE name language)
  508. message(DEPRECATION "SWIG_ADD_MODULE is deprecated. Use SWIG_ADD_LIBRARY instead.")
  509. swig_add_library(${name}
  510. LANGUAGE ${language}
  511. TYPE MODULE
  512. SOURCES ${ARGN})
  513. endmacro()
  514. function(SWIG_ADD_LIBRARY name)
  515. set(options NO_PROXY)
  516. set(oneValueArgs LANGUAGE
  517. TYPE
  518. OUTPUT_DIR
  519. OUTFILE_DIR)
  520. set(multiValueArgs SOURCES)
  521. cmake_parse_arguments(_SAM "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  522. if (_SAM_UNPARSED_ARGUMENTS)
  523. message(FATAL_ERROR "SWIG_ADD_LIBRARY: ${_SAM_UNPARSED_ARGUMENTS}: unexpected arguments")
  524. endif()
  525. if(NOT DEFINED _SAM_LANGUAGE)
  526. message(FATAL_ERROR "SWIG_ADD_LIBRARY: Missing LANGUAGE argument")
  527. endif()
  528. if(NOT DEFINED _SAM_SOURCES)
  529. message(FATAL_ERROR "SWIG_ADD_LIBRARY: Missing SOURCES argument")
  530. endif()
  531. if(NOT DEFINED _SAM_TYPE)
  532. set(_SAM_TYPE MODULE)
  533. elseif(_SAM_TYPE STREQUAL "USE_BUILD_SHARED_LIBS")
  534. unset(_SAM_TYPE)
  535. endif()
  536. cmake_policy(GET CMP0078 target_name_policy)
  537. if (target_name_policy STREQUAL "NEW")
  538. set (UseSWIG_TARGET_NAME_PREFERENCE STANDARD)
  539. else()
  540. if (NOT target_name_policy)
  541. cmake_policy(GET_WARNING CMP0078 _cmp0078_warning)
  542. message(AUTHOR_WARNING "${_cmp0078_warning}\n")
  543. endif()
  544. if (NOT DEFINED UseSWIG_TARGET_NAME_PREFERENCE)
  545. set (UseSWIG_TARGET_NAME_PREFERENCE LEGACY)
  546. elseif (NOT UseSWIG_TARGET_NAME_PREFERENCE MATCHES "^(LEGACY|STANDARD)$")
  547. message (FATAL_ERROR "UseSWIG_TARGET_NAME_PREFERENCE: ${UseSWIG_TARGET_NAME_PREFERENCE}: invalid value. 'LEGACY' or 'STANDARD' is expected.")
  548. endif()
  549. endif()
  550. if (NOT DEFINED UseSWIG_MODULE_VERSION)
  551. set (UseSWIG_MODULE_VERSION 1)
  552. elseif (NOT UseSWIG_MODULE_VERSION MATCHES "^(1|2)$")
  553. message (FATAL_ERROR "UseSWIG_MODULE_VERSION: ${UseSWIG_MODULE_VERSION}: invalid value. 1 or 2 is expected.")
  554. endif()
  555. set (SWIG_MODULE_${name}_NOPROXY ${_SAM_NO_PROXY})
  556. swig_module_initialize(${name} ${_SAM_LANGUAGE})
  557. # compute real target name.
  558. if (UseSWIG_TARGET_NAME_PREFERENCE STREQUAL "LEGACY" AND
  559. SWIG_MODULE_${name}_LANGUAGE STREQUAL "PYTHON" AND NOT SWIG_MODULE_${name}_NOPROXY)
  560. # swig will produce a module.py containing an 'import _modulename' statement,
  561. # which implies having a corresponding _modulename.so (*NIX), _modulename.pyd (Win32),
  562. # unless the -noproxy flag is used
  563. set(target_name "_${name}")
  564. else()
  565. set(target_name "${name}")
  566. endif()
  567. if (TARGET ${target_name})
  568. # a target with same name is already defined.
  569. # call NOW add_library command to raise the most useful error message
  570. add_library(${target_name})
  571. return()
  572. endif()
  573. set (workingdir "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${target_name}.dir")
  574. # set special variable to pass extra information to command SWIG_ADD_SOURCE_TO_MODULE
  575. # which cannot be changed due to legacy compatibility
  576. set (SWIG_WORKING_DIR "${workingdir}")
  577. set (SWIG_TARGET_NAME "${target_name}")
  578. set (outputdir "${_SAM_OUTPUT_DIR}")
  579. if (NOT _SAM_OUTPUT_DIR)
  580. if (CMAKE_SWIG_OUTDIR)
  581. set (outputdir "${CMAKE_SWIG_OUTDIR}")
  582. else()
  583. if (UseSWIG_MODULE_VERSION VERSION_GREATER 1)
  584. set (outputdir "${workingdir}/${_SAM_LANGUAGE}.files")
  585. else()
  586. set (outputdir "${CMAKE_CURRENT_BINARY_DIR}")
  587. endif()
  588. endif()
  589. endif()
  590. set (outfiledir "${_SAM_OUTFILE_DIR}")
  591. if(NOT _SAM_OUTFILE_DIR)
  592. if (SWIG_OUTFILE_DIR)
  593. set (outfiledir "${SWIG_OUTFILE_DIR}")
  594. else()
  595. if (_SAM_OUTPUT_DIR OR CMAKE_SWIG_OUTDIR)
  596. set (outfiledir "${outputdir}")
  597. else()
  598. set (outfiledir "${workingdir}")
  599. endif()
  600. endif()
  601. endif()
  602. # set again, locally, predefined variables to ensure compatibility
  603. # with command SWIG_ADD_SOURCE_TO_MODULE
  604. set(CMAKE_SWIG_OUTDIR "${outputdir}")
  605. set(SWIG_OUTFILE_DIR "${outfiledir}")
  606. # See if the user has specified source extensions for swig files?
  607. if (NOT DEFINED SWIG_SOURCE_FILE_EXTENSIONS)
  608. # Assume the default (*.i) file extension for Swig source files
  609. set(SWIG_SOURCE_FILE_EXTENSIONS ".i")
  610. endif()
  611. # Generate a regex out of file extensions.
  612. string(REGEX REPLACE "([$^.*+?|()-])" "\\\\\\1" swig_source_ext_regex "${SWIG_SOURCE_FILE_EXTENSIONS}")
  613. list (JOIN swig_source_ext_regex "|" swig_source_ext_regex)
  614. string (PREPEND swig_source_ext_regex "(")
  615. string (APPEND swig_source_ext_regex ")$")
  616. set(swig_dot_i_sources ${_SAM_SOURCES})
  617. list(FILTER swig_dot_i_sources INCLUDE REGEX ${swig_source_ext_regex})
  618. if (NOT swig_dot_i_sources)
  619. message(FATAL_ERROR "SWIG_ADD_LIBRARY: no SWIG interface files specified")
  620. endif()
  621. set(swig_other_sources ${_SAM_SOURCES})
  622. list(REMOVE_ITEM swig_other_sources ${swig_dot_i_sources})
  623. set(swig_generated_sources)
  624. set(swig_generated_timestamps)
  625. set(swig_generated_outdirs "${outputdir}")
  626. list(LENGTH swig_dot_i_sources swig_sources_count)
  627. if (swig_sources_count GREATER "1")
  628. # option -interface cannot be used
  629. set(SWIG_USE_INTERFACE FALSE)
  630. else()
  631. set(SWIG_USE_INTERFACE TRUE)
  632. endif()
  633. foreach(swig_it IN LISTS swig_dot_i_sources)
  634. SWIG_ADD_SOURCE_TO_MODULE(${name} swig_generated_source "${swig_it}")
  635. list (APPEND swig_generated_sources "${swig_generated_source}")
  636. if(CMAKE_GENERATOR MATCHES "Make")
  637. __swig_compute_timestamp(${name} ${SWIG_MODULE_${name}_LANGUAGE} "${swig_it}"
  638. "${workingdir}" swig_timestamp)
  639. list (APPEND swig_generated_timestamps "${swig_timestamp}")
  640. endif()
  641. get_source_file_property(swig_source_file_outdir "${swig_it}" OUTPUT_DIR)
  642. if (swig_source_file_outdir)
  643. list (APPEND swig_generated_outdirs "${swig_source_file_outdir}")
  644. endif()
  645. endforeach()
  646. list(REMOVE_DUPLICATES swig_generated_outdirs)
  647. set_property (DIRECTORY APPEND PROPERTY
  648. ADDITIONAL_CLEAN_FILES ${swig_generated_sources} ${swig_generated_timestamps})
  649. if (UseSWIG_MODULE_VERSION VERSION_GREATER 1)
  650. set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES ${swig_generated_outdirs})
  651. endif()
  652. add_library(${target_name}
  653. ${_SAM_TYPE}
  654. ${swig_generated_sources}
  655. ${swig_other_sources})
  656. if(CMAKE_GENERATOR MATCHES "Make")
  657. # see IMPLICIT_DEPENDS above
  658. add_custom_target(${name}_swig_compilation DEPENDS ${swig_generated_timestamps})
  659. add_dependencies(${target_name} ${name}_swig_compilation)
  660. endif()
  661. if(_SAM_TYPE STREQUAL "MODULE")
  662. set_target_properties(${target_name} PROPERTIES NO_SONAME ON)
  663. endif()
  664. string(TOLOWER "${_SAM_LANGUAGE}" swig_lowercase_language)
  665. if (swig_lowercase_language STREQUAL "octave")
  666. set_target_properties(${target_name} PROPERTIES PREFIX "")
  667. set_target_properties(${target_name} PROPERTIES SUFFIX ".oct")
  668. elseif (swig_lowercase_language STREQUAL "go")
  669. set_target_properties(${target_name} PROPERTIES PREFIX "")
  670. elseif (swig_lowercase_language STREQUAL "java")
  671. # In java you want:
  672. # System.loadLibrary("LIBRARY");
  673. # then JNI will look for a library whose name is platform dependent, namely
  674. # MacOS : libLIBRARY.jnilib
  675. # Windows: LIBRARY.dll
  676. # Linux : libLIBRARY.so
  677. if (APPLE)
  678. set_target_properties (${target_name} PROPERTIES SUFFIX ".jnilib")
  679. endif()
  680. if ((WIN32 AND MINGW) OR CYGWIN OR CMAKE_SYSTEM_NAME STREQUAL MSYS)
  681. set_target_properties(${target_name} PROPERTIES PREFIX "")
  682. endif()
  683. elseif (swig_lowercase_language STREQUAL "lua")
  684. if(_SAM_TYPE STREQUAL "MODULE")
  685. set_target_properties(${target_name} PROPERTIES PREFIX "")
  686. endif()
  687. elseif (swig_lowercase_language STREQUAL "python")
  688. if (UseSWIG_TARGET_NAME_PREFERENCE STREQUAL "STANDARD" AND NOT SWIG_MODULE_${name}_NOPROXY)
  689. # swig will produce a module.py containing an 'import _modulename' statement,
  690. # which implies having a corresponding _modulename.so (*NIX), _modulename.pyd (Win32),
  691. # unless the -noproxy flag is used
  692. set_target_properties(${target_name} PROPERTIES PREFIX "_")
  693. else()
  694. set_target_properties(${target_name} PROPERTIES PREFIX "")
  695. endif()
  696. # Python extension modules on Windows must have the extension ".pyd"
  697. # instead of ".dll" as of Python 2.5. Older python versions do support
  698. # this suffix.
  699. # http://docs.python.org/whatsnew/ports.html#SECTION0001510000000000000000
  700. # <quote>
  701. # Windows: .dll is no longer supported as a filename extension for extension modules.
  702. # .pyd is now the only filename extension that will be searched for.
  703. # </quote>
  704. if(WIN32 AND NOT CYGWIN)
  705. set_target_properties(${target_name} PROPERTIES SUFFIX ".pyd")
  706. endif()
  707. elseif (swig_lowercase_language STREQUAL "r")
  708. set_target_properties(${target_name} PROPERTIES PREFIX "")
  709. elseif (swig_lowercase_language STREQUAL "ruby")
  710. # In ruby you want:
  711. # require 'LIBRARY'
  712. # then ruby will look for a library whose name is platform dependent, namely
  713. # MacOS : LIBRARY.bundle
  714. # Windows: LIBRARY.dll
  715. # Linux : LIBRARY.so
  716. set_target_properties (${target_name} PROPERTIES PREFIX "")
  717. if (APPLE)
  718. set_target_properties (${target_name} PROPERTIES SUFFIX ".bundle")
  719. endif ()
  720. elseif (swig_lowercase_language STREQUAL "perl")
  721. # assume empty prefix because we expect the module to be dynamically loaded
  722. set_target_properties (${target_name} PROPERTIES PREFIX "")
  723. if (APPLE)
  724. set_target_properties (${target_name} PROPERTIES SUFFIX ".dylib")
  725. endif ()
  726. elseif (swig_lowercase_language STREQUAL "fortran")
  727. # Do *not* override the target's library prefix
  728. else()
  729. # assume empty prefix because we expect the module to be dynamically loaded
  730. set_target_properties (${target_name} PROPERTIES PREFIX "")
  731. endif ()
  732. # target property SWIG_SUPPORT_FILES_DIRECTORY specify output directories of support files
  733. set_property (TARGET ${target_name} PROPERTY SWIG_SUPPORT_FILES_DIRECTORY ${swig_generated_outdirs})
  734. # target property SWIG_SUPPORT_FILES lists principal proxy support files
  735. if (NOT SWIG_MODULE_${name}_NOPROXY)
  736. string(TOUPPER "${_SAM_LANGUAGE}" swig_uppercase_language)
  737. set(swig_all_support_files)
  738. foreach (swig_it IN LISTS SWIG_${swig_uppercase_language}_EXTRA_FILE_EXTENSIONS)
  739. set (swig_support_files ${swig_generated_sources})
  740. list (FILTER swig_support_files INCLUDE REGEX ".*${swig_it}$")
  741. list(APPEND swig_all_support_files ${swig_support_files})
  742. endforeach()
  743. if (swig_all_support_files)
  744. list(REMOVE_DUPLICATES swig_all_support_files)
  745. endif()
  746. set_property (TARGET ${target_name} PROPERTY SWIG_SUPPORT_FILES ${swig_all_support_files})
  747. endif()
  748. # to ensure legacy behavior, export some variables
  749. set (SWIG_MODULE_${name}_LANGUAGE "${SWIG_MODULE_${name}_LANGUAGE}" PARENT_SCOPE)
  750. set (SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG "${SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG}" PARENT_SCOPE)
  751. set (SWIG_MODULE_${name}_REAL_NAME "${target_name}" PARENT_SCOPE)
  752. set (SWIG_MODULE_${name}_NOPROXY "${SWIG_MODULE_${name}_NOPROXY}" PARENT_SCOPE)
  753. set (SWIG_MODULE_${name}_EXTRA_FLAGS "${SWIG_MODULE_${name}_EXTRA_FLAGS}" PARENT_SCOPE)
  754. # the last one is a bit crazy but it is documented, so...
  755. # NOTA: works as expected if only ONE input file is specified
  756. set (swig_generated_file_fullname "${swig_generated_file_fullname}" PARENT_SCOPE)
  757. endfunction()
  758. #
  759. # Like TARGET_LINK_LIBRARIES but for swig modules
  760. #
  761. function(SWIG_LINK_LIBRARIES name)
  762. if (UseSWIG_TARGET_NAME_PREFERENCE STREQUAL "STANDARD")
  763. message(DEPRECATION "SWIG_LINK_LIBRARIES is deprecated. Use TARGET_LINK_LIBRARIES instead.")
  764. target_link_libraries(${name} ${ARGN})
  765. else()
  766. if(SWIG_MODULE_${name}_REAL_NAME)
  767. target_link_libraries(${SWIG_MODULE_${name}_REAL_NAME} ${ARGN})
  768. else()
  769. message(SEND_ERROR "Cannot find Swig library \"${name}\".")
  770. endif()
  771. endif()
  772. endfunction()