Skip to content

Build Process in Windows using Cmake

Daniel Wagner edited this page Jul 3, 2023 · 1 revision

Building FVS in Windows Using Cmake

Don Robinson, ESSA Technologies, July 2019

This wiki documents the process of setting things up on a Windows PC so you can build FVS executables from the source files in the open-fvs repository using the Cmake utility. Builds 64-bit versions have been tested on a clean Win7 SP1 VM. For more information on the build process, including information for builds on other platforms please refer to our other build pages for building in a Unix environment, building through Visual Studio, building in Windows with Make, or the FAQ.

Contents

  • Getting the Necessary Tools
  • Getting the Source Files
  • Building the MinGW Makefile with Cmake
  • Building the Executable for Development & Debugging
  • Building the Executable in Batch
  • Redistributables
  • Switching Between CMake Build Systems
  • Working with Databases

Getting the Necessary Tools

You will need Administrator privileges to install the necessary tools, so ensure you have that before proceeding.

The following documentation should work for a number of Unix like shell environments built to run on the Windows platform, MinGW is used here as an example. Information about MinGW can be found at www.mingw.org

If you are planning on running FVS tests, refer to the Tests wiki page to see additional MingGW components that you may wish to install. After selecting the components you need, they can be downloaded and installed by choosing "Installation > Update Catalogue" from the Installation Manager menu. This will download and install the additional utilities to the MinGW installation directory.

Once the install has begun you will be asked to select 5 options:

  1. Version: most recent (e.g. 4.9.0)
  2. Architecture: x86_64
  3. Threads: posix
  4. Exception: seh
  5. Build revision: most recent (e.g. 1)

These 5 options have been tested but others may also work.

For 64-bit builds, add the MinGW directory to the PATH, which by default (using the 5 selections above) is:

C:\Program Files\mingw-w64\x86_64-4.9.0-posix-seh-rt_v3-rev1\mingw64\bin

You will also need to install the Cmake software, which can be found at http://cmake.org. Download and install the latest version. The Cmake build steps described below have been tested with CMake Version 2.8, using Version 4.8.1 language compilers installed by MinGW.

Your development work will likely mean that you will eventually merge your work into the trunk code. Please see the Testing wiki to learn about the requirements for testing model behavior prior to integrating code. Note that creating and running FVS tests requires the following (Unix) utilities: make, echo, grep, diff and rm.

Getting the Source Files

Please visit our Downloading Source Code page to find out about Git clients and the FVS code base.

Building the MinGW Makefile with Cmake

Open a DOS Command Window and navigate to the directory which contains the FVS code base. If you aren't familiar with the command prompt, click Start > (All) Programs > Accessories > Command Prompt and the Command Window should open to your personal directory. Assuming you have the FVS code base installed as described under Downloading Source Code, use the cd command to navigate to the trunk\bin directory inside the 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 MinGW Makefile. If MinGW is installed, Cmake should automatically detect it 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 (don't forget the '.' at the end!)

cmake -G"MinGW Makefiles" .

This will begin the creation of MinGW 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 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:

-- Building FVS variant with MinGW
-- tobuild = <...>/trunk/bin/FVSie_sourceList.txt
-- The C compiler identification is GNU 4.8.1
-- The CXX compiler identification is GNU 4.8.1
-- The Fortran compiler identification is GNU
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working Fortran compiler: C:/MinGW/bin/gfortran.exe
-- Check for working Fortran compiler: C:/MinGW/bin/gfortran.exe  -- works
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Checking whether C:/MinGW/bin/gfortran.exe supports Fortran 90
-- Checking whether C:/MinGW/bin/gfortran.exe supports Fortran 90 -- yes
-- slfn = FVSiec_sourceList.txt prgName= FVSie
-- 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 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.

Building the Executable for Development & Debugging

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:

mingw32-make

When complete, you will find these 4 key components in the variant sub-directory:

Component Name Language
FVSie.exe FORTRAN
libFVSfofem.dll C
libFVS_ie.dll FORTRAN
libFVSsql.dll C

Building the Executable in Batch

Assuming you have a command-prompt in this directory:

\MyFvsFiles\trunk\bin

you can run the DOS batch file shown below to compile all variants in \bin sub-directory. If you wish to modify this batch file for a subset of variants, please make a copy and use your copy.

BuildAll_MinGW.bat

Redistributables

FVS executables created with MinGW - the EXE and 3 DLLs - can be freely distributed to others. If these are provided to users who do not have the MinGW system installed (or whose components cannot be found by the PATH variable), the following files will need to be provided. When provided, they can be copied into the directory containing the FVS executable.

32-bit Component | 64-bit Component (not supported) | -----------------------|------------------------ libgcc_s_dw2-1.dll | libgcc_s_dw2-1.dll libgfortran-3.dll | libgfortran-3.dll libquadmath-0.dll | libquadmath-0.dll libgcc_s_seh-1.dll | libwinpthread-1.dll

Note that although the 32- and 64-bit build component DLLs may have the same filename, they are different binary files. 32- and 64-bit DLLs cannot be mixed. On a default 32-bit installation, the redistributables can be found here:

C:\MinGW\bin

On a default 64-bit installation the redistributables can be found here (assuming the 5 installation options described above):

C:\Program Files\mingw-w64\x86_64-4.9.0-posix-seh-rt_v3-rev1\mingw64\bin

The 32- or 64-bit DLL redistributables must match the 32- or 64-bit version of FVS. Only 64-bit versions are currently recommended or supported

Switching Between CMake Build Systems

Most of the time you will probably only want to build MinGW makefiles. However, developers may may need to test their code on a non-MinGW system like Visual Studio or switch between 32- and 64-bit builds. If you need to do this, you should remove these files and directories before attempting to build with Visual Studio:

directory: CMakeFiles
file: cmake_install.cmake
file: CMakeCache.txt

These files and directories contain information that is stored by CMake the first time it is run, and will "lock" CMake into always creating MinGW makefiles. Removing them allows CMake to create other kinds of build systems.

Working with Databases

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 32/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 32- or 64-bit components, as these are the configurations that have been tested.

If you wish to interact with a SQL database file using a 32- or 64-bit MinGW build of FVS, 32- and 64-bit versions of the SQLite3 database software for can be found here. Installation of this software creates a System DSN ODBC driver that can interact with SQLite3 databases having a default .db filename suffix.

If 32- or 64-bit Microsoft Office software is installed on your computer, it is also possible to interact directly with Excel and Access files, as described in the FVS Database Extension documentation. This documentation also describes how to customize database connection parameters. It may be possible to mix 32- and 64-bit versions of FVS and Microsoft Office drivers, but this has not been tested. The Windows OS does not permit simultaneous installation of both 32- and 64-bit ODBC drivers for Excel or Access.