Skip to content

Commit

Permalink
make.sh now automatically detects operating system and X11 support on…
Browse files Browse the repository at this point in the history
… Linux and only runs FluidX3D if last compilation was successful, fixed compiler warnings on Android
  • Loading branch information
ProjectPhysX committed Feb 17, 2024
1 parent 1043f9a commit f990dfb
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 39 deletions.
23 changes: 3 additions & 20 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,16 @@ git clone https://github.com/ProjectPhysX/FluidX3D.git
- Compile and run by clicking the <kbd>► Local Windows Debugger</kbd> button.
- To select a specific GPU, open Windows CMD in the `FluidX3D` folder (type `cmd` in File Explorer in the directory field and press <kbd>Enter</kbd>), then run `bin\FluidX3D.exe 0` to select device `0`. You can also select multiple GPUs with `bin\FluidX3D.exe 0 1 3 6` if the setup is [configured as multi-GPU](#the-lbm-class).

### Linux
### Linux / macOS / Android
- Compile and run with:
```bash
chmod +x make.sh
./make.sh
```
- Compiling requires [`g++`](https://gcc.gnu.org/) with `C++17`, which is supported since version `8` (check with `g++ --version`). If you have [`make`](https://www.gnu.org/software/make/) installed (check with `make --version`), compiling will will be faster using multiple CPU cores; otherwise compiling falls back to using a single CPU core.
- If you use [`INTERACTIVE_GRAPHICS`](src/defines.hpp), select [`TARGET=Linux-X11`](make.sh#L3) in [`make.sh`](make.sh#L3).
- To select a specific GPU, enter `./make.sh 0` to compile+run, or `bin/FluidX3D 0` to run on device `0`. You can also select multiple GPUs with `bin/FluidX3D 0 1 3 6` if the setup is [configured as multi-GPU](#the-lbm-class).

### macOS
- Select [`TARGET=macOS`](make.sh#L5) in [`make.sh`](make.sh#L5).
- Compile and run with:
```bash
chmod +x make.sh
./make.sh
```
- [`INTERACTIVE_GRAPHICS`](src/defines.hpp) mode is not supported on macOS, as no X11 is available. You can still use [`INTERACTIVE_GRAPHICS_ASCII`](src/defines.hpp) preview though, or [render video](#video-rendering) to the hard drive with regular [`GRAPHICS`](src/defines.hpp) mode.

### Android
- Select [`TARGET=Android`](make.sh#L6) in [`make.sh`](make.sh#L6).
- Compile and run with:
```bash
chmod +x make.sh
./make.sh
```
- [`INTERACTIVE_GRAPHICS`](src/defines.hpp) mode is not supported on Android, as no X11 is available. You can still use [`INTERACTIVE_GRAPHICS_ASCII`](src/defines.hpp) preview though, or [render video](#video-rendering) to the hard drive with regular [`GRAPHICS`](src/defines.hpp) mode.
- Operating system (Linux/macOS/Android) and X11 support (required for [`INTERACTIVE_GRAPHICS`](src/defines.hpp)) are detected automatically. In case problems arise, you can still manually select [`target=...`](make.sh#L13) in [`make.sh`](make.sh#L13).
- On macOS and Android, [`INTERACTIVE_GRAPHICS`](src/defines.hpp) mode is not supported, as no X11 is available. You can still use [`INTERACTIVE_GRAPHICS_ASCII`](src/defines.hpp) though, or [render video](#video-rendering) to the hard drive with regular [`GRAPHICS`](src/defines.hpp) mode.

<br>

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ $$f_j(i\\%2\\ ?\\ \vec{x}+\vec{e}_i\\ :\\ \vec{x},\\ t+\Delta t)=f_i^\textrm{tem
- uses PCIe communication, so no SLI/Crossfire/NVLink/InfinityFabric required
- single-node parallelization, so no MPI installation required
- [GPUs don't even have to be from the same vendor](https://youtu.be/PscbxGVs52o), but similar memory capacity and bandwidth are recommended
- works in [Windows](DOCUMENTATION.md#windows) and [Linux](DOCUMENTATION.md#linux) with C++17, with limited support also for [macOS](DOCUMENTATION.md#macos) and [Android](DOCUMENTATION.md#android)
- works on [Windows](DOCUMENTATION.md#windows) and [Linux](DOCUMENTATION.md#linux--macos--android) with C++17, with limited support also for [macOS](DOCUMENTATION.md#linux--macos--android) and [Android](DOCUMENTATION.md#linux--macos--android)
- supports [importing and voxelizing triangle meshes](DOCUMENTATION.md#loading-stl-files) from binary `.stl` files, with fast GPU voxelization
- supports [exporting volumetric data](DOCUMENTATION.md#data-export) as binary `.vtk` files
- supports [exporting triangle meshes](DOCUMENTATION.md#data-export) as binary `.vtk` files
Expand Down
34 changes: 24 additions & 10 deletions make.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
#!/bin/bash

# command line argument(s): device ID(s); if empty, FluidX3D will automatically choose the fastest available device(s)

#TARGET=Linux-X11 # compile on Linux with X11 graphics
TARGET=Linux # compile on Linux (without X11)
#TARGET=macOS # compile on macOS (without X11)
#TARGET=Android # compile on Android (without X11)
case "$(uname -a)" in # automatically detect operating system and X11 support on Linux
Darwin*) target=macOS;;
*Android) target=Android;;
Linux*) if xhost >&/dev/null; then target=Linux-X11; else target=Linux; fi;;
*) target=Linux;;
esac
echo -e "\033[92mInfo\033[0m: Detected Operating System: "${target}

#target=Linux-X11 # manually set to compile on Linux with X11 graphics
#target=Linux # manually set to compile on Linux (without X11)
#target=macOS # manually set to compile on macOS (without X11)
#target=Android # manually set to compile on Android (without X11)

echo_and_execute() { echo "$@"; "$@"; }

if command -v make &>/dev/null; then # if make is available, compile FluidX3D with multiple CPU cores
make $TARGET
echo -e "\033[92mInfo\033[0m: Compiling with "$(nproc)" CPU cores."
make ${target}
else # else (make is not installed), compile FluidX3D with a single CPU core
echo -e "\033[92mInfo\033[0m: Compiling with 1 CPU core. For faster multi-core compiling, install make with \"sudo apt install make\"."
mkdir -p bin # create directory for executable
rm -rf temp bin/FluidX3D # prevent execution of old executable if compiling fails
if [ $TARGET == Linux-X11 ]; then g++ src/*.cpp -o bin/FluidX3D -std=c++17 -pthread -I./src/OpenCL/include -L./src/OpenCL/lib -lOpenCL -I./src/X11/include -L./src/X11/lib -lX11 -lXrandr; fi
if [ $TARGET == Linux ]; then g++ src/*.cpp -o bin/FluidX3D -std=c++17 -pthread -I./src/OpenCL/include -L./src/OpenCL/lib -lOpenCL; fi
if [ $TARGET == macOS ]; then g++ src/*.cpp -o bin/FluidX3D -std=c++17 -pthread -I./src/OpenCL/include -framework OpenCL; fi
if [ $TARGET == Android ]; then g++ src/*.cpp -o bin/FluidX3D -std=c++17 -pthread -I./src/OpenCL/include -L/system/vendor/lib64 -lOpenCL; fi
if [[ ${target} == Linux-X11 ]]; then echo_and_execute g++ src/*.cpp -o bin/FluidX3D -std=c++17 -pthread -Wno-comment -I./src/OpenCL/include -L./src/OpenCL/lib -lOpenCL -I./src/X11/include -L./src/X11/lib -lX11 -lXrandr; fi
if [[ ${target} == Linux ]]; then echo_and_execute g++ src/*.cpp -o bin/FluidX3D -std=c++17 -pthread -Wno-comment -I./src/OpenCL/include -L./src/OpenCL/lib -lOpenCL; fi
if [[ ${target} == macOS ]]; then echo_and_execute g++ src/*.cpp -o bin/FluidX3D -std=c++17 -pthread -Wno-comment -I./src/OpenCL/include -framework OpenCL; fi
if [[ ${target} == Android ]]; then echo_and_execute g++ src/*.cpp -o bin/FluidX3D -std=c++17 -pthread -Wno-comment -I./src/OpenCL/include -L/system/vendor/lib64 -lOpenCL; fi
fi

bin/FluidX3D "$@" # run FluidX3D
if [[ $? == 0 ]]; then bin/FluidX3D "$@"; fi # run FluidX3D only if last compilation was successful
21 changes: 13 additions & 8 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
MAKEFLAGS = -j$(nproc)
CC = g++
CFLAGS = -std=c++17 -pthread
CFLAGS = -std=c++17 -pthread -Wno-comment

.PHONY: no-target
no-target:
@echo Please select one of these targets: make Linux-X11, make Linux, make macOS, make Android
@echo "\033[91mError\033[0m: Please select one of these targets: make Linux-X11, make Linux, make macOS, make Android"

Linux-X11 Linux: LDFLAGS_OPENCL = -I./src/OpenCL/include -L./src/OpenCL/lib -lOpenCL
macOS: LDFLAGS_OPENCL = -I./src/OpenCL/include -framework OpenCL
Android: LDFLAGS_OPENCL = -I./src/OpenCL/include -L/system/vendor/lib64 -lOpenCL
Linux-X11 Linux macOS Android: LDFLAGS_OPENCL = -I./src/OpenCL/include

Linux-X11: LDFLAGS_X11 = -I./src/X11/include -L./src/X11/lib -lX11 -lXrandr
Linux-X11 Linux: LDLIBS_OPENCL = -L./src/OpenCL/lib -lOpenCL
macOS: LDLIBS_OPENCL = -framework OpenCL
Android: LDLIBS_OPENCL = -L/system/vendor/lib64 -lOpenCL

Linux-X11: LDFLAGS_X11 = -I./src/X11/include
Linux macOS Android: LDFLAGS_X11 =

Linux-X11: LDLIBS_X11 = -L./src/X11/lib -lX11 -lXrandr
Linux macOS Android: LDLIBS_X11 =

Linux-X11 Linux macOS Android: bin/FluidX3D

bin/FluidX3D: temp/graphics.o temp/info.o temp/kernel.o temp/lbm.o temp/lodepng.o temp/main.o temp/setup.o temp/shapes.o make.sh
@mkdir -p bin
$(CC) temp/*.o -o bin/FluidX3D $(CFLAGS) $(LDFLAGS_OPENCL) $(LDFLAGS_X11)
$(CC) temp/*.o -o bin/FluidX3D $(CFLAGS) $(LDFLAGS_OPENCL) $(LDLIBS_OPENCL) $(LDFLAGS_X11) $(LDLIBS_X11)

temp/graphics.o: src/graphics.cpp src/defines.hpp src/graphics.hpp src/lodepng.hpp src/utilities.hpp make.sh
@mkdir -p temp
Expand Down Expand Up @@ -53,4 +58,4 @@ temp/shapes.o: src/shapes.cpp src/defines.hpp src/graphics.hpp src/info.hpp src/

.PHONY: clean
clean:
@rm -rf temp bin/FluidX3D
@rm -rf temp bin/FluidX3D

0 comments on commit f990dfb

Please sign in to comment.