This repo contains some basic examples which test if SCons is working properly for Fortran compilation.
A fortran compiler. You would need GNU Fortran or Intel Fortran installed on your system.
A virtual environment with SCons. With your preferred Python interpreter do this: Linux or MacOS
python -m venv venv
. ./venv/bin/activate
pip install scons
Windows
python -m venv venv
.\venv\Scripts\activate
pip install scons
The source code is divided into three modules:
main_prog.fThe main program in a fixed form file. Depends on module_one and module_two.module_one.f90A Fortran module containing two public functions, in free form, depends on module_two.module_two.f90A Fortran module continaing a public function, in free form
Identical source code is in the TestFlat and TestSConscript directories.
Here the Fortran files are all in one directory and can be compiled using different SConstruct files:
SConstructUses the DefaultEnvironment to build the ProgramSConstruct_gfortran2Defines an Environment, passing the tools, to build the ProgramSConstruct_gfortran3Uses the DefaultEnvironment but reverses the order of the source files.
Here the content from the SConstruct files from the TestFlat directory are
moved into SConscript files. The code in this area can be built in two
different ways:
- Individual SConstruct files that process the corresponding SConscript file.
- A single SConstruct file that uses
variant_dirfor each.
I tried everything here with the scons repo checked out locally at tag 4.8.1 and
ran pip install -e . into the virtual environment. The main issue at this point
is that:
- None of this code builds out of the box at all on Windows. The ifort tool does not configure properly even if you have it pre-configured in the environment.
- The gfortran tool is configured on Windows by default, but the gfortran exe is
not located even if you have it in the path when calling
sconson the command line. - Explicitly prepending the gfortran location into the build Environment path solves that but then the Program's do not link.