@@ -47,7 +47,7 @@ module fpm_compiler
47
47
use tomlf, only: toml_table
48
48
use fpm_toml, only: serializable_t, set_string, set_value, toml_stat, get_value
49
49
use fpm_compile_commands, only: compile_command_t, compile_command_table_t
50
- use shlex_module, only: sh_split = > split, ms_split
50
+ use shlex_module, only: sh_split = > split, ms_split, quote = > ms_quote
51
51
implicit none
52
52
public :: compiler_t, new_compiler, archiver_t, new_archiver, get_macros
53
53
public :: append_clean_flags, append_clean_flags_array
@@ -103,6 +103,8 @@ module fpm_compiler
103
103
procedure :: get_feature_flag
104
104
! > Get flags for the main linking command
105
105
procedure :: get_main_flags
106
+ ! > Get library export flags
107
+ procedure :: get_export_flags
106
108
! > Compile a Fortran object
107
109
procedure :: compile_fortran
108
110
! > Compile a C object
@@ -122,6 +124,7 @@ module fpm_compiler
122
124
! > Enumerate libraries, based on compiler and platform
123
125
procedure :: enumerate_libraries
124
126
127
+
125
128
! > Serialization interface
126
129
procedure :: serializable_is_same = > compiler_is_same
127
130
procedure :: dump_to_toml = > compiler_dump
@@ -1070,6 +1073,50 @@ function enumerate_libraries(self, prefix, libs) result(r)
1070
1073
1071
1074
end function enumerate_libraries
1072
1075
1076
+ ! >
1077
+ ! > Generate library export flags for a shared library build
1078
+ ! >
1079
+ function get_export_flags (self , target_dir , target_name ) result(export_flags)
1080
+ ! > Instance of the compiler
1081
+ class(compiler_t), intent (in ) :: self
1082
+ ! > Path and package name
1083
+ character (len=* ), intent (in ) :: target_dir, target_name
1084
+ character (len= :), allocatable :: export_flags
1085
+
1086
+ character (len= :), allocatable :: implib_path, def_path
1087
+
1088
+ ! Only apply on Windows
1089
+ if (get_os_type() /= OS_WINDOWS) then
1090
+ export_flags = " "
1091
+ return
1092
+ end if
1093
+
1094
+ select case (self% id)
1095
+
1096
+ case (id_gcc, id_caf, id_f95)
1097
+ ! GNU-based: emit both import library and def file
1098
+ implib_path = quote (join_path(target_dir, target_name // " .dll.a" ) , for_cmd= .true. )
1099
+ def_path = quote (join_path(target_dir, target_name // " .def" ) , for_cmd= .true. )
1100
+
1101
+ export_flags = " -Wl,--out-implib," // implib_path // &
1102
+ " -Wl,--output-def," // def_path
1103
+
1104
+ case (id_intel_classic_windows, id_intel_llvm_windows)
1105
+ ! Intel/MSVC-style
1106
+ implib_path = quote (join_path(target_dir, target_name // " .lib" ) , for_cmd= .true. )
1107
+ def_path = quote (join_path(target_dir, target_name // " .def" ) , for_cmd= .true. )
1108
+
1109
+ export_flags = " /IMPLIB:" // implib_path // &
1110
+ " /DEF:" // def_path
1111
+
1112
+ case default
1113
+
1114
+ export_flags = " " ! Do nothing elsewhere
1115
+
1116
+ end select
1117
+
1118
+ end function get_export_flags
1119
+
1073
1120
! > Create new compiler instance
1074
1121
subroutine new_compiler (self , fc , cc , cxx , echo , verbose )
1075
1122
! > New instance of the compiler
0 commit comments