@@ -32,7 +32,7 @@ module fpm_targets
32
32
use fpm_filesystem, only: dirname, join_path, canon_path
33
33
use fpm_strings, only: string_t, operator (.in .), string_cat, fnv_1a, resize, lower, str_ends_with, &
34
34
add_strings
35
- use fpm_compiler, only: get_macros
35
+ use fpm_compiler, only: get_macros, is_cxx_gnu_based
36
36
use fpm_sources, only: get_exe_name_with_suffix
37
37
use fpm_manifest_library, only: library_config_t
38
38
use fpm_manifest_preprocess, only: preprocess_config_t
@@ -317,8 +317,8 @@ subroutine build_target_list(targets,model,library)
317
317
318
318
integer :: i, j, k, n_source, exe_type
319
319
character (:), allocatable :: exe_dir, compile_flags, lib_name
320
- logical :: with_lib, monolithic, shared_lib, static_lib
321
-
320
+ logical :: with_lib, monolithic, shared_lib, static_lib, clang_cxx_backend_macos
321
+
322
322
! Initialize targets
323
323
allocate (targets(0 ))
324
324
@@ -327,6 +327,12 @@ subroutine build_target_list(targets,model,library)
327
327
j= 1 ,size (model% packages))])
328
328
329
329
if (n_source < 1 ) return
330
+
331
+ if (get_os_type()==OS_MACOS) then
332
+ clang_cxx_backend_macos = .not. is_cxx_gnu_based(model% compiler% cxx)
333
+ else
334
+ clang_cxx_backend_macos = .false.
335
+ endif
330
336
331
337
with_lib = any (model% packages% has_library())
332
338
@@ -436,10 +442,12 @@ subroutine build_target_list(targets,model,library)
436
442
437
443
! > Add stdc++ as a linker flag. If not already there.
438
444
if (.not. (" stdc++" .in . model% link_libraries)) then
439
-
440
- if (get_os_type() == OS_MACOS) then
445
+
446
+ if (clang_cxx_backend_macos) then
447
+ ! On macOS with non-GNU C++ compiler (e.g., Clang), use "c++"
441
448
call add_strings(model% link_libraries, string_t(" c++" ))
442
449
else
450
+ ! For GNU C++ compiler or non-macOS systems, use "stdc++"
443
451
call add_strings(model% link_libraries, string_t(" stdc++" ))
444
452
end if
445
453
@@ -1010,7 +1018,7 @@ recursive subroutine collect_used_modules(target)
1010
1018
1011
1019
if (.not. (target % source% modules_provided(j)% s .in . modules_used)) then
1012
1020
1013
- modules_used = [ modules_used, target % source% modules_provided(j)]
1021
+ call add_strings( modules_used, target % source% modules_provided(j))
1014
1022
1015
1023
end if
1016
1024
@@ -1295,7 +1303,7 @@ recursive subroutine get_link_objects(link_objects,target,is_exe)
1295
1303
1296
1304
! Add dependency object file to link object list
1297
1305
temp_str% s = dep% output_file
1298
- link_objects = [ link_objects, temp_str]
1306
+ call add_strings( link_objects, temp_str)
1299
1307
1300
1308
! For executable objects, also need to include non-library
1301
1309
! dependencies from dependencies (recurse)
@@ -1324,7 +1332,7 @@ subroutine add_include_build_dirs(model, targets)
1324
1332
if (target % target_type /= FPM_TARGET_OBJECT) cycle
1325
1333
if (target % output_dir .in . build_dirs) cycle
1326
1334
temp% s = target % output_dir
1327
- build_dirs = [ build_dirs, temp]
1335
+ call add_strings( build_dirs, temp)
1328
1336
end associate
1329
1337
end do
1330
1338
@@ -1356,7 +1364,7 @@ subroutine get_library_dirs(model, targets, shared_lib_dirs)
1356
1364
if (all (target % target_type /= [FPM_TARGET_SHARED,FPM_TARGET_ARCHIVE])) cycle
1357
1365
if (target % output_dir .in . shared_lib_dirs) cycle
1358
1366
temp = string_t(target % output_dir)
1359
- shared_lib_dirs = [ shared_lib_dirs, temp]
1367
+ call add_strings( shared_lib_dirs, temp)
1360
1368
end associate
1361
1369
end do
1362
1370
0 commit comments