Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Official Windows support via CMake #48
The cmake files for netcdf-fortran need to be overhauled, to leverage some of the knowledge gained whilst enhancing cmake support in netcdf-c. Part of this effort will also be to include official support for netCDF-Fortran using Windows compilers.
We are a bit hobbled by the fact that there aren't any free compilers (I can find) that are commonly used in conjunction with Microsoft Visual Studio. PGI and Intel Fortran Compilers seem to be the main two our community are using. The Intel compiler pricing is prohibitive at this point, but we should be able to get most of the way there using the PGI compilers.
Recently I succeeded in building NetCDF4 on Windows using the MSVC++ and Intel Fortran compilers. The procedure is more or less straightforward, but there is one file that needed patching, netcdf-config.cmake.in. The computation of the prefix path is wrong. Here is the code I use for this:
Compute installation prefix relative to this file.
get_filename_component (_dir "@CMAKE_CURRENT_LIST_FILE@" PATH)
Note that I use CMake's "NMake Makefiles" generator and nmake rather than building via Visual Studio. The latter should not be a problem, but I seldom use that method in conjunction with CMake-based projects.
I have used VS 2013 and Intel Fortran 2015 myself. I did create a small batch file to automate things as much as possible, but I also see that it wants either VS 2012 or VS 2013. The reason for that is that the build procedure for HDF5 requires either of these (or else only batch and configuration files for these two environments are provided).
What are the symptoms? What messages do you get?
I eventually succeeded in building netCDF-Fortran with Intel Fortran 17.0 on Windows. Some notes on the process are below. Any advice is appreciated, maybe I could turn this into a pull request.
netCDF-C 22.214.171.124 Static Library
The Windows distribution for netCDF-C does not include static libraries so you need to build them yourself. I ran CMake with the following arguments, which may vary depending on your HDF5 configuration. If you want to build with a static CRT (/MT) you can also set
netCDF-Fortran 4.4.4 Static Library
This is easier than a shared build. I ran CMake with the following arguments. This will build the library only; examples and tests will not build because additional libraries need to be passed to the linker and the current CMake script does not support this. These arguments should disable tests, but since there is no ENABLE_EXAMPLES option in CMakeLists.txt you will need to remove ADD_SUBDIRECTORY(examples) manually for a 'clean' build.
I could then build examples with the following 'one-liner', adjust as necessary for your HDF5 configuration:
netCDF-Fortran 4.4.4 Shared Library
You can use the same CMake arguments for the static library but set BUILD_SHARED_LIBS=TRUE and NETCDF_C_LIBRARY to the shared version of the C library, the one provided in the official Windows distribution will work. This will get you almost all the way there, but I had the exact same issues mentioned by @arjenmarkusdeltaresnl in the Intel Forums:
There are two problems here:
My temporary solution was just to remove all of those function calls from netCDF-Fortran because I didn't need them. I think a proper solution would involve either of a couple options:
I'm not sure yet how to resolve the issue with ncerr and ncopts.