Skip to content

Commit 78656e7

Browse files
authored
Merge branch 'main' into flang_new_support
2 parents ae98019 + 265cbee commit 78656e7

22 files changed

+739
-182
lines changed

ci/run_tests.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,5 +344,27 @@ pushd static_app_only
344344
test $EXIT_CODE -eq 0
345345
popd
346346

347+
# Test custom module directory
348+
pushd custom_module_dir
349+
"$fpm" build
350+
rm -rf ./test_custom_install
351+
"$fpm" install --prefix ./test_custom_install
352+
# Verify modules are installed in custom directory
353+
test -f ./test_custom_install/custom_modules/greeting.mod
354+
test -f ./test_custom_install/custom_modules/math_utils.mod
355+
# Verify library is still installed normally
356+
test -f ./test_custom_install/lib/libcustom-module-dir.a
357+
# Clean up
358+
rm -rf ./test_custom_install
359+
popd
360+
361+
# Test both shared and static library types
362+
pushd both_lib_types
363+
"$fpm" build
364+
"$fpm" install --prefix=.
365+
# Check that exactly 2 libboth_lib_types library files were installed
366+
test $(ls lib/libboth_lib_types* | wc -l) -eq 2
367+
popd
368+
347369
# Cleanup
348370
rm -rf ./*/build
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name = "both_lib_types"
2+
library.type=["shared", "static"]
3+
install.library=true
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module both_lib_types
2+
implicit none
3+
private
4+
5+
public :: say_hello
6+
public :: get_number
7+
contains
8+
subroutine say_hello
9+
print *, "Hello from both_lib_types!"
10+
end subroutine say_hello
11+
12+
integer function get_number()
13+
get_number = 42
14+
end function get_number
15+
end module both_lib_types
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Custom Module Directory Example
2+
3+
This example demonstrates the use of a custom module directory in the `[install]` section of `fpm.toml`.
4+
5+
## Features
6+
7+
- Two simple Fortran modules: `greeting` and `math_utils`
8+
- Custom module installation directory specified as `custom_modules`
9+
- Shows how modules can be installed to a different location than headers
10+
11+
## Configuration
12+
13+
In `fpm.toml`:
14+
15+
```toml
16+
[install]
17+
library = true
18+
module-dir = "custom_modules"
19+
```
20+
21+
This configuration will install compiled `.mod` files to the `custom_modules` directory instead of the default `include` directory.
22+
23+
## Testing
24+
25+
To test this example:
26+
27+
```bash
28+
cd example_packages/custom_module_dir
29+
fpm build
30+
fpm install --prefix /tmp/test_install
31+
# Check that .mod files are in /tmp/test_install/custom_modules/
32+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name = "custom-module-dir"
2+
install.library = true
3+
install.module-dir = "custom_modules"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module greeting
2+
implicit none
3+
private
4+
public :: say_hello
5+
6+
contains
7+
8+
subroutine say_hello(name)
9+
character(len=*), intent(in) :: name
10+
print *, 'Hello, ' // name // '!'
11+
end subroutine say_hello
12+
13+
end module greeting
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module math_utils
2+
implicit none
3+
private
4+
public :: add_numbers, multiply_numbers
5+
6+
contains
7+
8+
function add_numbers(a, b) result(sum)
9+
integer, intent(in) :: a, b
10+
integer :: sum
11+
sum = a + b
12+
end function add_numbers
13+
14+
function multiply_numbers(a, b) result(product)
15+
integer, intent(in) :: a, b
16+
integer :: product
17+
product = a * b
18+
end function multiply_numbers
19+
20+
end module math_utils

src/fpm.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module fpm
99
use fpm_dependency, only : new_dependency_tree
1010
use fpm_filesystem, only: is_dir, join_path, list_files, exists, &
1111
basename, filewrite, mkdir, run, os_delete_dir, delete_file
12-
use fpm_model, only: fpm_model_t, srcfile_t, show_model, fortran_features_t, &
12+
use fpm_model, only: fpm_model_t, srcfile_t, show_model, &
1313
FPM_SCOPE_UNKNOWN, FPM_SCOPE_LIB, FPM_SCOPE_DEP, &
1414
FPM_SCOPE_APP, FPM_SCOPE_EXAMPLE, FPM_SCOPE_TEST
1515
use fpm_compiler, only: new_compiler, new_archiver, set_cpp_preprocessor_flags

src/fpm/cmd/install.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ subroutine cmd_install(settings)
6363

6464
call new_installer(installer, prefix=settings%prefix, &
6565
bindir=settings%bindir, libdir=settings%libdir, testdir=settings%testdir, &
66-
includedir=settings%includedir, &
66+
includedir=settings%includedir, moduledir=package%install%module_dir, &
6767
verbosity=merge(2, 1, settings%verbose))
6868

6969
if (allocated(package%library) .and. package%install%library) then
@@ -141,7 +141,7 @@ subroutine install_module_files(installer, targets, error)
141141
call filter_modules(targets, modules)
142142

143143
do ii = 1, size(modules)
144-
call installer%install_header(modules(ii)%s//".mod", error)
144+
call installer%install_module(modules(ii)%s//".mod", error)
145145
if (allocated(error)) exit
146146
end do
147147
if (allocated(error)) return

src/fpm/installer.f90

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ module fpm_installer
2727
character(len=:), allocatable :: testdir
2828
!> Include directory relative to the installation prefix
2929
character(len=:), allocatable :: includedir
30+
!> Module directory relative to the installation prefix
31+
character(len=:), allocatable :: moduledir
3032
!> Output unit for informative printout
3133
integer :: unit = output_unit
3234
!> Verbosity of the installer
@@ -46,6 +48,8 @@ module fpm_installer
4648
procedure :: install_library
4749
!> Install a header/module in its correct subdirectory
4850
procedure :: install_header
51+
!> Install a module in its correct subdirectory
52+
procedure :: install_module
4953
!> Install a test program in its correct subdirectory
5054
procedure :: install_test
5155
!> Install a generic file into a subdirectory in the installation prefix
@@ -69,6 +73,9 @@ module fpm_installer
6973
!> Default name of the include subdirectory
7074
character(len=*), parameter :: default_includedir = "include"
7175

76+
!> Default name of the module subdirectory
77+
character(len=*), parameter :: default_moduledir = "include"
78+
7279
!> Copy command on Unix platforms
7380
character(len=*), parameter :: default_copy_unix = "cp"
7481

@@ -90,7 +97,7 @@ module fpm_installer
9097
contains
9198

9299
!> Create a new instance of an installer
93-
subroutine new_installer(self, prefix, bindir, libdir, includedir, testdir, verbosity, &
100+
subroutine new_installer(self, prefix, bindir, libdir, includedir, moduledir, testdir, verbosity, &
94101
copy, move)
95102
!> Instance of the installer
96103
type(installer_t), intent(out) :: self
@@ -102,6 +109,8 @@ subroutine new_installer(self, prefix, bindir, libdir, includedir, testdir, verb
102109
character(len=*), intent(in), optional :: libdir
103110
!> Include directory relative to the installation prefix
104111
character(len=*), intent(in), optional :: includedir
112+
!> Module directory relative to the installation prefix
113+
character(len=*), intent(in), optional :: moduledir
105114
!> Test directory relative to the installation prefix
106115
character(len=*), intent(in), optional :: testdir
107116
!> Verbosity of the installer
@@ -139,6 +148,12 @@ subroutine new_installer(self, prefix, bindir, libdir, includedir, testdir, verb
139148
else
140149
self%includedir = default_includedir
141150
end if
151+
152+
if (present(moduledir)) then
153+
self%moduledir = moduledir
154+
else
155+
self%moduledir = default_moduledir
156+
end if
142157

143158
if (present(testdir)) then
144159
self%testdir = testdir
@@ -288,6 +303,18 @@ subroutine install_header(self, header, error)
288303
call self%install(header, self%includedir, error)
289304
end subroutine install_header
290305

306+
!> Install a module in its correct subdirectory
307+
subroutine install_module(self, module, error)
308+
!> Instance of the installer
309+
class(installer_t), intent(inout) :: self
310+
!> Path to the module
311+
character(len=*), intent(in) :: module
312+
!> Error handling
313+
type(error_t), allocatable, intent(out) :: error
314+
315+
call self%install(module, self%moduledir, error)
316+
end subroutine install_module
317+
291318
!> Install a generic file into a subdirectory in the installation prefix
292319
subroutine install(self, source, destination, error)
293320
!> Instance of the installer

0 commit comments

Comments
 (0)