From 6d41159e36958fd96f656cbe787981635b6ed93e Mon Sep 17 00:00:00 2001 From: Marco Cetica Date: Thu, 9 Nov 2023 10:31:50 +0100 Subject: [PATCH] Migrated to CMake --- .github/workflows/dc.yml | 7 +++++-- .gitignore | 3 +++ CMakeLists.txt | 16 +++++++++++++++ Makefile | 42 ---------------------------------------- README.md | 9 +++++---- src/CMakeLists.txt | 17 ++++++++++++++++ 6 files changed, 46 insertions(+), 48 deletions(-) create mode 100644 CMakeLists.txt delete mode 100644 Makefile create mode 100644 src/CMakeLists.txt diff --git a/.github/workflows/dc.yml b/.github/workflows/dc.yml index f1e3b9b..f2d0c11 100644 --- a/.github/workflows/dc.yml +++ b/.github/workflows/dc.yml @@ -8,7 +8,10 @@ jobs: build: runs-on: ubuntu-latest steps: - - name: checkout repo + - name: Checkout repo uses: actions/checkout@main - name: Build dc - run: make clean all + run: | + mkdir build && cd build + cmake .. + make diff --git a/.gitignore b/.gitignore index 69f3152..98fd049 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,6 @@ dc # Manual dc.1 + +# CMake folders +build diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..3e68fda --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.12) +project(dc) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \ + -Wall -Wextra -Werror -pedantic-errors \ + -fstack-protector-strong -D_FORTIFY_SOURCE=2 \ + -Wformat-security -fsanitize=address -fsanitize=undefined \ + -fstack-clash-protection -Wundef -Wshadow -Wpointer-arith \ + -Wcast-align -Wwrite-strings -ftrapv -std=c++20 -O3") + +add_executable(dc main.cpp) +include_directories(src) +add_subdirectory(src) + +target_link_libraries(dc src) diff --git a/Makefile b/Makefile deleted file mode 100644 index 63ba0e1..0000000 --- a/Makefile +++ /dev/null @@ -1,42 +0,0 @@ -TARGET = dc -CC = clang++ -#CC = g++ -CXXFLAGS = -Wall -Wextra -Werror -pedantic-errors -fstack-protector-strong \ - -D_FORTIFY_SOURCE=2 -Wformat-security -fsanitize=address -fsanitize=undefined \ - -fstack-clash-protection -Wundef -Wshadow -Wpointer-arith \ - -Wcast-align -Wwrite-strings -ftrapv -std=c++20 -O3 - -all: $(TARGET) - -$(TARGET): main.o eval.a math.a stack.a macro.a - $(CC) $(CXXFLAGS) $^ -o $@ - -main.o: main.cpp - $(CC) $(CXXFLAGS) -c $< -o $@ - -eval.a: eval.o - ar rcs $@ $^ - -math.a: math.o - ar rcs $@ $^ - -stack.a: stack.o - ar rcs $@ $^ - -macro.a: macro.o - ar rcs $@ $^ - -eval.o: src/eval.cpp - $(CC) $(CXXFLAGS) -c -o $@ $< - -math.o: src/math.cpp - $(CC) $(CXXFLAGS) -c -o $@ $< - -stack.o: src/stack.cpp - $(CC) $(CXXFLAGS) -c -o $@ $< - -macro.o: src/macro.cpp - $(CC) $(CXXFLAGS) -c -o $@ $< - -clean: - rm -f *.o *.a src/*.gch $(TARGET) diff --git a/README.md b/README.md index 6836d0f..4620016 100644 --- a/README.md +++ b/README.md @@ -47,12 +47,13 @@ Some of the supported features are: And much more. You can find the complete manual [here](https://github.com/ice-bit/dc/blob/master/man.md). ## Installation -`dc` is written in C++20 without using any additional dependency. In order to build it, issue the following commands: +`dc` is written in C++20 without using any additional dependency. In order to build it, install a recent version of CMake and issue +the following command: ```sh -$> make clean all +$> mkdir build && cd build +$> cmake .. && make ``` - -A new binary called `dc` will be created in your local folder. +A new statically-compiled binary called `dc` will be created in your local folder. To generate a man page from the `man.md` document, use the following command(note: needs pandoc): ```sh diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..35770f4 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,17 @@ +project(src) + +set(HEADER_FILES + eval.h + macro.h + math.h + operation.h + stack.h + types.h) + +set(SOURCE_FILES + eval.cpp + macro.cpp + math.cpp + stack.cpp) + +add_library(src STATIC ${SOURCE_FILES} ${HEADER_FILES})