-
Notifications
You must be signed in to change notification settings - Fork 28
Build Process in Unix Cmake
Don Robinson, ESSA Technologies, July 2019
This wiki documents the process of setting things up on Unix so you can build FVS executables from the source files in the open-fvs repository. Builds of 32- and 64-bit versions have been tested using Ubuntu Linux. For more information on the build process, including information for builds on Windows please refer to our other wiki pages, Building in Windows through Cmake, Building through Visual Studio, or the FAQ. As an alternative to the Cmake build environment described below, you might also want to read this page for building FVS in Windows with Make to see if the make tools are suitable.
- Getting the Necessary Tools
- Getting the Source Files
- Building the Unix Makefile with Cmake
- Building the Executable for Development & Debugging
- Building the Executable in Batch
- Redistributables
- Working with Databases
This documentation is based on building FVS on the Ubuntu variant of Linux (64-bit Ubuntu 14.04). It has been tested with Cmake 2.8.7 and gfortran 4.6.3. Your particular Unix OS might behave differently. You will probably need to download and install Cmake, gfortran and ODBC software using commands like this:
sudo apt-get install gfortran
sudo apt-get install cmake
sudo apt-get install unixodbc-dev
On 64-bit Ubuntu you will probably need to download and install the C/C++ compilers:
sudo apt-get install build-essential
The Cmake build steps described below have been tested with Version 2.8.7 and require at least Version 2.6. gfortran has been tested with Version 4.6.3.
Please visit Downloading Source Code to find out about Git clients and the FVS code base.
Open a command line shell and navigate to the trunk/bin
directory into which you checked out the open-fvs files. If you had placed the files into a directory called MyFvsFiles
you would type the command as shown below.
cd /MyFvsFiles/trunk/bin
Once you have navigated to the correct directory you are ready to use Cmake to create the Unix Makefile. Cmake should automatically detect the OS and build the Makefile for each FVS variant. (If this does not happen automatically, please post the problem so that it can be resolved.)
At the command line type
cmake -G"Unix Makefiles" .
This will begin the creation of Unix makefiles for all FVS variants. Each variant's Makefile will be placed in a sub-directory like this
/MyFvsFiles/trunk/bin/FVSie_CmakeDir
FVS variant subdirectories are named with the pattern FVS**_CmakeDir
, where **
is a 2-letter abbreviation for the variant (e.g., 2-letters ie
for Inland Empire or ls
for Lake States).
Cmake utilizes two kinds of files to create to create each variant makefile. First, it uses a master script file called CMakeLists.txt to control the creation of the makefile. (You are welcome to inspect this file, but editing it is not recommended for beginners.) This master script file utilizes a set of about 20 files in turn - one for each variant - with names like 'FVSie_sourceList.txt'. These files need to exist in the trunk/bin
directory in order to build the variants.
As Cmake creates each variant makefile you will see something like this:
-- tobuild = <...>/trunk/bin/FVSie_sourceList.txt
-- Building FVS variant with Unix
-- The C compiler identification is GNU
-- The Fortran compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working Fortran compiler: /usr/bin/gfortran
-- Check for working Fortran compiler: /usr/bin/gfortran -- works
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Checking whether /usr/bin/gfortran supports Fortran 90
-- Checking whether /usr/bin/gfortran supports Fortran 90 -- yes
-- slfn = FVSie_sourceList.txt prgName= FVSiec
-- FVSvariant = FVSie
-- Configuring done
-- Generating done
-- Build files have been written to: <...>/trunk/bin/FVSie_CmakeDir
-- Configuring done
-- Generating done
-- Build files have been written to: <...>/trunk/bin
When that is complete, you can proceed to build FVS from with the variant sub-directory. You only need to repeat the step of creating a makefile if the underlying set of FVS source files change. Afterward, you can just rebuild the variants you need, based on periodic updates to the source code.
At the command-line, cd
to the directory containing the variant you wish to work with. In the example that follows the Inland Empire variant (ie) is used, and the makefile will be located here:
/MyFvsFiles/trunk/bin/FVSie_CmakeDir/Makefile
At the command-line, type this to begin building the executable:
make
When complete, you will find these 4 key components in the variant sub-directory:
Component Name | Language |
---|---|
FVSie | FORTRAN |
libFVSfofem.so | C |
libFVS_ie.so | FORTRAN |
libFVSsql.so | C |
Note: When Mac OS X is used as the build environment, the .so
suffix will be replaced with a .dylib
suffix.
This feature is not yet developed for Unix. It is a trivial shell script...
FVS executables created with Unix - the executable and 3 shared libraries - can be freely distributed to others using the same Unix OS platform. To work properly, components for database connectivity (described below) must also be installed on the host computer.
FVS can interact with many common database formats: SQL, MS Access, MS Excel and probably others. Each of these target database formats requires special ODBC software drivers to enable input and output, and there are some limitations based on combinations of operating system, FVS tool chain and 64 bit versions of drivers. In all cases, there is a greater chance of first-time success if there is consistency in the use of 64-bit components, as these are the configurations that have been tested.
If you wish to interact with a SQL database file using a 64-bit Unix build of FVS, 64-bit versions of the SQLite and SQLite3 database software for can be installed using a command like this:
sudo apt-get install libsqliteodbc
After installation you will find the text file /etc/odbcinst.ini
on your system, with the following contents:
[SQLite]
Description = SQLite ODBC Driver
Driver = /usr/lib/libsqliteodbc.so
Setup = /usr/lib/libsqliteodbc.so
UsageCount = 1
[SQLite3]
Description = SQLite3 ODBC Driver
Driver = /usr/lib/libsqlite3odbc.so
Setup = /usr/lib/libsqlite3odbc.so
UsageCount = 1
If you wish to enable the automatic recognition by the FVS Database Extension, of SQL-format database files with a .db
suffix, the following lines must be added to this file:
[SQLite3 ODBC Driver]
Description = SQLite3 ODBC Driver
Driver = /usr/lib/libsqlite3odbc.so
Setup = /usr/lib/libsqlite3odbc.so
UsageCount = 1
To make this change, you can bypass the read-only status of the file with this command:
sudo chmod 777 /etc/odbcinst.ini
and then edit the file using a text editor such as vi
.
The FVS Database Extension documentation TO DO UPDATE URL ONCE WORKING describes all the available ways to interact with databases, including how to customize database connection parameters.