From 9144cd53be930b37235ae552a92b5d2aa51e9325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20B=C3=B6ckenkamp?= Date: Wed, 9 Feb 2022 12:45:26 +0100 Subject: [PATCH 1/2] Add CMake compatibility, cleanup/improve project structure --- .gitignore | 1 + CMakeLists.txt | 17 +++++++++++++++++ Makefile | 16 ++++++++-------- compile-and-run-test | 2 +- base64.h => include/cpp-base64/base64.h | 0 base64.cpp => src/base64.cpp | 2 +- measure-time.cpp => test/measure-time.cpp | 2 +- test-google.cpp => test/test-google.cpp | 2 +- test.cpp => test/test.cpp | 2 +- 9 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 CMakeLists.txt rename base64.h => include/cpp-base64/base64.h (100%) rename base64.cpp => src/base64.cpp (99%) rename measure-time.cpp => test/measure-time.cpp (99%) rename test-google.cpp => test/test-google.cpp (98%) rename test.cpp => test/test.cpp (99%) diff --git a/.gitignore b/.gitignore index 63cddfe..6d3139b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ test-base64 .wsjcpp/* *.o *.exe +build/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..c76b25b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.12) +project("cpp-base64" LANGUAGES CXX VERSION 2.0.8 + DESCRIPTION "Base64 encoding and decoding with C++" + HOMEPAGE_URL "https://github.com/CodeFinder2/cpp-base64") +include(GNUInstallDirs) + +add_library(${PROJECT_NAME} src/base64.cpp) +target_include_directories(${PROJECT_NAME} SYSTEM + PUBLIC $ + $) + +install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME} DESTINATION include) +install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Config + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +export(TARGETS ${PROJECT_NAME} FILE ${PROJECT_NAME}Config.cmake) diff --git a/Makefile b/Makefile index 126e2ca..23a3846 100644 --- a/Makefile +++ b/Makefile @@ -36,14 +36,14 @@ base64-test-11: base64-11.o test-11.o base64-test-17: base64-17.o test-17.o g++ base64-17.o test-17.o -o $@ -base64-11.o: base64.cpp base64.h - g++ -std=c++11 $(WARNINGS) -c base64.cpp -o base64-11.o +base64-11.o: src/base64.cpp include/cpp-base64/base64.h + g++ -std=c++11 $(WARNINGS) -c src/base64.cpp -o base64-11.o -I include -base64-17.o: base64.cpp base64.h - g++ -std=c++17 $(WARNINGS) -c base64.cpp -o base64-17.o +base64-17.o: src/base64.cpp include/cpp-base64/base64.h + g++ -std=c++17 $(WARNINGS) -c src/base64.cpp -o base64-17.o -I include -test-11.o: test.cpp - g++ -std=c++11 $(WARNINGS) -c test.cpp -o test-11.o +test-11.o: test/test.cpp + g++ -std=c++11 $(WARNINGS) -c test/test.cpp -o test-11.o -I include -test-17.o: test.cpp - g++ -std=c++17 $(WARNINGS) -c test.cpp -o test-17.o +test-17.o: test/test.cpp + g++ -std=c++17 $(WARNINGS) -c test/test.cpp -o test-17.o -I include diff --git a/compile-and-run-test b/compile-and-run-test index 1ab5985..9955487 100755 --- a/compile-and-run-test +++ b/compile-and-run-test @@ -1,2 +1,2 @@ -g++ test.cpp base64.cpp -o test-base64 +g++ test/test.cpp src/base64.cpp -o test-base64 -I include ./test-base64 diff --git a/base64.h b/include/cpp-base64/base64.h similarity index 100% rename from base64.h rename to include/cpp-base64/base64.h diff --git a/base64.cpp b/src/base64.cpp similarity index 99% rename from base64.cpp rename to src/base64.cpp index 7666ef8..8e58efe 100644 --- a/base64.cpp +++ b/src/base64.cpp @@ -31,7 +31,7 @@ */ -#include "base64.h" +#include "cpp-base64/base64.h" #include #include diff --git a/measure-time.cpp b/test/measure-time.cpp similarity index 99% rename from measure-time.cpp rename to test/measure-time.cpp index 91d4df9..46bb73b 100644 --- a/measure-time.cpp +++ b/test/measure-time.cpp @@ -1,4 +1,4 @@ -#include "base64.h" +#include "../include/cpp-base64/base64.h" #include #include diff --git a/test-google.cpp b/test/test-google.cpp similarity index 98% rename from test-google.cpp rename to test/test-google.cpp index bc5090e..261257a 100644 --- a/test-google.cpp +++ b/test/test-google.cpp @@ -1,4 +1,4 @@ -#include "base64.h" +#include "../include/cpp-base64/base64.h" #include #include diff --git a/test.cpp b/test/test.cpp similarity index 99% rename from test.cpp rename to test/test.cpp index 0b641cd..d5885b6 100644 --- a/test.cpp +++ b/test/test.cpp @@ -1,4 +1,4 @@ -#include "base64.h" +#include #include int main() { From 36eebde2754b6f9b94da4af0a9b0a42697263e0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20B=C3=B6ckenkamp?= Date: Wed, 8 Feb 2023 12:59:33 +0100 Subject: [PATCH 2/2] Fix Makefile (thanks to @ntwerdochlib for the comment) --- .gitignore | 2 ++ Makefile | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 6d3139b..424e082 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ test-base64 *.o *.exe build/ +base64-test-11 +base64-test-17 diff --git a/Makefile b/Makefile index 23a3846..174815d 100644 --- a/Makefile +++ b/Makefile @@ -27,8 +27,8 @@ WARNINGS= \ -fdiagnostics-show-option test: base64-test-11 base64-test-17 - base64-test-11 - base64-test-17 + -./base64-test-11 + -./base64-test-17 base64-test-11: base64-11.o test-11.o g++ base64-11.o test-11.o -o $@