@@ -532,3 +532,133 @@ ar: creating build/debug/library/math_constants.a
532
532
# gfortran (for build/debug/test/runTests)
533
533
sin(pi) = 1.2246467991473532E-016
534
534
```
535
+
536
+ ### Adding Dependencies
537
+
538
+ Inevitably you'll want to be able to include other libraries in your project.
539
+ fpm makes this incredibly simple, by taking care of fetching and compiling your
540
+ dependencies for you. You just tell it what your dependencies are, and where to
541
+ find them. Let's add a dependency to our library. Now our ` fpm.toml ` file looks
542
+ like this:
543
+
544
+ ``` toml
545
+ name = " math_constants"
546
+ version = " 0.1.0"
547
+ license = " MIT"
548
+ author = " Jane Programmer"
549
+
550
+ copyright = " 2020 Jane Programmer"
551
+
552
+ [library ]
553
+ source-dir =" src"
554
+
555
+ [dependencies ]
556
+ helloff = { git = " https://gitlab.com/everythingfunctional/helloff.git" }
557
+
558
+ [[executable ]]
559
+ name =" math_constants"
560
+ source-dir =" app"
561
+ main =" main.f90"
562
+
563
+ [[test ]]
564
+ name =" runTests"
565
+ source-dir =" test"
566
+ main =" main.f90"
567
+ ```
568
+
569
+ Now you can use any modules from this library anywhere in your code. Just like
570
+ this:
571
+
572
+ ``` fortran
573
+ program demo
574
+ use helloff, only: create_greeting
575
+ use math_constants, only: e, pi, half_pi, two_pi
576
+ print *, 'math_constants library demo'
577
+ print *, 'pi = ', pi
578
+ print *, '2*pi = ', two_pi
579
+ print *, 'pi/2 = ', half_pi
580
+ print *, 'e = ', e
581
+ print *, create_greeting("fpm")
582
+ end program demo
583
+ ```
584
+
585
+ And now ` fpm run ` will output the following:
586
+
587
+ ```
588
+ math_constants library demo
589
+ pi = 3.1415926535897931
590
+ 2*pi = 6.2831853071795862
591
+ pi/2 = 1.5707963267948966
592
+ e = 2.7182818284590451
593
+ Hello, fpm!
594
+ ```
595
+
596
+ Additionally, any users of your library will now automatically depend on your
597
+ dependencies too. So if you don't need that depedency for the library, like in
598
+ the above example, then you can specify it for the specific executable like
599
+ below. Then fpm will still fetch and compile it when building your executable,
600
+ but users of your library won't have to.
601
+
602
+ ``` toml
603
+ name = " math_constants"
604
+ version = " 0.1.0"
605
+ license = " MIT"
606
+ author = " Jane Programmer"
607
+
608
+ copyright = " 2020 Jane Programmer"
609
+
610
+ [library ]
611
+ source-dir =" src"
612
+
613
+ [[executable ]]
614
+ name =" math_constants"
615
+ source-dir =" app"
616
+ main =" main.f90"
617
+ [executable .dependencies ]
618
+ helloff = { git = " https://gitlab.com/everythingfunctional/helloff.git" }
619
+
620
+
621
+ [[test ]]
622
+ name =" runTests"
623
+ source-dir =" test"
624
+ main =" main.f90"
625
+ ```
626
+
627
+ You can also specify dependencies for your tests in a similar way, with
628
+ ` [test.dependencies] ` instead of ` [executable.dependencies] ` . There's also
629
+ another option for test dependencies. The below example makes the dependencies
630
+ available for all the tests, but again your users won't depend on these.
631
+
632
+ ``` toml
633
+ name = " math_constants"
634
+ version = " 0.1.0"
635
+ license = " MIT"
636
+ author = " Jane Programmer"
637
+
638
+ copyright = " 2020 Jane Programmer"
639
+
640
+ [library ]
641
+ source-dir =" src"
642
+
643
+ [dev-dependencies ]
644
+ helloff = { git = " https://gitlab.com/everythingfunctional/helloff.git" }
645
+
646
+ [[executable ]]
647
+ name =" math_constants"
648
+ source-dir =" app"
649
+ main =" main.f90"
650
+
651
+ [[test ]]
652
+ name =" runTests"
653
+ source-dir =" test"
654
+ main =" main.f90"
655
+ ```
656
+
657
+ You can also be specific about which version of a dependency you'd like. You can
658
+ specify a branch to use like ` helloff = { git = "https://gitlab.com/everythingfunctional/helloff.git", branch = "master" } ` ,
659
+ or a tag like ` helloff = { git = "https://gitlab.com/everythingfunctional/helloff.git", tag = "v1.2.3" } ` ,
660
+ or even a specific commit like ` helloff = { git = "https://gitlab.com/everythingfunctional/helloff.git", rev = "a1b2c3" } ` .
661
+ You can even specify the path to another folder, if for example you've got another
662
+ fpm package in the same repository. Like this: ` helloff = { path = "helloff" } ` .
663
+ Note that you should * not* specify paths outside of your repository, or things
664
+ won't work for your users.
0 commit comments