-
Notifications
You must be signed in to change notification settings - Fork 44
Building on Windows
Kelly (KT) Thompson edited this page Mar 3, 2019
·
6 revisions
- These are not meant to be instructions, but rather working notes while this process is standardized.
- I have not worked with the 64-bit flavor of these instructions. Assume everything is 32-bit.
-
Visual Studio 2017 Community Edition. Choose the following options:
- Visual C++
- Git for Windows
- CMake 3.11+
- Random123
- GSL
> git clone [email protected]:KineticTheory/gsl > cd $build_dir > cmake -G"Visual Studio 15 2017 Win64" -DGSL_INSTALL_MULTI_CONFIG=ON -DBUILD_SHARED_LIBS=ON -DMSVC_RUNTIME_DYNAMIC=ON -DCMAKE_INSTALL_PREFIX=c:\work\vendors64\gsl-2.4 c:\work\gsl > cmake --build . --target gsl --config Release > cmake --build . --target install --config Release
- Alternate: GSL
- Microsoft MPI
- Python 2 for Windows - or use the python3 that ships with VS2017.
- TortoiseGit
- LAPACK
- Metis
-
c:\work\vendors64
- Unzip or install Random123 and GSL here. -
c:\work\draco
- This is the git controlled source directory -
C:\work\vs2017_x64\d
- This is the build directory -
C:\work\vs2017_x64\install
- This is the install location.
- Visual Studio does not provide native support for Fortran.
- The Draco build system has a modified version of
CMakeAddFortranSubdirectory
that allows the Fortran portions of the code to be built withgfortran
provided by msys2/mingw32. - To enable Fortran support
- Install msys2/mingw32 and update the installation:
- start the msys64 shell
- Update the installation:
pacman -Syuu
(repeat as needed; might need to exit the shell and restart it.) - Install mingw32:
pacman -S mingw-w64-i686-gcc
- Install mingw64:
pacman -S mingw-w64-x86_64-gcc
- Search for other packages:
pacman -Ss fortran
==> mingw-w64-i686-gcc-fortran - Install 32-bit gfortran:
pacman -S mingw-w64-i686-gcc-fortran
- For the next step, you also need
gendef
:pacman -S mingw-w64-i686-tools
- Install msys2/mingw32 and update the installation:
- To allow Microsoft MPI to work with mingw32's gfortran requires two extra steps:
- We must convert the
.dll
into a.a
:- Start a mingw32 shell
cd /i/work/vendors
-
gendef /c/windows/system32/msmpi.dll
==> msmpi.def -
dlltool -d msmpi.def -l libmsmpi.a -D msmpi.dll
==> libmsmpi.a
cp libmsmpi.a /c/program files/microsoft mpi/bin/.
rm msmpi.def
- We must modify
mpif.h
- Edit
C:\Program Files (x86)\Microsoft SDKs\MPI\Include\mpif.h
- Replace the single occurrence of
INT_PTR_KIND()
with8
.
- Edit
- We must convert the
- CMakeAddFortranSubdirectory issues.
- There appears to be an issue with Visual Studio 2017 Community Edition. I posted the following to [email protected]:
I use the CMakeAddFortranSubdirectory feature in one of my projects. This appears to be broken under
Visual Studio 2017 Community Edition RC because CMake\share\cmake-3.8\Modules\Platform\GNUtoMS_lib.bat.in
generates a batch file that contains:
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat"
and this batch function changes the current working directory to %USERPROFILE%/Source (unlike earlier
versions). Has anyone else seen this?
I have fixed the issue by replacing the cmake provided GNUtoMS_lib.bat.in with
@echo off
set CWD=%CD%
call "@CMAKE_GNUtoMS_BAT@"
cd /d %CWD%
lib /machine:"@CMAKE_GNUtoMS_ARCH@" %*
I'm not sure if CMake needs to make this change more permanent or if this is a bug in VS2017.
- Create
c:\work\vendors\setup.bat
that contains something like this:
@echo off
set VENDOR_DIR=c:\work\vendors
set GSL_ROOT_DIR=%VENDOR_DIR%\gsl-1.16
set RANDOM123_INC_DIR=%VENDOR_DIR%\Random123-1.08\include
rem Mingw-w64 (gfortran)
set PATH=%PATH%;C:\msys64\mingw32\bin
rem CMake
set PATH=%PATH%;C:\Program Files\CMake\bin
rem Help cmake find vcvars32.bat
set PATH=%PATH%;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build
- Use Tortoise or Git for Windows to clone the Draco repository.
- Optional: configure your ssh keys and add the upstream repository.
- Start the Visual Studio Command Prompt. There should be a shortcut named
x86 Native Tools Command Prompt for VS 2017 RC
. cd c:\work\vendors
setup.bat
- Start cmake:
cmake-gui
- Sources:
c:\work\draco
- Binaries:
c:\work\vs2017\d
- Configure
- Generate
- Open Project
- Right click on Solution Explorer --> CMakePredefinedTargets --> All_Build and select Build
- Tests can be run from the Command Prompt for Visual Studio:
ctest -C Debug -j 4