Skip to content

Commit f990dfb

Browse files
committed
make.sh now automatically detects operating system and X11 support on Linux and only runs FluidX3D if last compilation was successful, fixed compiler warnings on Android
1 parent 1043f9a commit f990dfb

File tree

4 files changed

+41
-39
lines changed

4 files changed

+41
-39
lines changed

DOCUMENTATION.md

+3-20
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,16 @@ git clone https://github.com/ProjectPhysX/FluidX3D.git
2424
- Compile and run by clicking the <kbd>► Local Windows Debugger</kbd> button.
2525
- 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).
2626

27-
### Linux
27+
### Linux / macOS / Android
2828
- Compile and run with:
2929
```bash
3030
chmod +x make.sh
3131
./make.sh
3232
```
3333
- 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.
34-
- If you use [`INTERACTIVE_GRAPHICS`](src/defines.hpp), select [`TARGET=Linux-X11`](make.sh#L3) in [`make.sh`](make.sh#L3).
3534
- 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).
36-
37-
### macOS
38-
- Select [`TARGET=macOS`](make.sh#L5) in [`make.sh`](make.sh#L5).
39-
- Compile and run with:
40-
```bash
41-
chmod +x make.sh
42-
./make.sh
43-
```
44-
- [`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.
45-
46-
### Android
47-
- Select [`TARGET=Android`](make.sh#L6) in [`make.sh`](make.sh#L6).
48-
- Compile and run with:
49-
```bash
50-
chmod +x make.sh
51-
./make.sh
52-
```
53-
- [`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.
35+
- 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).
36+
- 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.
5437

5538
<br>
5639

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ $$f_j(i\\%2\\ ?\\ \vec{x}+\vec{e}_i\\ :\\ \vec{x},\\ t+\Delta t)=f_i^\textrm{tem
378378
- uses PCIe communication, so no SLI/Crossfire/NVLink/InfinityFabric required
379379
- single-node parallelization, so no MPI installation required
380380
- [GPUs don't even have to be from the same vendor](https://youtu.be/PscbxGVs52o), but similar memory capacity and bandwidth are recommended
381-
- 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)
381+
- 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)
382382
- supports [importing and voxelizing triangle meshes](DOCUMENTATION.md#loading-stl-files) from binary `.stl` files, with fast GPU voxelization
383383
- supports [exporting volumetric data](DOCUMENTATION.md#data-export) as binary `.vtk` files
384384
- supports [exporting triangle meshes](DOCUMENTATION.md#data-export) as binary `.vtk` files

make.sh

+24-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
1+
#!/bin/bash
2+
13
# command line argument(s): device ID(s); if empty, FluidX3D will automatically choose the fastest available device(s)
24

3-
#TARGET=Linux-X11 # compile on Linux with X11 graphics
4-
TARGET=Linux # compile on Linux (without X11)
5-
#TARGET=macOS # compile on macOS (without X11)
6-
#TARGET=Android # compile on Android (without X11)
5+
case "$(uname -a)" in # automatically detect operating system and X11 support on Linux
6+
Darwin*) target=macOS;;
7+
*Android) target=Android;;
8+
Linux*) if xhost >&/dev/null; then target=Linux-X11; else target=Linux; fi;;
9+
*) target=Linux;;
10+
esac
11+
echo -e "\033[92mInfo\033[0m: Detected Operating System: "${target}
12+
13+
#target=Linux-X11 # manually set to compile on Linux with X11 graphics
14+
#target=Linux # manually set to compile on Linux (without X11)
15+
#target=macOS # manually set to compile on macOS (without X11)
16+
#target=Android # manually set to compile on Android (without X11)
17+
18+
echo_and_execute() { echo "$@"; "$@"; }
719

820
if command -v make &>/dev/null; then # if make is available, compile FluidX3D with multiple CPU cores
9-
make $TARGET
21+
echo -e "\033[92mInfo\033[0m: Compiling with "$(nproc)" CPU cores."
22+
make ${target}
1023
else # else (make is not installed), compile FluidX3D with a single CPU core
24+
echo -e "\033[92mInfo\033[0m: Compiling with 1 CPU core. For faster multi-core compiling, install make with \"sudo apt install make\"."
1125
mkdir -p bin # create directory for executable
1226
rm -rf temp bin/FluidX3D # prevent execution of old executable if compiling fails
13-
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
14-
if [ $TARGET == Linux ]; then g++ src/*.cpp -o bin/FluidX3D -std=c++17 -pthread -I./src/OpenCL/include -L./src/OpenCL/lib -lOpenCL; fi
15-
if [ $TARGET == macOS ]; then g++ src/*.cpp -o bin/FluidX3D -std=c++17 -pthread -I./src/OpenCL/include -framework OpenCL; fi
16-
if [ $TARGET == Android ]; then g++ src/*.cpp -o bin/FluidX3D -std=c++17 -pthread -I./src/OpenCL/include -L/system/vendor/lib64 -lOpenCL; fi
27+
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
28+
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
29+
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
30+
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
1731
fi
1832

19-
bin/FluidX3D "$@" # run FluidX3D
33+
if [[ $? == 0 ]]; then bin/FluidX3D "$@"; fi # run FluidX3D only if last compilation was successful

makefile

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
MAKEFLAGS = -j$(nproc)
22
CC = g++
3-
CFLAGS = -std=c++17 -pthread
3+
CFLAGS = -std=c++17 -pthread -Wno-comment
44

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

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

13-
Linux-X11: LDFLAGS_X11 = -I./src/X11/include -L./src/X11/lib -lX11 -lXrandr
11+
Linux-X11 Linux: LDLIBS_OPENCL = -L./src/OpenCL/lib -lOpenCL
12+
macOS: LDLIBS_OPENCL = -framework OpenCL
13+
Android: LDLIBS_OPENCL = -L/system/vendor/lib64 -lOpenCL
14+
15+
Linux-X11: LDFLAGS_X11 = -I./src/X11/include
1416
Linux macOS Android: LDFLAGS_X11 =
1517

18+
Linux-X11: LDLIBS_X11 = -L./src/X11/lib -lX11 -lXrandr
19+
Linux macOS Android: LDLIBS_X11 =
20+
1621
Linux-X11 Linux macOS Android: bin/FluidX3D
1722

1823
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
1924
@mkdir -p bin
20-
$(CC) temp/*.o -o bin/FluidX3D $(CFLAGS) $(LDFLAGS_OPENCL) $(LDFLAGS_X11)
25+
$(CC) temp/*.o -o bin/FluidX3D $(CFLAGS) $(LDFLAGS_OPENCL) $(LDLIBS_OPENCL) $(LDFLAGS_X11) $(LDLIBS_X11)
2126

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

5459
.PHONY: clean
5560
clean:
56-
@rm -rf temp bin/FluidX3D
61+
@rm -rf temp bin/FluidX3D

0 commit comments

Comments
 (0)