@@ -234,15 +234,31 @@ as well as ``SWIG``:
234
234
set(SWIG_SOURCE_FILE_EXTENSIONS ".i" ".swg")
235
235
#]=======================================================================]
236
236
237
+ if (CMAKE_VERSION GREATER_EQUAL 3.13)
238
+ cmake_policy (GET CMP0078 target_name_policy)
239
+ endif ()
240
+ if (CMAKE_VERSION GREATER_EQUAL 3.14)
241
+ cmake_policy (GET CMP0086 module_name_policy)
242
+ endif ()
243
+
237
244
cmake_policy (VERSION 3.12)
245
+ if (target_name_policy)
246
+ # respect user choice regarding CMP0078 policy
247
+ cmake_policy (SET CMP0078 ${target_name_policy} )
248
+ endif ()
249
+ if (module_name_policy)
250
+ # respect user choice regarding CMP0086 policy
251
+ cmake_policy (SET CMP0086 ${module_name_policy} )
252
+ endif ()
253
+ unset (target_name_policy)
254
+ unset (module_name_policy)
238
255
239
256
set (SWIG_CXX_EXTENSION "cxx" )
240
257
set (SWIG_EXTRA_LIBRARIES "" )
241
258
242
259
set (SWIG_PYTHON_EXTRA_FILE_EXTENSIONS ".py" )
243
260
set (SWIG_JAVA_EXTRA_FILE_EXTENSIONS ".java" "JNI.java" )
244
261
set (SWIG_CSHARP_EXTRA_FILE_EXTENSIONS ".cs" "PINVOKE.cs" )
245
- set (SWIG_FORTRAN_EXTRA_FILE_EXTENSIONS ".f90" )
246
262
247
263
set (SWIG_MANAGE_SUPPORT_FILES_SCRIPT "${CMAKE_CURRENT_LIST_DIR} /UseSWIG/ManageSupportFiles.cmake" )
248
264
@@ -322,15 +338,30 @@ function(SWIG_GET_EXTRA_OUTPUT_FILES language outfiles generatedpath infile)
322
338
set (extra_file "${generatedpath} /${module_basename}${it} " )
323
339
if (extra_file MATCHES "\\ .cs$" AND CMAKE_CSharp_COMPILER_LOADED)
324
340
set_source_files_properties (${extra_file} PROPERTIES LANGUAGE "CSharp" )
325
- elseif (extra_file MATCHES "\\ .f90$" AND CMAKE_Fortran_COMPILER_LOADED)
326
- set_source_files_properties (${extra_file} PROPERTIES LANGUAGE "Fortran" )
327
341
else ()
328
342
# Treat extra outputs as plain files regardless of language.
329
343
set_source_files_properties (${extra_file} PROPERTIES LANGUAGE "" )
330
344
endif ()
331
345
list (APPEND files "${extra_file} " )
332
346
endforeach ()
333
347
348
+ if (language STREQUAL "FORTRAN" AND CMAKE_Fortran_COMPILER_LOADED)
349
+ # Process possible user-supplied extension in flags (obtained via parent
350
+ # scope variable) to determine the source file name.
351
+ list (FIND SWIG_COMPILATION_FLAGS "-fext" fext_idx)
352
+ if (fext_idx EQUAL -1)
353
+ # Default Fortran generated extension
354
+ set (fext "f90" )
355
+ else ()
356
+ # Get extension from user-provided flag
357
+ math (EXPR fext_idx "${fext_idx} + 1" )
358
+ list (GET SWIG_COMPILATION_FLAGS "${fext_idx} " fext)
359
+ endif ()
360
+ set (extra_file "${generatedpath} /${module_basename} .${fext} " )
361
+ set_source_files_properties ("${extra_file} " PROPERTIES LANGUAGE "Fortran" )
362
+ list (APPEND files "${extra_file} " )
363
+ endif ()
364
+
334
365
set (${outfiles} ${files} PARENT_SCOPE)
335
366
endfunction ()
336
367
@@ -405,6 +436,7 @@ function(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile)
405
436
get_filename_component (swig_source_file_fullname "${infile} " ABSOLUTE )
406
437
407
438
if (NOT SWIG_MODULE_${name} _NOPROXY)
439
+ set (SWIG_COMPILATION_FLAGS ${swig_source_file_flags} )
408
440
SWIG_GET_EXTRA_OUTPUT_FILES(${SWIG_MODULE_${name} _LANGUAGE}
409
441
swig_extra_generated_files
410
442
"${outdir} "
@@ -438,20 +470,39 @@ function(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile)
438
470
list (APPEND swig_special_flags "-c++" )
439
471
endif ()
440
472
441
- set (module_name_policy "NEW" )
473
+
474
+ if (CMAKE_VERSION GREATER_EQUAL 3.14)
475
+ cmake_policy (GET CMP0086 module_name_policy)
476
+ elseif (FLIBCPP_CMP0086)
477
+ set (module_name_policy ${FLIBCPP_CMP0086} )
478
+ else ()
479
+ set (module_name_policy OLD)
480
+ endif ()
442
481
if (module_name_policy STREQUAL "NEW" )
443
482
get_source_file_property (module_name "${infile} " SWIG_MODULE_NAME)
444
483
if (module_name)
445
484
list (APPEND swig_special_flags "-module" "${module_name} " )
446
485
endif ()
486
+ else ()
487
+ if (NOT module_name_policy)
488
+ cmake_policy (GET_WARNING CMP0086 _cmp0086_warning)
489
+ message (AUTHOR_WARNING "${_cmp0086_warning} \n " )
490
+ endif ()
447
491
endif ()
448
492
449
493
set (swig_extra_flags)
450
494
if (SWIG_MODULE_${name} _LANGUAGE STREQUAL "CSHARP" )
451
495
if (NOT ("-dllimport" IN_LIST swig_source_file_flags OR "-dllimport" IN_LIST SWIG_MODULE_${name} _EXTRA_FLAGS))
452
496
# This makes sure that the name used in the generated DllImport
453
497
# matches the library name created by CMake
454
- list (APPEND SWIG_MODULE_${name} _EXTRA_FLAGS "-dllimport" "${name} " )
498
+ list (APPEND SWIG_MODULE_${name} _EXTRA_FLAGS "-dllimport" "$<TARGET_FILE_PREFIX:${target_name} >$<TARGET_FILE_BASE_NAME:${target_name} >" )
499
+ endif ()
500
+ endif ()
501
+ if (SWIG_MODULE_${name} _LANGUAGE STREQUAL "PYTHON" AND NOT SWIG_MODULE_${name} _NOPROXY)
502
+ if (NOT ("-interface" IN_LIST swig_source_file_flags OR "-interface" IN_LIST SWIG_MODULE_${name} _EXTRA_FLAGS))
503
+ # This makes sure that the name used in the proxy code
504
+ # matches the library name created by CMake
505
+ list (APPEND SWIG_MODULE_${name} _EXTRA_FLAGS "-interface" "$<TARGET_FILE_PREFIX:${target_name} >$<TARGET_FILE_BASE_NAME:${target_name} >" )
455
506
endif ()
456
507
endif ()
457
508
list (APPEND swig_extra_flags ${SWIG_MODULE_${name} _EXTRA_FLAGS})
@@ -576,11 +627,18 @@ function(SWIG_ADD_LIBRARY name)
576
627
unset (_SAM_TYPE)
577
628
endif ()
578
629
579
- set (target_name_policy "NEW" )
630
+ if (CMAKE_VERSION GREATER_EQUAL 3.13)
631
+ cmake_policy (GET CMP0078 target_name_policy)
632
+ elseif (FLIBCPP_CMP0078)
633
+ set (target_name_policy ${FLIBCPP_CMP0078} )
634
+ else ()
635
+ set (target_name_policy OLD)
636
+ endif ()
580
637
if (target_name_policy STREQUAL "NEW" )
581
638
set (UseSWIG_TARGET_NAME_PREFERENCE STANDARD)
582
639
else ()
583
640
if (NOT target_name_policy)
641
+ cmake_policy (GET_WARNING CMP0078 _cmp0078_warning)
584
642
message (AUTHOR_WARNING "${_cmp0078_warning} \n " )
585
643
endif ()
586
644
if (NOT DEFINED UseSWIG_TARGET_NAME_PREFERENCE)
@@ -685,9 +743,9 @@ function(SWIG_ADD_LIBRARY name)
685
743
endif ()
686
744
endforeach ()
687
745
set_property (DIRECTORY APPEND PROPERTY
688
- ADDITIONAL_MAKE_CLEAN_FILES ${swig_generated_sources} ${swig_generated_timestamps} )
746
+ ADDITIONAL_CLEAN_FILES ${swig_generated_sources} ${swig_generated_timestamps} )
689
747
if (UseSWIG_MODULE_VERSION VERSION_GREATER 1)
690
- set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${outputdir} " )
748
+ set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES "${outputdir} " )
691
749
endif ()
692
750
693
751
add_library (${target_name}
@@ -706,8 +764,6 @@ function(SWIG_ADD_LIBRARY name)
706
764
if (swig_lowercase_language STREQUAL "octave" )
707
765
set_target_properties (${target_name} PROPERTIES PREFIX "" )
708
766
set_target_properties (${target_name} PROPERTIES SUFFIX ".oct" )
709
- elseif (swig_lowercase_language STREQUAL "fortran" )
710
- # XXX
711
767
elseif (swig_lowercase_language STREQUAL "go" )
712
768
set_target_properties (${target_name} PROPERTIES PREFIX "" )
713
769
elseif (swig_lowercase_language STREQUAL "java" )
@@ -766,6 +822,8 @@ function(SWIG_ADD_LIBRARY name)
766
822
if (APPLE )
767
823
set_target_properties (${target_name} PROPERTIES SUFFIX ".dylib" )
768
824
endif ()
825
+ elseif (swig_lowercase_language STREQUAL "fortran" )
826
+ # Do *not* override the target's library prefix
769
827
else ()
770
828
# assume empty prefix because we expect the module to be dynamically loaded
771
829
set_target_properties (${target_name} PROPERTIES PREFIX "" )
0 commit comments