Use private and public instead of legacy LINK_

This commit is contained in:
2025-08-01 20:05:12 +02:00
parent c1367e494e
commit 96817ee672
6 changed files with 80 additions and 88 deletions

View File

@@ -12,7 +12,7 @@ implementation, that exposes the library to a user.
```sh ```sh
cmake -B build -G Ninja cmake -B build -G Ninja
make -C build ninja -C build
``` ```
Pass `-DCMAKE_BUILD_TYPE=Debug` or `-DCMAKE_BUILD_TYPE=Release` to Pass `-DCMAKE_BUILD_TYPE=Debug` or `-DCMAKE_BUILD_TYPE=Release` to

View File

@@ -18,14 +18,18 @@ FetchContent_Declare(toml11
) )
FetchContent_MakeAvailable(toml11) FetchContent_MakeAvailable(toml11)
add_executable(katja-cli main.cpp component.hpp component.cpp) set(FTXUI_BUILD_MODULES ON)
target_sources(katja-cli PUBLIC FILE_SET all_my_modules TYPE CXX_MODULES FILES page.cpp)
add_executable(katja-cli main.cpp)
target_sources(katja-cli PUBLIC FILE_SET all_my_modules TYPE CXX_MODULES FILES
component.cpp page.cpp
)
target_include_directories(katja-cli PRIVATE ${Boost_INCLUDE_DIR}) target_include_directories(katja-cli PRIVATE ${Boost_INCLUDE_DIR})
target_link_libraries(katja-cli target_link_libraries(katja-cli
LINK_PUBLIC katja PUBLIC katja
LINK_PRIVATE ftxui::screen PRIVATE ftxui::screen
LINK_PRIVATE ftxui::dom PRIVATE ftxui::dom
LINK_PRIVATE ftxui::component PRIVATE ftxui::component
LINK_PRIVATE toml11::toml11 PRIVATE toml11::toml11
) )
set_target_properties(katja-cli PROPERTIES RUNTIME_OUTPUT_NAME katja) set_target_properties(katja-cli PROPERTIES RUNTIME_OUTPUT_NAME katja)

View File

@@ -3,18 +3,34 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/ */
#include "component.hpp" module;
#include <optional>
#include <sstream> #include <sstream>
namespace katja #include <ftxui/component/event.hpp>
#include <ftxui/component/component.hpp>
#include <ftxui/dom/elements.hpp>
#include "katja/repository.hpp"
export module component;
export namespace katja
{ {
PackageListBase::PackageListBase(const std::string& title, const std::vector<package_identifier>& packages) class PackageListBase : public ftxui::ComponentBase
{
std::string title;
const std::vector<package_identifier> packages;
std::optional<std::size_t> selected;
public:
PackageListBase(const std::string& title, const std::vector<package_identifier>& packages = {})
: title(title), packages(packages) : title(title), packages(packages)
{ {
} }
ftxui::Element PackageListBase::OnRender() ftxui::Element OnRender() override
{ {
std::vector<ftxui::Element> lines; std::vector<ftxui::Element> lines;
@@ -34,7 +50,7 @@ namespace katja
return ftxui::window(ftxui::text(summary.str()), ftxui::vbox(lines) | ftxui::yframe); return ftxui::window(ftxui::text(summary.str()), ftxui::vbox(lines) | ftxui::yframe);
} }
bool PackageListBase::OnEvent(ftxui::Event event) bool OnEvent(ftxui::Event event) override
{ {
if (event == ftxui::Event::ArrowDown) if (event == ftxui::Event::ArrowDown)
{ {
@@ -64,8 +80,9 @@ namespace katja
} }
return false; return false;
} }
};
ftxui::Component PackageList(const std::string& title, const std::vector<package_identifier>& packages) ftxui::Component PackageList(const std::string& title, const std::vector<package_identifier>& packages = {})
{ {
return ftxui::Make<PackageListBase>(title, packages); return ftxui::Make<PackageListBase>(title, packages);
} }

View File

@@ -1,33 +0,0 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <optional>
#include <ftxui/component/event.hpp>
#include <ftxui/component/component.hpp>
#include <ftxui/dom/elements.hpp>
#include "katja/repository.hpp"
namespace katja
{
class PackageListBase : public ftxui::ComponentBase
{
std::string title;
const std::vector<package_identifier> packages;
std::optional<std::size_t> selected;
public:
PackageListBase(const std::string& title, const std::vector<package_identifier>& packages = {});
ftxui::Element OnRender() override;
bool OnEvent(ftxui::Event event) override;
};
ftxui::Component PackageList(const std::string& title, const std::vector<package_identifier>& packages = {});
}

View File

@@ -7,10 +7,14 @@ module;
#include <algorithm> #include <algorithm>
#include "component.hpp" #include <ftxui/component/component.hpp>
#include "katja/repository.hpp"
export module page; export module page;
import component;
export namespace katja export namespace katja
{ {
class PageBase : public ftxui::ComponentBase class PageBase : public ftxui::ComponentBase

View File

@@ -13,7 +13,7 @@ foreach(test_source ${KATJA_TEST_SOURCES})
add_executable(${tester} ${test_source}) add_executable(${tester} ${test_source})
target_compile_definitions(${tester} PRIVATE "BOOST_TEST_DYN_LINK=1") target_compile_definitions(${tester} PRIVATE "BOOST_TEST_DYN_LINK=1")
target_link_libraries(${tester} LINK_PRIVATE katja Boost::unit_test_framework) target_link_libraries(${tester} PRIVATE katja Boost::unit_test_framework)
add_test(NAME ${test_name} COMMAND ${tester}) add_test(NAME ${test_name} COMMAND ${tester})
endforeach() endforeach()