From 9bec46cc1fb6a03d320955054a10154264a3d4ac Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Fri, 21 Mar 2025 01:04:57 +0100 Subject: [PATCH] Split cmake files between directories --- CMakeLists.txt | 19 ++++--------------- cli/CMakeLists.txt | 4 ++++ katja/database.cpp | 2 +- tests/CMakeLists.txt | 15 +++++++++++++++ tests/database.cpp | 14 ++++++++++++++ tests/repository.cpp | 13 +++++++++++++ tests/tester.cpp | 9 --------- 7 files changed, 51 insertions(+), 25 deletions(-) create mode 100644 cli/CMakeLists.txt create mode 100644 tests/CMakeLists.txt create mode 100644 tests/database.cpp create mode 100644 tests/repository.cpp delete mode 100644 tests/tester.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b2b97d0..aef0836 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,25 +7,14 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS 1) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_CXX_STANDARD 17) -find_package(Boost CONFIG COMPONENTS unit_test_framework REQUIRED) - -add_library(backend +add_library(katja katja/database.cpp include/katja/database.hpp katja/sbo.cpp include/katja/sbo.hpp katja/repository.cpp include/katja/repository.hpp ) -target_include_directories(backend PRIVATE include ${Boost_INCLUDE_DIR}) - -add_executable(katja cli/main.cpp) -target_include_directories(katja PRIVATE include ${Boost_INCLUDE_DIR}) -target_link_libraries(katja LINK_PUBLIC backend) +include_directories(include ${Boost_INCLUDE_DIR}) +add_subdirectory(cli) if(BUILD_TESTING) - add_executable(tester tests/tester.cpp) - - target_include_directories(tester PRIVATE include ${Boost_INCLUDE_DIR}) - target_compile_definitions(tester PRIVATE "BOOST_TEST_DYN_LINK=1") - target_link_libraries(tester LINK_PRIVATE backend Boost::unit_test_framework) - - add_test(NAME tester COMMAND tester) + add_subdirectory(tests) endif() diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt new file mode 100644 index 0000000..11f92ce --- /dev/null +++ b/cli/CMakeLists.txt @@ -0,0 +1,4 @@ +add_executable(katja-cli main.cpp) +target_include_directories(katja-cli PRIVATE ${Boost_INCLUDE_DIR}) +target_link_libraries(katja-cli LINK_PUBLIC katja) +set_target_properties(katja-cli PROPERTIES RUNTIME_OUTPUT_NAME katja) diff --git a/katja/database.cpp b/katja/database.cpp index 11e3730..fb21d1f 100644 --- a/katja/database.cpp +++ b/katja/database.cpp @@ -45,7 +45,7 @@ namespace katja database_package::database_package(std::string&& name, std::string&& version, std::string&& architecture, std::string&& build_tag) - : name(name), version(version), architecture(version), build_tag(build_tag) + : name(name), version(version), architecture(architecture), build_tag(build_tag) { } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..33ddc98 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,15 @@ +find_package(Boost CONFIG COMPONENTS unit_test_framework REQUIRED) + +file(GLOB KATJA_TEST_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) + +foreach(test_source ${KATJA_TEST_SOURCES}) + get_filename_component(test_name ${test_source} NAME_WE) + set(tester ${test_name}-tester) + + add_executable(${tester} ${test_source}) + + target_compile_definitions(${tester} PRIVATE "BOOST_TEST_DYN_LINK=1") + target_link_libraries(${tester} LINK_PRIVATE katja Boost::unit_test_framework) + + add_test(NAME ${test_name} COMMAND ${tester}) +endforeach() diff --git a/tests/database.cpp b/tests/database.cpp new file mode 100644 index 0000000..d895804 --- /dev/null +++ b/tests/database.cpp @@ -0,0 +1,14 @@ +#define BOOST_TEST_MODULE database tests + +#include +#include "katja/database.hpp" + +BOOST_AUTO_TEST_CASE(generate_package_identifier) +{ + katja::database_package actual("libarchive-3.7.8-i586-1_slack15.0"); + + BOOST_TEST(actual.name == "libarchive"); + BOOST_TEST(actual.version == "3.7.8"); + BOOST_TEST(actual.architecture == "i586"); + BOOST_TEST(actual.build_tag == "1_slack15.0"); +} diff --git a/tests/repository.cpp b/tests/repository.cpp new file mode 100644 index 0000000..1f1fb19 --- /dev/null +++ b/tests/repository.cpp @@ -0,0 +1,13 @@ +#define BOOST_TEST_MODULE repository tests + +#include +#include "katja/repository.hpp" + +BOOST_AUTO_TEST_CASE(construct_valid_database_package) +{ + katja::package_identifier given{ "libarchive", "3.7.8", "i586", "slackware" }; + std::string actual = given.to_string(); + std::string expected = "libarchive;3.7.8;i586;slackware"; + + BOOST_TEST(actual == expected); +} diff --git a/tests/tester.cpp b/tests/tester.cpp deleted file mode 100644 index a464447..0000000 --- a/tests/tester.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#define BOOST_TEST_MODULE unit tests - -#include -#include "katja/repository.hpp" - -BOOST_AUTO_TEST_CASE(construct_valid_database_package) -{ - BOOST_TEST(true); -}