From 8e10307aa515388ec4d7de0c679b31eca3961890 Mon Sep 17 00:00:00 2001 From: Milan Skocic Date: Fri, 14 Nov 2025 10:03:33 +0100 Subject: [PATCH 1/9] Add compile flags getters. Use get_debug_compile_flags and get_release_compile_flags for pulling the default flags instead of hard-coding them in features_collection.f90. --- src/fpm/manifest/feature_collection.f90 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fpm/manifest/feature_collection.f90 b/src/fpm/manifest/feature_collection.f90 index 280ff08b6a..7980125956 100644 --- a/src/fpm/manifest/feature_collection.f90 +++ b/src/fpm/manifest/feature_collection.f90 @@ -15,7 +15,8 @@ module fpm_manifest_feature_collection id_unknown, id_gcc, id_f95, id_caf, & id_intel_classic_nix, id_intel_classic_mac, id_intel_classic_windows, & id_intel_llvm_nix, id_intel_llvm_windows, id_intel_llvm_unknown, & - id_pgi, id_nvhpc, id_nag, id_flang, id_lahey, id_lfortran, id_all + id_pgi, id_nvhpc, id_nag, id_flang, id_lahey, id_lfortran, id_all, & + get_debug_compile_flags, get_release_compile_flags use fpm_strings, only: string_t, lower, operator(==), split, str use tomlf, only: toml_table, toml_array, toml_key, toml_stat use fpm_toml, only: get_value, len, serializable_t, set_value, set_string, set_list, add_table, & From 2f8ff388617d35cb34038964a18225b261f68d09 Mon Sep 17 00:00:00 2001 From: Milan Skocic Date: Fri, 14 Nov 2025 10:04:22 +0100 Subject: [PATCH 2/9] Do not use the hard-code compile flags. --- src/fpm/manifest/feature_collection.f90 | 1 - 1 file changed, 1 deletion(-) diff --git a/src/fpm/manifest/feature_collection.f90 b/src/fpm/manifest/feature_collection.f90 index 7980125956..150c37b559 100644 --- a/src/fpm/manifest/feature_collection.f90 +++ b/src/fpm/manifest/feature_collection.f90 @@ -922,7 +922,6 @@ function default_variant(name, compiler_id, os_type, flags) result(feature) feature%name = name feature%platform%compiler = compiler_id feature%platform%os_type = os_type - feature%flags = flags feature%default = .true. ! These are built-in features end function default_variant From cb7d15c0a222e999695e313e2e00d079e0aa3c6e Mon Sep 17 00:00:00 2001 From: Milan Skocic Date: Fri, 14 Nov 2025 10:05:00 +0100 Subject: [PATCH 3/9] Add FFLAGS pulled from getters defined in fpm_compiler.F90. --- src/fpm/manifest/feature_collection.f90 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/fpm/manifest/feature_collection.f90 b/src/fpm/manifest/feature_collection.f90 index 150c37b559..bf5e420173 100644 --- a/src/fpm/manifest/feature_collection.f90 +++ b/src/fpm/manifest/feature_collection.f90 @@ -923,6 +923,15 @@ function default_variant(name, compiler_id, os_type, flags) result(feature) feature%platform%compiler = compiler_id feature%platform%os_type = os_type feature%default = .true. ! These are built-in features + + ! FFLAGS + ! Default flags for debug + ! The argument flags is no more need + ! It is kept for backward compatibility + call get_debug_compile_flags(compiler_id, feature%flags) + + ! test if release is requested + if (name == "release") call get_release_compile_flags(compiler_id, feature%flags) end function default_variant From 353ec2372eb67af3710d1e9b09af224226d97487 Mon Sep 17 00:00:00 2001 From: Milan Skocic Date: Fri, 14 Nov 2025 10:06:36 +0100 Subject: [PATCH 4/9] Add CFLAGS hard-coded as fPIC only. A better solution would be to define getters for CFLAGS i.e. get_debug_compile_c_flags and get_release_compile_c_flags. Use them to pull the default flags for C sources. --- src/fpm/manifest/feature_collection.f90 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/fpm/manifest/feature_collection.f90 b/src/fpm/manifest/feature_collection.f90 index bf5e420173..44efc30dd4 100644 --- a/src/fpm/manifest/feature_collection.f90 +++ b/src/fpm/manifest/feature_collection.f90 @@ -932,6 +932,12 @@ function default_variant(name, compiler_id, os_type, flags) result(feature) ! test if release is requested if (name == "release") call get_release_compile_flags(compiler_id, feature%flags) + + ! CFLAGS + ! Equivalent function of get_debug/release_compile_flags must be implemented in fpm_compiler.F90 + ! Hot fix: hard-coded c_flags=-fPIC (especially needed for shared library) + feature%c_flags = "-fPIC" + end function default_variant From 7d21e7fdb37a2430fa2449cf1ac1c2aa11f474b8 Mon Sep 17 00:00:00 2001 From: Milan Skocic Date: Fri, 14 Nov 2025 10:08:12 +0100 Subject: [PATCH 5/9] Update comments for FFLAGS and CFLAGS in default_variant(). --- src/fpm/manifest/feature_collection.f90 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/fpm/manifest/feature_collection.f90 b/src/fpm/manifest/feature_collection.f90 index 44efc30dd4..7db5d4d2f1 100644 --- a/src/fpm/manifest/feature_collection.f90 +++ b/src/fpm/manifest/feature_collection.f90 @@ -925,9 +925,10 @@ function default_variant(name, compiler_id, os_type, flags) result(feature) feature%default = .true. ! These are built-in features ! FFLAGS - ! Default flags for debug - ! The argument flags is no more need - ! It is kept for backward compatibility + ! The argument flags is no more needed but it is kept for backward compatibility + ! flags are hard-coded in default_release/debug_feature + ! It might better to be pulled from default compile flags defined in fpm_compiler.F90 + ! TODO: Validate this change call get_debug_compile_flags(compiler_id, feature%flags) ! test if release is requested @@ -936,6 +937,7 @@ function default_variant(name, compiler_id, os_type, flags) result(feature) ! CFLAGS ! Equivalent function of get_debug/release_compile_flags must be implemented in fpm_compiler.F90 ! Hot fix: hard-coded c_flags=-fPIC (especially needed for shared library) + ! TODO: Validate this change feature%c_flags = "-fPIC" end function default_variant From 9123a657d82162877564c8f07711c07d42b856c2 Mon Sep 17 00:00:00 2001 From: Milan Skocic Date: Sat, 15 Nov 2025 18:50:45 +0100 Subject: [PATCH 6/9] Remove imports from fpm_compiler.F90. Imports not needed for now. They will be necessary if a solution by using functions defined in the module `fpm_compiler.F90` is decided. --- src/fpm/manifest/feature_collection.f90 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/fpm/manifest/feature_collection.f90 b/src/fpm/manifest/feature_collection.f90 index 7db5d4d2f1..80b24588d6 100644 --- a/src/fpm/manifest/feature_collection.f90 +++ b/src/fpm/manifest/feature_collection.f90 @@ -15,8 +15,7 @@ module fpm_manifest_feature_collection id_unknown, id_gcc, id_f95, id_caf, & id_intel_classic_nix, id_intel_classic_mac, id_intel_classic_windows, & id_intel_llvm_nix, id_intel_llvm_windows, id_intel_llvm_unknown, & - id_pgi, id_nvhpc, id_nag, id_flang, id_lahey, id_lfortran, id_all, & - get_debug_compile_flags, get_release_compile_flags + id_pgi, id_nvhpc, id_nag, id_flang, id_lahey, id_lfortran, id_all use fpm_strings, only: string_t, lower, operator(==), split, str use tomlf, only: toml_table, toml_array, toml_key, toml_stat use fpm_toml, only: get_value, len, serializable_t, set_value, set_string, set_list, add_table, & From f237efd1d1d32c6389c06a2de4c57a982175ea43 Mon Sep 17 00:00:00 2001 From: Milan Skocic Date: Sat, 15 Nov 2025 18:54:43 +0100 Subject: [PATCH 7/9] Add c_flags and cxx_flags for the different variants (debug). All variants, except those for OS_WINDOWS, will accept the -fPIC flag for C/C++ sources. A more complete set of flags for C/C++ sources was added for the gcc compiler. For the other compilers, additional work might be needed to define the correct flags mathcing those passed for Fortran sources. --- src/fpm/manifest/feature_collection.f90 | 26 ++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/fpm/manifest/feature_collection.f90 b/src/fpm/manifest/feature_collection.f90 index 80b24588d6..4df83b19f8 100644 --- a/src/fpm/manifest/feature_collection.f90 +++ b/src/fpm/manifest/feature_collection.f90 @@ -813,35 +813,47 @@ function default_debug_feature() result(collection) call collection%push_variant(default_variant('debug', id_caf, OS_ALL, & ' -Wall -Wextra -Wimplicit-interface -Wno-external-argument-mismatch& & -fPIC -fmax-errors=1 -g -fcheck=bounds& - & -fcheck=array-temps -fbacktrace')) + & -fcheck=array-temps -fbacktrace', & + ' -fPIC', & + ' -fPIC')) call collection%push_variant(default_variant('debug', id_gcc, OS_ALL, & ' -Wall -Wextra -Wimplicit-interface -Wno-external-argument-mismatch& & -fPIC -fmax-errors=1 -g -fcheck=bounds& - & -fcheck=array-temps -fbacktrace -fcoarray=single')) + & -fcheck=array-temps -fbacktrace -fcoarray=single', & + ' -Wall -Wextra -fPIC -fmax-errors=1 -g', & + ' -Wall -Wextra -fPIC -fmax-errors=1 -g')) call collection%push_variant(default_variant('debug', id_f95, OS_ALL, & ' -Wall -Wextra -Wimplicit-interface -Wno-external-argument-mismatch& & -fPIC -fmax-errors=1 -g -fcheck=bounds& - & -fcheck=array-temps -Wno-maybe-uninitialized -Wno-uninitialized -fbacktrace')) + & -fcheck=array-temps -Wno-maybe-uninitialized -Wno-uninitialized -fbacktrace', & + ' -fPIC', & + ' -fPIC')) call collection%push_variant(default_variant('debug', id_nvhpc, OS_ALL, & - ' -Minform=inform -Mbackslash -g -Mbounds -Mchkptr -Mchkstk -traceback')) + ' -Minform=inform -Mbackslash -g -Mbounds -Mchkptr -Mchkstk -traceback', & + ' -fPIC', & + ' -fPIC')) call collection%push_variant(default_variant('debug', id_intel_classic_nix, OS_ALL, & - ' -warn all -check all -error-limit 1 -O0 -g -assume byterecl -traceback')) + ' -warn all -check all -error-limit 1 -O0 -g -assume byterecl -traceback', & + ' -fPIC', & + ' -fPIC')) call collection%push_variant(default_variant('debug', id_intel_classic_nix, OS_WINDOWS, & ' /warn:all /check:all /error-limit:1& & /Od /Z7 /assume:byterecl /traceback')) call collection%push_variant(default_variant('debug', id_intel_llvm_nix, OS_ALL, & - ' -warn all -check all -error-limit 1 -O0 -g -assume byterecl -traceback')) + ' -warn all -check all -error-limit 1 -O0 -g -assume byterecl -traceback', & + ' -fPIC', & + ' -fPIC')) call collection%push_variant(default_variant('debug', id_intel_llvm_nix, OS_WINDOWS, & ' /warn:all /check:all /error-limit:1 /Od /Z7 /assume:byterecl')) - call collection%push_variant(default_variant('debug', id_lfortran, OS_ALL, '')) + call collection%push_variant(default_variant('debug', id_lfortran, OS_ALL, '', ' -fPIC', ' -fPIC')) end function default_debug_feature From 2cc45714e44a8bf342610e7f345c7c09a35e186a Mon Sep 17 00:00:00 2001 From: Milan Skocic Date: Sat, 15 Nov 2025 18:55:14 +0100 Subject: [PATCH 8/9] Add c_flags and cxx_flags for the different variants (release). All variants, except those for OS_WINDOWS, will accept the -fPIC flag for C/C++ sources. A more complete set of flags for C/C++ sources was added for the gcc compiler. For the other compilers, additional work might be needed to define the correct flags mathcing those passed for Fortran sources. --- src/fpm/manifest/feature_collection.f90 | 34 ++++++++++++++++++------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/fpm/manifest/feature_collection.f90 b/src/fpm/manifest/feature_collection.f90 index 4df83b19f8..3b93dc5022 100644 --- a/src/fpm/manifest/feature_collection.f90 +++ b/src/fpm/manifest/feature_collection.f90 @@ -869,20 +869,30 @@ function default_release_feature() result(collection) ! Add release variants for different compilers call collection%push_variant(default_variant('release', id_caf, OS_ALL, & - ' -O3 -Wimplicit-interface -fPIC -fmax-errors=1 -funroll-loops')) + ' -O3 -Wimplicit-interface -fPIC -fmax-errors=1 -funroll-loops', & + ' -fPIC', & + ' -fPIC')) call collection%push_variant(default_variant('release', id_gcc, OS_ALL, & - ' -O3 -Wimplicit-interface -fPIC -fmax-errors=1 -funroll-loops -fcoarray=single')) + ' -O3 -Wimplicit-interface -fPIC -fmax-errors=1 -funroll-loops -fcoarray=single', & + ' -O3 -fPIC -fmax-errors=1 -funroll-loops', & + ' -O3 -fPIC -fmax-errors=1 -funroll-loops')) call collection%push_variant(default_variant('release', id_f95, OS_ALL, & - ' -O3 -Wimplicit-interface -fPIC -fmax-errors=1 -ffast-math -funroll-loops')) + ' -O3 -Wimplicit-interface -fPIC -fmax-errors=1 -ffast-math -funroll-loops', & + ' -fPIC', & + ' -fPIC')) call collection%push_variant(default_variant('release', id_nvhpc, OS_ALL, & - ' -Mbackslash')) + ' -Mbackslash', & + ' -fPIC', & + ' -fPIC')) call collection%push_variant(default_variant('release', id_intel_classic_nix, OS_LINUX, & ' -fp-model precise -pc64 -align all -error-limit 1 -reentrancy& - & threaded -nogen-interfaces -assume byterecl')) + & threaded -nogen-interfaces -assume byterecl', & + ' -fPIC', & + ' -fPIC')) call collection%push_variant(default_variant('release', id_intel_classic_windows, & OS_WINDOWS, ' /fp:precise /align:all /error-limit:1 /reentrancy:threaded& @@ -890,17 +900,23 @@ function default_release_feature() result(collection) call collection%push_variant(default_variant('release', id_intel_llvm_nix, & OS_LINUX, ' -fp-model=precise -pc64 -align all -error-limit 1 -reentrancy threaded& - & -nogen-interfaces -assume byterecl')) + & -nogen-interfaces -assume byterecl', & + ' -fPIC', & + ' -fPIC')) call collection%push_variant(default_variant('release', id_intel_llvm_nix, & OS_WINDOWS, ' /fp:precise /align:all /error-limit:1 /reentrancy:threaded& & /nogen-interfaces /assume:byterecl')) - + call collection%push_variant(default_variant('release', id_nag, OS_ALL, & - ' -O4 -coarray=single -PIC')) + ' -O4 -coarray=single -PIC', & + ' -fPIC', & + ' -fPIC')) call collection%push_variant(default_variant('release', id_lfortran, OS_ALL, & - ' flag_lfortran_opt')) + ' flag_lfortran_opt', & + ' -fPIC', & + ' -fPIC')) end function default_release_feature From 31be9615677c080450341fac340647f16cb6c37f Mon Sep 17 00:00:00 2001 From: Milan Skocic Date: Sat, 15 Nov 2025 19:08:24 +0100 Subject: [PATCH 9/9] Generalize the function default_variant for accepting C/C++ flags. The argument flags was made optional and 2 additional optional arguments were added i.e. c_flags and cxx_flags. The default values for featture%flags, feature%c_flags and feature%cxx_flags were set to an empty string. The latter are set if the respective optional arguments are defined. flags, c_flags and cxx_flags are set from the callers default_release_feature and default_debug_feature. This way there won't be backward compatibility as the flags were already defined in the callers. For now, the c_flags and cxx_flags are limited to the fPIC flag necessary for the shared libraries except for the variant with the gcc compiler where equivalent c_flags to flags were defined. More work is needed to complete the set of c_flags and cxx_flags for other variants. --- src/fpm/manifest/feature_collection.f90 | 33 ++++++++++++------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/fpm/manifest/feature_collection.f90 b/src/fpm/manifest/feature_collection.f90 index 3b93dc5022..dba6c3ca75 100644 --- a/src/fpm/manifest/feature_collection.f90 +++ b/src/fpm/manifest/feature_collection.f90 @@ -939,33 +939,32 @@ subroutine get_default_features(collections, error) end subroutine get_default_features !> Helper to create a feature variant - function default_variant(name, compiler_id, os_type, flags) result(feature) + function default_variant(name, compiler_id, os_type, flags, c_flags, cxx_flags) result(feature) character(len=*), intent(in) :: name integer(compiler_enum), intent(in) :: compiler_id integer, intent(in) :: os_type - character(len=*), intent(in) :: flags + character(len=*), optional, intent(in) :: flags + character(len=*), optional, intent(in) :: c_flags + character(len=*), optional, intent(in) :: cxx_flags type(feature_config_t) :: feature feature%name = name feature%platform%compiler = compiler_id feature%platform%os_type = os_type feature%default = .true. ! These are built-in features + feature%flags = "" + feature%c_flags = "" + feature%cxx_flags = "" - ! FFLAGS - ! The argument flags is no more needed but it is kept for backward compatibility - ! flags are hard-coded in default_release/debug_feature - ! It might better to be pulled from default compile flags defined in fpm_compiler.F90 - ! TODO: Validate this change - call get_debug_compile_flags(compiler_id, feature%flags) - - ! test if release is requested - if (name == "release") call get_release_compile_flags(compiler_id, feature%flags) - - ! CFLAGS - ! Equivalent function of get_debug/release_compile_flags must be implemented in fpm_compiler.F90 - ! Hot fix: hard-coded c_flags=-fPIC (especially needed for shared library) - ! TODO: Validate this change - feature%c_flags = "-fPIC" + if (present(flags)) then + feature%flags = flags + end if + if (present(c_flags)) then + feature%c_flags = c_flags + end if + if (present(cxx_flags)) then + feature%cxx_flags = cxx_flags + end if end function default_variant