usnistgov / REFPROP-cmake

Small repo with CMake build system for building REFPROP shared library
49 stars 27 forks source link

REFPROP-cmake

Small repo with CMake build system for building REFPROP shared library for REFPROP versions 9.1 and newer

Why you should use this build system:

Brought to you by Ian Bell, NIST, ian.bell@nist.gov

Getting help

Open an issue: https://github.com/usnistgov/REFPROP-cmake/issues/new

License

Public domain, (though REFPROP itself is not public domain)

Pre-Requisites

Instructions

  1. Do a recursive(!) clone of this repository (e.g. git clone --recursive https://github.com/usnistgov/REFPROP-cmake.git)
  2. Copy the FORTRAN directory from your REFPROP installation into the root of your checked out code (or see below about using the path directly)
  3. Open a console in the root of the cloned repository
  4. mkdir build
  5. cd build
  6. cmake .. -DCMAKE_BUILD_TYPE=Release
  7. cmake --build .

Once the shared library has been build, you will need to place it somewhere that your operating system knows where to find it. On windows, that would be on the PATH environment variable. On OSX, that would be one of the default shared library locations (see apple docs ).

OSX/MacOS Notes

  1. Use the gfortran from homebrew and build for x86_64 and use Rosetta2 emulation. The flags you want are something like:

    cmake .. -DCMAKE_FORTRAN_COMPILER=/path/to/gfortran -DREFPROP_X8664=ON

    • If you want to force a 32-bit build (I'm looking at you Excel 2016 on Mac), you can do:

    cmake .. -DREFPROP_32BIT=ON

    • You can obtain homebrew versions of gcc and gfortran with brew install gcc once homebrew is installed

    • On OSX, cmake --build . with homebrewed python and vanilla system python both installed fails because find_package(PythonInterp), called by cmake .. -DCMAKE_BUILD_TYPE=Release, picks up the system python rather than the brewed python, as evident from an examination of CMakeCache.txt and build.make.

    The solution is to force cmake to use the brewed python:

    cmake .. -DCMAKE_BUILD_TYPE=Release -DPYTHON_EXECUTABLE:FILEPATH=/usr/local/bin/python3
  2. Use gcc/gfortran from Macports. Install Macports gcc and select it by sudo port install gccXX and sudo port select gcc mp-gccXX where XX is the version of gcc, e.g., 12. Then you can use the same non-Mac-specific install instructions as described above in the "Instructions" section.

cmake .. -DREFPROP_OSX_STATIC_LINK=ON

General Notes

Instructions for MINGW builds on windows

It is possible to use a fully open-source build system on windows to compile REFPROP. This is enabled by the use of the MINGW compiler system.

To get started from a clean windows installation, you will need:

Then to set up your shell, at the command prompt do:

set PATH=D:\Software\mingw\bin;%PATH%

or put the path to wherever the MINGW compiler has been installed.

Check out the git sources with:

git clone --recursive https://github.com/usnistgov/REFPROP-cmake

Move into that directory:

cd REFPROP-cmake

Make a working directory

mkdir build

Move into that directory

cd build

Configure the build system

cmake .. -DREFPROP_FORTRAN_PATH=R:/FORTRAN -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release

and build the DLL

cmake --build .

That's it!

Or, all in a tidy batch file that clones the repo, does the build, and cleans up after itself...

You will want to save these contents in a .bat file and run it from the command prompt, passing it 32 for a 32-bit build generating REFPROP.DLL, or 64 for a 64-bit build, generating the REFPRP64.DLL file.

Here is the contents of build_dll.bat

@echo off

REM Call this script like: build_dll.bat 32
REM for a 32-bit build, or build_dll.bat 64 for a 64-bit build

REM --- THESE ARE THE PATHS YOU MAY NEED TO MODIFY ---
set PATH_32BIT=D:\Software\mingw-w64\i686-7.2.0-posix-dwarf-rt_v5-rev0\mingw32\bin
set PATH_64BIT=D:\Software\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev0\mingw64\bin
set FORTRAN_PATH=R:/FORTRAN

REM --------- You should not need to touch anything below this line ------------

@setlocal enabledelayedexpansion

if "%1" == "64" (
    set MINGW_PATH=%PATH_64BIT%
    set BITNESS=64
) 
if "%1" == "32" (
    set MINGW_PATH=%PATH_32BIT%
    set BITNESS=32
) 
if "%MINGW_PATH%" == "" (
    echo An invalid bitness was selected, valid values are "64" or "32"
    pause
    exit /b
)
if not exist "%MINGW_PATH%" (
    echo The path to MINGW bin folder is invalid
    pause
    exit /b
)
set "PATH=%MINGW_PATH%;%PATH%"

git clone --recursive https://github.com/usnistgov/REFPROP-cmake
cd REFPROP-cmake
mkdir build
cd build
cmake .. -DREFPROP_FORTRAN_PATH=%FORTRAN_PATH% -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release
cmake --build .
cd ../..
if "%BITNESS%" == "32" (
    copy REFPROP-cmake\build\REFPROP.DLL REFPROP.DLL
)
if "%BITNESS%" == "64" (
    copy REFPROP-cmake\build\REFPRP64.DLL REFPRP64.DLL
)
rmdir /Q /S REFPROP-cmake