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