Fpm usage for already-written code

I’d like to know how to run the already-written code with fpm.

The link
https://fpm.fortran-lang.org/en/tutorial/hello-fpm.html

only demonstrates how to start a new project with fpm

The second question is related to this output

What does the tree represent in the upper link? It does not look like a command here!

I am using Windows OS.

Are you using MSYS2? If so, you can install the tree utility by running

pacman -S tree
1 Like

For already existing projects you will need to define a fpm.toml with all the location of your source files. That might not necessarily play nice with your existing project structure.

You might want to have a look at one of my open source repos that takes an existing repo and repackages it for fpm

If you have your source files under src it’s probably going to be a lot easier to build with fpm. The thing that you will probably miss is defining a set of compile flags, but we are in the process of getting that working in a future release.

1 Like

Thank you for the link; I’ll look into it. However, it does not appear to be simple.

In many cases I start with “fpm new DIRNAME” or “fpm new . --backfill” in an existing directory. Without seeing your original file structure I am not positive that is better than manually creating the subdirectories, etc. I have found it simplest in most cases to start that way. I am curious why you did not use “fpm new” as it might point towards ways to improve that subcommand.

1 Like

main.f90 is the program and the rest are all modules.

So how do I work with it?

If there are no other restrictions, change to the directory, backfill it, move the files into the expected locations and run, like this:

cd $TO_THE_DIRECTORY
fpm new . --backfill
mv main.f90 app/
mv *mod.f90 src/
fpm run

Those are the ULS (Unix-Like Systems) commands; but the only thing that would vary would be the move commands; which have to be OS-specific.

It is working fine now

but seems like fpm is a bit slower

Try with

$ fpm run <myprogram> --profile release

The meaning is the following:

 --profile PROF    selects the compilation profile for the build.
                   Currently available profiles are "release" for
                   high optimization and "debug" for full debug options.
                   If --flag is not specified the "debug" flags are the
                   default.

(For fpm developers, should the --flag in the last sentence of the description be --profile?)

1 Like

It’s correct but a little confusing. If --flag is specified no profile is applied unless specified. This allows you complete control of the compiler options. If --flag is not specified the default is --profile debug.

So if --flag is specified and no profile is specified only the options specified with --flag are applied.

If both are specified the options from the profile are combined with the options specified with --flag.

fpm run  ###  same as "fpm run --profile debug"
fpm run --flag '-Wall -O3'  ## only the options specified are applied
fpm run --flag "-march=broadwell" --profile release # use options from release profile plus specified option.
2 Likes