From a5794e02daf92c1f01050e5b2800cd8fc3ccea80 Mon Sep 17 00:00:00 2001 From: Johan Ouwerkerk Date: Sun, 15 Dec 2019 17:15:28 +0100 Subject: [PATCH] Refactor: turn the base32 wrapper into a static library This library is meant for private use by Keysmith, to simplify linking to the base32 functionality in CMake files. --- autotests/CMakeLists.txt | 12 +++++------- autotests/base32/CMakeLists.txt | 9 +++++++++ autotests/{ => base32}/base32-decode.cpp | 2 +- src/CMakeLists.txt | 6 +++--- src/account.cpp | 2 +- src/base32/CMakeLists.txt | 8 ++++++++ src/{ => base32}/base32.cpp | 2 +- src/{ => base32}/base32.h | 0 8 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 autotests/base32/CMakeLists.txt rename autotests/{ => base32}/base32-decode.cpp (99%) create mode 100644 src/base32/CMakeLists.txt rename src/{ => base32}/base32.cpp (99%) rename src/{ => base32}/base32.h (100%) diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index f7b2542..4d3e488 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -1,12 +1,10 @@ include_directories(BEFORE ../src) +add_subdirectory(base32) add_subdirectory(validators) -set(Base32_UUT_SRCS ../src/base32.cpp) -set(Account_UUT_SRCS ../src/account.cpp ${Base32_UUT_SRCS}) -set(Test_DEP_LIBS Qt5::Core Qt5::Test) +set(Account_UUT_SRCS ../src/account.cpp) +set(Test_DEP_LIBS Qt5::Core Qt5::Test ${LIBOATH_LIBRARIES} base32_lib) -ecm_add_test(base32-decode.cpp ${Base32_UUT_SRCS} LINK_LIBRARIES ${Test_DEP_LIBS} ${LIBOATH_LIBRARIES} TEST_NAME base32-decode) - -ecm_add_test(hotp-generator-samples.cpp ${Account_UUT_SRCS} LINK_LIBRARIES ${Test_DEP_LIBS} ${LIBOATH_LIBRARIES} TEST_NAME hotp-generator-samples) -ecm_add_test(totp-generator-samples.cpp ${Account_UUT_SRCS} LINK_LIBRARIES ${Test_DEP_LIBS} ${LIBOATH_LIBRARIES} TEST_NAME totp-generator-samples) +ecm_add_test(hotp-generator-samples.cpp ${Account_UUT_SRCS} LINK_LIBRARIES ${Test_DEP_LIBS} TEST_NAME hotp-generator-samples) +ecm_add_test(totp-generator-samples.cpp ${Account_UUT_SRCS} LINK_LIBRARIES ${Test_DEP_LIBS} TEST_NAME totp-generator-samples) diff --git a/autotests/base32/CMakeLists.txt b/autotests/base32/CMakeLists.txt new file mode 100644 index 0000000..3494af8 --- /dev/null +++ b/autotests/base32/CMakeLists.txt @@ -0,0 +1,9 @@ + +set(Test_DEP_LIBS Qt5::Core Qt5::Test ${LIBOATH_LIBRARIES} base32_lib) +set(base32_lib_test_SRCS base32-decode.cpp) + +ecm_add_tests( + ${base32_lib_test_SRCS} + LINK_LIBRARIES ${Test_DEP_LIBS} + NAME_PREFIX base32- +) diff --git a/autotests/base32-decode.cpp b/autotests/base32/base32-decode.cpp similarity index 99% rename from autotests/base32-decode.cpp rename to autotests/base32/base32-decode.cpp index 2491e5c..86ed13c 100644 --- a/autotests/base32-decode.cpp +++ b/autotests/base32/base32-decode.cpp @@ -16,7 +16,7 @@ * * ****************************************************************************/ -#include "base32.h" +#include "base32/base32.h" #include #include diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ebfcbcf..f4be272 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,13 +1,13 @@ +add_subdirectory(base32) add_subdirectory(validators) set(keysmith_SRCS main.cpp accountmodel.cpp account.cpp - base32.cpp - ) +) -set(keysmith_internal_libs validator_lib) +set(keysmith_internal_libs base32_lib validator_lib) qt5_add_resources(RESOURCES resources.qrc) add_executable(org.kde.keysmith ${keysmith_SRCS} ${RESOURCES}) diff --git a/src/account.cpp b/src/account.cpp index 4aef5fb..a24490f 100644 --- a/src/account.cpp +++ b/src/account.cpp @@ -18,7 +18,7 @@ #include "account.h" -#include "base32.h" +#include "base32/base32.h" #include "oath_p.h" #include diff --git a/src/base32/CMakeLists.txt b/src/base32/CMakeLists.txt new file mode 100644 index 0000000..26b0dae --- /dev/null +++ b/src/base32/CMakeLists.txt @@ -0,0 +1,8 @@ +# +# This directory contains a wrapper around base32 functionality of the oath library +# + +set(base32_SRCS base32.cpp) + +add_library(base32_lib STATIC ${base32_SRCS}) +target_link_libraries(base32_lib Qt5::Core ${LIBOATH_LIBRARIES}) diff --git a/src/base32.cpp b/src/base32/base32.cpp similarity index 99% rename from src/base32.cpp rename to src/base32/base32.cpp index 833b9b3..39c29ea 100644 --- a/src/base32.cpp +++ b/src/base32/base32.cpp @@ -18,7 +18,7 @@ #include "base32.h" -#include "oath_p.h" +#include "../oath_p.h" #include diff --git a/src/base32.h b/src/base32/base32.h similarity index 100% rename from src/base32.h rename to src/base32/base32.h