Skip to content

Commit

Permalink
Merge branch 'visual_studio_compiling' into 'master'
Browse files Browse the repository at this point in the history
fixes for windows compilation (defining NOMINMAX), installation-instructions for Windows/Visual Studio

See merge request lfortran/lfortran!1639
  • Loading branch information
certik committed Jan 8, 2022
2 parents bb39faf + 9d1e193 commit af1927c
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Testing/Temporary
CPackConfig.cmake
CPackSourceConfig.cmake
_CPack_Packages
/CMakeSettings.json

## libraries
*.a
Expand All @@ -68,6 +69,7 @@ src/lfortran/parser/tokenizer.cpp
src/lfortran/parser/preprocessor.cpp
src/lfortran/ast.h
src/lfortran/asr.h
src/libasr/asr.h
src/lfortran/config.h
share/jupyter/kernels/fortran/kernel.json
src/runtime/*.o.empty.c
Expand Down Expand Up @@ -141,6 +143,7 @@ MANIFEST

## Editor Files
.vscode/
.vs/

## Build Files
*/bin/lfortran
Expand Down
2 changes: 2 additions & 0 deletions build0.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

xonsh ./build1_win.sh
8 changes: 8 additions & 0 deletions build1_win.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

bash ci/version.sh
python grammar/asdl_cpp.py
python grammar/asdl_cpp.py grammar/ASR.asdl src/libasr/asr.h
pushd src/lfortran/parser && re2c -W -b tokenizer.re -o tokenizer.cpp && popd
pushd src/lfortran/parser && re2c -W -b preprocessor.re -o preprocessor.cpp && popd
pushd src/lfortran/parser && bison -Wall -d -r all parser.yy && popd
23 changes: 23 additions & 0 deletions doc/src/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,29 @@ Run an interactive prompt:
./src/bin/lfortran
```

## Build on Windows with Visual Studio

Install Conda for example by installing the Miniconda installation by following instructions there for your platform. If not already done, activate the Conda-Installation (cf. Conda installation instructions).

First, clone the repo to a local folder.

Launch a Conda command interpreter and run the following commands:
```bash
conda update -q conda
conda install -c conda-forge python=3.7 re2c m2-bison xonsh llvmdev=11.1.0 jupyter xeus=1.0.1 xtl nlohmann_json cppzmq jupyter_kernel_test pytest
```
Next, `cd` to the root of the repository and run
```bash
.\build0.bat
```

Now, you can launch Visual Studio and open the LFortran folder.
Before the first build you have to set up the `ZLib`-pathes: Go to the CMake-Settings (Project -> CMake Setttings for lfortran) and check `Show advanced variables`. Scroll to the `ZLIB_...` variables and set:
- `ZLIB_INCLUDE_DIR` = \<Conda-Installation-Path\>\Library\include
- `ZLIB_LIBRARY_[DEBUG|RELEASE]` = \<Conda-Installation-Path\>\Library\lib\zlib.lib

Then you can generate the CMake-Cache and build the project.

## Enabling the Jupyter Kernel

To install the Jupyter kernel, install the following Conda packages also:
Expand Down
3 changes: 3 additions & 0 deletions src/bin/tpl/cpp-terminal/terminal_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include <stdexcept>

#ifdef _WIN32
# ifndef NOMINMAX
# define NOMINMAX
# endif // NOMINMAX
# include <conio.h>
# define _WINSOCKAPI_
# include <windows.h>
Expand Down
4 changes: 3 additions & 1 deletion src/bin/tpl/whereami/whereami.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ extern "C" {
#endif

#if defined(_WIN32)

#ifndef NOMINMAX
#define NOMINMAX
#endif // NOMINMAX
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
Expand Down
7 changes: 7 additions & 0 deletions src/lfortran/utils.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#ifdef _WIN32
#ifndef NOMINMAX
#define NOMINMAX
#endif // NOMINMAX
#include <windows.h>
#endif

#include <fstream>

#include <bin/tpl/whereami/whereami.h>
Expand Down

0 comments on commit af1927c

Please sign in to comment.