make it compile with cmake.
This commit is contained in:
62
Makefile-Self
Normal file
62
Makefile-Self
Normal file
@ -0,0 +1,62 @@
|
||||
TARGET_EXEC := sim
|
||||
|
||||
BUILD_DIR := ./build
|
||||
SRC_DIR := ./src
|
||||
INC_DIR := ./include
|
||||
SHADER_DIR := ./kernels
|
||||
SHADER_EXT := 'cl'
|
||||
|
||||
# Find all the C and C++ files we want to compile
|
||||
SRCS := $(shell find $(SRC_DIR) -name '*.cpp')
|
||||
GLSLS := $(shell find $(SHADER_DIR) -name '*.cl')
|
||||
|
||||
# Prepends BUILD_DIR and appends .o to every src file
|
||||
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
|
||||
spirvs := $(glsls:%.$(shader_ext)=$(build_dir)/%.sphv)
|
||||
|
||||
# String substitution (suffix version without %).
|
||||
DEPS := $(OBJS:.o=.d)
|
||||
|
||||
# Every folder in ./include will need to be passed to GCC so that it can find header files
|
||||
INC_DIRS := $(shell find $(INC_DIR) -type d)
|
||||
# Add a prefix to INC_DIRS. So moduleA would become -ImoduleA. GCC understands this -I flag
|
||||
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
|
||||
|
||||
LIBS := OpenCL
|
||||
|
||||
LDFLAGS := $(addprefix -l,$(LIBS))
|
||||
|
||||
# The -MMD and -MP flags together generate Makefiles for us! we use c++ 26
|
||||
CPPFLAGS := -Wall -Wextra $(INC_FLAGS) -L/libs -MMD -MP -std=c++20
|
||||
|
||||
#set flags for kernel compiling
|
||||
GPU_VENDOR := glxinfo | grep -E "OpenGL vendor | OpenGL renderer" | cut -d" " -f4
|
||||
ARCH := uname -m
|
||||
ifeq ($(GPU_VENDOR),"AMD")
|
||||
CLFLAGS := --target=amdgcn-amd-amdhsa -mcpu=gfx900
|
||||
else ifeq ($(GPU_VENDOR),"NVIDIA")
|
||||
CLFLAGS := --target=nvtpx64-unkown-unkown
|
||||
else ifeq ($(ARCH), "x86_64")
|
||||
CLFLAGS := --target=spirv64
|
||||
else
|
||||
CLFLAGS := --target=spirv32
|
||||
endif
|
||||
|
||||
CXX := clang -v
|
||||
|
||||
# The final build step.
|
||||
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
|
||||
$(CXX) $(OBJS) -o $@ $(LDFLAGS)
|
||||
|
||||
# Build step for C++ source
|
||||
$(BUILD_DIR)/%.cpp.o: %.cpp $(SPIRVS)
|
||||
mkdir -p $(dir $@)
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@ $(LDFLAGS)
|
||||
|
||||
#build the shaders
|
||||
$(BUILD_DIR)/%.spv: %.cl
|
||||
mkdir -p $(dir $@)
|
||||
$(CXX) $(CLFLAGS) -c $< -o $@
|
||||
|
||||
run: $(BUILD_DIR)/$(TARGET_EXEC)
|
||||
./$(BUILD_DIR)/$(TARGET_EXEC)
|
||||
Reference in New Issue
Block a user