From 7fa4ea24c3da970ef3223f6257efc99e6e184bb1 Mon Sep 17 00:00:00 2001 From: "Dr. Moritz Lehmann" Date: Sun, 31 Dec 2023 12:19:17 +0100 Subject: [PATCH] Added makefile for multi-core compiling if make is available, happy new year! --- .gitignore | 1 + DOCUMENTATION.md | 6 +++--- LICENSE.md | 2 +- make.sh | 23 +++++++++++++-------- makefile | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ src/shapes.hpp | 1 - 6 files changed, 72 insertions(+), 13 deletions(-) create mode 100644 makefile diff --git a/.gitignore b/.gitignore index 5ed02948..2f1f4696 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ bin/ temp/ +stl/ .vs/ FluidX3D.vcxproj.user \ No newline at end of file diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 43d3c436..83ec2a98 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -31,11 +31,11 @@ git clone https://github.com/ProjectPhysX/FluidX3D.git ./make.sh ``` - Compiling requires `C++17`, which is supported since `g++` version `8`. Check with `g++ --version`. -- If you use [`INTERACTIVE_GRAPHICS`](src/defines.hpp), change to the "[compile on Linux with X11](make.sh#L6)" command in [`make.sh`](make.sh#L6). +- If you use [`INTERACTIVE_GRAPHICS`](src/defines.hpp), change to the "[compile on Linux with X11 graphics](make.sh#L3)" command 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 the "[compile on macOS](make.sh#L9)" command in [`make.sh`](make.sh#L9). +- Select the "[compile on macOS](make.sh#L5)" command in [`make.sh`](make.sh#L5). - Compile and run with: ```bash chmod +x make.sh @@ -43,7 +43,7 @@ git clone https://github.com/ProjectPhysX/FluidX3D.git ``` ### Android -- Select the "[compile on Android](make.sh#L10)" command in [`make.sh`](make.sh#L10). +- Select the "[compile on Android](make.sh#L6)" command in [`make.sh`](make.sh#L6). - Compile and run with: ```bash chmod +x make.sh diff --git a/LICENSE.md b/LICENSE.md index 9cc692c7..97058561 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (c) 2022-2023 Dr. Moritz Lehmann +Copyright (c) 2022-2024 Dr. Moritz Lehmann Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files, to use this software for public research, education or personal use, and to alter it and redistribute it freely, subject to the following restrictions: diff --git a/make.sh b/make.sh index f978fe5c..a06d8252 100644 --- a/make.sh +++ b/make.sh @@ -1,12 +1,19 @@ # command line argument(s): device ID(s); if empty, FluidX3D will automatically choose the fastest available device(s) -mkdir -p bin # create directory for executable -rm -f ./bin/FluidX3D # prevent execution of old version if compiling fails +#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) -#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 # compile on Linux with X11 +if command -v make &>/dev/null; then # if make is available, compile FluidX3D with multiple CPU cores + make $TARGET +else # else (make is not installed), compile FluidX3D with a single CPU core + 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; 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 +fi -g++ ./src/*.cpp -o ./bin/FluidX3D -std=c++17 -pthread -I./src/OpenCL/include -L./src/OpenCL/lib -lOpenCL # compile on Linux (without X11) -#g++ ./src/*.cpp -o ./bin/FluidX3D -std=c++17 -pthread -I./src/OpenCL/include -framework OpenCL # compile on macOS (without X11) -#g++ ./src/*.cpp -o ./bin/FluidX3D -std=c++17 -pthread -I./src/OpenCL/include -L/system/vendor/lib64 -lOpenCL # compile on Android (without X11) - -./bin/FluidX3D "$@" # run FluidX3D +bin/FluidX3D "$@" # run FluidX3D \ No newline at end of file diff --git a/makefile b/makefile new file mode 100644 index 00000000..1f52384e --- /dev/null +++ b/makefile @@ -0,0 +1,52 @@ +MAKEFLAGS = -j$(nproc) +CC = g++ +CFLAGS = -std=c++17 -pthread + +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: LDFLAGS_X11 = -I./src/X11/include -L./src/X11/lib -lX11 +Linux macOS Android: LDFLAGS_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) + +temp/graphics.o: src/graphics.cpp src/defines.hpp src/graphics.hpp src/lodepng.hpp src/utilities.hpp make.sh + @mkdir -p temp + $(CC) -c src/graphics.cpp -o temp/graphics.o $(CFLAGS) $(LDFLAGS_X11) + +temp/info.o: src/info.cpp src/defines.hpp src/graphics.hpp src/info.hpp src/lbm.hpp src/lodepng.hpp src/opencl.hpp src/units.hpp src/utilities.hpp make.sh + @mkdir -p temp + $(CC) -c src/info.cpp -o temp/info.o $(CFLAGS) $(LDFLAGS_OPENCL) + +temp/kernel.o: src/kernel.cpp src/kernel.hpp src/lodepng.hpp src/utilities.hpp + @mkdir -p temp + $(CC) -c src/kernel.cpp -o temp/kernel.o $(CFLAGS) + +temp/lbm.o: src/lbm.cpp src/defines.hpp src/graphics.hpp src/info.hpp src/lbm.hpp src/lodepng.hpp src/opencl.hpp src/units.hpp src/utilities.hpp make.sh + @mkdir -p temp + $(CC) -c src/lbm.cpp -o temp/lbm.o $(CFLAGS) $(LDFLAGS_OPENCL) + +temp/lodepng.o: src/lodepng.cpp src/lodepng.hpp + @mkdir -p temp + $(CC) -c src/lodepng.cpp -o temp/lodepng.o $(CFLAGS) + +temp/main.o: src/main.cpp src/defines.hpp src/graphics.hpp src/info.hpp src/lbm.hpp src/lodepng.hpp src/opencl.hpp src/setup.hpp src/shapes.hpp src/units.hpp src/utilities.hpp make.sh + @mkdir -p temp + $(CC) -c src/main.cpp -o temp/main.o $(CFLAGS) $(LDFLAGS_OPENCL) + +temp/setup.o: src/setup.cpp src/defines.hpp src/graphics.hpp src/info.hpp src/lbm.hpp src/lodepng.hpp src/opencl.hpp src/setup.hpp src/shapes.hpp src/units.hpp src/utilities.hpp make.sh + @mkdir -p temp + $(CC) -c src/setup.cpp -o temp/setup.o $(CFLAGS) $(LDFLAGS_OPENCL) + +temp/shapes.o: src/shapes.cpp src/defines.hpp src/graphics.hpp src/info.hpp src/lbm.hpp src/lodepng.hpp src/opencl.hpp src/shapes.hpp src/units.hpp src/utilities.hpp make.sh + @mkdir -p temp + $(CC) -c src/shapes.cpp -o temp/shapes.o $(CFLAGS) $(LDFLAGS_OPENCL) + +.PHONY: clean +clean: + @rm -rf temp bin/FluidX3D \ No newline at end of file diff --git a/src/shapes.hpp b/src/shapes.hpp index 395128ef..c80950b7 100644 --- a/src/shapes.hpp +++ b/src/shapes.hpp @@ -1,6 +1,5 @@ #pragma once -#include "defines.hpp" #include "utilities.hpp" bool sphere(const uint x, const uint y, const uint z, const float3& p, const float r);