cdss-app-statemod-fortran-utest
CDSS StateMod Fortran unit tests, experimental.
This repository contains a test of using cmake
and cmocka
for StateMod unit tests.
The cmake
software is a popular software build framework.
The cmocka
software is a popular unit testing framework for C programs.
Because C and Fortran can be linked, an attempt is made here to use cmocka
for Fortran unit tests.
Alternative unit testing frameworks, and those specific to Fortran are found at the following Wikipedia page.
However, they all have a dependency on a wrapper framework written in Ruby or Python.
Using the C language cmocka
will allow programming the unit tests in a language
that can directly link to Fortran.
The following are instructions for installing cmake
and cmocka
in a MinGW environment,
which is what is used for StateMod development.
cmake
Install A binary distribution of cmake
is available on the CMake download page.
Download the zip file version so that contents can be reviewed, for example cmake-3.14.1-win64-x64.zip
.
Copy the contents of the file to the build-util
folder in this repository.
The bin
folder contains the software.
Edit the cdss-app-statemod-fortran/build-util/mingw/setup-mingw-env.bat
batch file to add the
above bin
folder to the PATH
environment variable.
Open a new cmd
window and test that cmake
is found by typing where cmake
.
Put together a run script 1-run-cmake.bat
similar to what has been done on other projects.
This shows the following error:
1-run-cmake.bat
scriptFolder=C:\Users\sam\cdss-dev\StateMod\git-repos\cdss-app-statemod-fortran-utest\test\
buildFolder=C:\Users\sam\cdss-dev\StateMod\git-repos\cdss-app-statemod-fortran-utest\test\build
-- The C compiler identification is GNU 5.3.0
-- The CXX compiler identification is GNU 5.3.0
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
CMake Error: Generator: execution of make failed. Make command was: nmake /nologo cmTC_05796\fast
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- broken
CMake Error at C:/Users/sam/cdss-dev/StateMod/git-repos/cdss-app-statemod-fortran-utest/build-util/cmake-3.14.1-win64-x64/share/cmake-3.14/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"C:/MinGW/bin/gcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/sam/cdss-dev/StateMod/git-repos/cdss-app-statemod-fortran-utest/test/build/CMakeFiles/CMakeTmp
Run Build Command(s):nmake /nologo cmTC_05796\fast
The system cannot find the file specified
Generator: execution of make failed. Make command was: nmake /nologo cmTC_05796\fast
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:7 (project)
-- Configuring incomplete, errors occurred!
See also "C:/Users/sam/cdss-dev/StateMod/git-repos/cdss-app-statemod-fortran-utest/test/build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/sam/cdss-dev/StateMod/git-repos/cdss-app-statemod-fortran-utest/test/build/CMakeFiles/CMakeError.log".
C:\Users\sam\cdss-dev\StateMod\git-repos\cdss-app-statemod-fortran-utest\test>
C:\Users\sam\cdss-dev\StateMod\git-repos\cdss-app-statemod-fortran-utest\test>where mingw-get
C:\MinGW\bin\mingw-get.exe
cmake
tries to compile a simple program and is apparently failing.
Searching for solutions did not indicate any clear solution.
It may be that there is an incompatibility between latest cmake
and gcc/gfortran version that is installed in MINGW (5.3.0).
It has been a couple of years since installing the compiler.
Try updating the compiler by using a cmd
window configured for StateMod
cdss-app-statemod-fortran/build-util/mingw/setup-mingw-env.bat
.
mingw-get update
mingw-get upgrade
There were no warnings. After running this, the version is 6.3.0.
Try running again and get essentially the same error.
It may be an issue that the 32-bit MINGW environment is installed on a 64-bit Windows 10
and cmake
things it is doing a cross-compile, even though this is not being requested.
See the following:
As suggested, set:
SET (CMAKE_C_COMPILER_WORKS 1)
SET (CMAKE_CXX_COMPILER_WORKS 1)
This allows cmake
to create the makefiles but trying to run make using 2-compile-tests.bat
gives a different error:
Makefile:40: *** missing separator. Stop.
The offending line is the !ELSE
in:
!IF "$(OS)" == "Windows_NT"
NULL=nul
!ELSE
NULL=nul
!ENDIF
Commenting all these lines out and then running make help
shows:
make help
make[1]: Entering directory `/c/Users/sam/cdss-dev/StateMod/git-repos/cdss-app-statemod-fortran-utest/test/build/year'
Microsoft Windows [Version 10.0.17763.379]
(c) 2018 Microsoft Corporation. All rights reserved.
So something does not seem to be working.
After some more reading, need to run cmake
and tell it that MinGW makefiles are being used:
set cmakeFlags=-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=gcc -DCMAKE_Fortran_COMPILER=gfortran -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -G "MinGW Makefiles"
cmake %cmakeFlags% ..
This then complains with:
sh.exe was found in your PATH, here:
C:/MinGW/msys/1.0/bin/sh.exe
For MinGW make to work correctly sh.exe must NOT be in your path.
Run cmake from a shell that does not have sh.exe in your PATH.
If you want to use a UNIX shell, then use MSYS Makefiles.
Cripes! More research indicates to use -DCMAKE_SH="CMAKE_SH-NOTFOUND"
when running cmake
.