From bd60a28eefe5870456cea254f2ea055d810861ef Mon Sep 17 00:00:00 2001 From: jmsgrogan Date: Mon, 3 Oct 2022 07:45:10 +0100 Subject: [PATCH] Fix up build and start site generator. --- apps/CMakeLists.txt | 12 +- apps/website-generator.cpp | 129 ++++++++++++++++++ src/core/CommandLineArgs.cpp | 14 +- src/core/CommandLineArgs.h | 21 +-- src/image/CMakeLists.txt | 12 +- src/image/PngWriterImpl.h | 4 +- .../video/BasicVideoConverter.cpp | 0 src/video/BasicVideoConverter.cppcd | 0 src/video/BasicVideoConverter.h | 0 src/video/CMakeLists.txt | 58 ++++---- src/video/IVideoConverter.h | 0 src/windows/CMakeLists.txt | 92 +++++++------ test/CMakeLists.txt | 19 ++- test/image/TestPngWriter.cpp | 1 + test/video/TestVideoDecoder.cpp | 1 + 15 files changed, 267 insertions(+), 96 deletions(-) create mode 100644 apps/website-generator.cpp rename test/web/TestSvgWriter.cpp => src/video/BasicVideoConverter.cpp (100%) create mode 100644 src/video/BasicVideoConverter.cppcd create mode 100644 src/video/BasicVideoConverter.h create mode 100644 src/video/IVideoConverter.h diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index 2b2fc4a..fb5e6ed 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -27,4 +27,14 @@ target_link_libraries(sample_console PUBLIC console core network database geometry audio web) set_property(TARGET sample_console PROPERTY FOLDER apps) -set_property(TARGET sample_gui PROPERTY FOLDER apps) \ No newline at end of file +set_property(TARGET sample_gui PROPERTY FOLDER apps) + +# Website Generator +add_executable(website_generator website-generator.cpp) +#target_include_directories(website_generator PUBLIC +# "${PROJECT_SOURCE_DIR}/src/console" +# ) +target_link_libraries(website_generator PUBLIC core web) + +set_property(TARGET website_generator PROPERTY FOLDER apps) + diff --git a/apps/website-generator.cpp b/apps/website-generator.cpp new file mode 100644 index 0000000..e0d4251 --- /dev/null +++ b/apps/website-generator.cpp @@ -0,0 +1,129 @@ +#include "CommandLineArgs.h" + +#include +#include +#include +#include + +class GeneratorConfig +{ + +}; + +class ContentPage +{ +public: + + ContentPage(const std::string& filename) + : mFilename(filename) + { + + } + + std::string getFilename() const + { + return mFilename; + } + +private: + + std::string mFilename; +}; + + +class WebsiteGenerator +{ +public: + + void findProject(const std::string& searchPath) + { + const auto config_path = std::filesystem::path(searchPath) / "config.toml"; + if (std::filesystem::exists(config_path)) + { + mProjectPath = searchPath; + std::cout << "Found config.toml in " << searchPath << std::endl; + } + } + + void readConfig() + { + + } + + void parseContentFiles() + { + const auto content_dir = mProjectPath / "content"; + if (std::filesystem::is_directory(content_dir)) + { + std::cout << "checking " << content_dir << std::endl; + const auto pages_dir = content_dir / "pages"; + if (std::filesystem::is_directory(pages_dir)) + { + std::cout << "checking " << pages_dir << std::endl; + for (const auto& entry : std::filesystem::directory_iterator(pages_dir)) + { + if (std::filesystem::is_regular_file(entry) && entry.path().extension() == ".md") + { + mPages.push_back(ContentPage(entry.path())); + } + } + } + } + else + { + std::cout << "nope in " << content_dir << std::endl; + } + + for(const auto& page : mPages) + { + std::cout << "Got page " << page.getFilename() << std::endl; + } + + } + + void parseTemplateFiles() + { + + } + + void doSubstitutions() + { + + } + + void write() + { + + } + + +private: + + std::filesystem::path mProjectPath; + GeneratorConfig mConfig; + std::vector mPages; +}; + + +int main(int argc, char *argv[]) +{ + auto args = CommandLineArgs::Create(); + args->process(argc, argv); + args->recordLaunchPath(); + + WebsiteGenerator generator; + generator.findProject(args->getArg(1)); + + generator.readConfig(); + + // Find and process project files + generator.parseContentFiles(); + + // Find template files + + // Substitute template files + + + + return 0; +} diff --git a/src/core/CommandLineArgs.cpp b/src/core/CommandLineArgs.cpp index 80eaa6f..a742e02 100644 --- a/src/core/CommandLineArgs.cpp +++ b/src/core/CommandLineArgs.cpp @@ -7,22 +7,22 @@ CommandLineArgs::CommandLineArgs() } -std::unique_ptr CommandLineArgs::CreateUnique() +std::unique_ptr CommandLineArgs::Create() { return std::make_unique(); } -std::filesystem::path CommandLineArgs::GetLaunchPath() +std::filesystem::path CommandLineArgs::getLaunchPath() { return mLaunchPath; } -void CommandLineArgs::RecordLaunchPath() +void CommandLineArgs::recordLaunchPath() { mLaunchPath = std::filesystem::current_path(); } -void CommandLineArgs::Process(int argc, char *argv[]) +void CommandLineArgs::process(int argc, char *argv[]) { for(int idx=0; idx& args) +void CommandLineArgs::process(const std::vector& args) { mArugments = args; } -std::size_t CommandLineArgs::GetNumberOfArgs() const +std::size_t CommandLineArgs::getNumberOfArgs() const { return mArugments.size(); } -std::string CommandLineArgs::GetArg(std::size_t index) const +std::string CommandLineArgs::getArg(std::size_t index) const { if(index mArugments; - std::filesystem::path mLaunchPath; - public: CommandLineArgs(); - static std::unique_ptr CreateUnique(); + static std::unique_ptr Create(); - void RecordLaunchPath(); + std::filesystem::path getLaunchPath(); - std::filesystem::path GetLaunchPath(); + std::size_t getNumberOfArgs() const; - void Process(int argc, char *argv[]); + std::string getArg(std::size_t index) const; - void Process(const std::vector& args); + void process(int argc, char *argv[]); - std::size_t GetNumberOfArgs() const; + void process(const std::vector& args); - std::string GetArg(std::size_t index) const; + void recordLaunchPath(); + +private: + std::vector mArugments; + std::filesystem::path mLaunchPath; }; using CommandLineArgsUPtr = std::unique_ptr; diff --git a/src/image/CMakeLists.txt b/src/image/CMakeLists.txt index aaf7b16..bcfa8cf 100644 --- a/src/image/CMakeLists.txt +++ b/src/image/CMakeLists.txt @@ -17,13 +17,13 @@ list(APPEND image_DEFINES "") find_package(PNG QUIET) if(PNG_FOUND) -list(APPEND image_LIBS PNG::PNG) -list(APPEND image_LIB_INCLUDES - PngWriterLibPng.cpp - ) -list(APPEND image_DEFINES HAS_LIBPNG) + list(APPEND image_LIBS PNG::PNG) + list(APPEND image_LIB_INCLUDES + PngWriterLibPng.cpp + ) + list(APPEND image_DEFINES HAS_LIBPNG) else() -message(STATUS "LIBRARY CHECK: libPNG not found - disabling libPNG based image i/o.") + message(STATUS "LIBRARY CHECK: libPNG not found - disabling libPNG based image i/o.") endif() diff --git a/src/image/PngWriterImpl.h b/src/image/PngWriterImpl.h index 2efc2da..81dd933 100644 --- a/src/image/PngWriterImpl.h +++ b/src/image/PngWriterImpl.h @@ -8,7 +8,9 @@ class Image; class PngWriterImpl { public: + virtual ~PngWriterImpl() = default; + virtual void setPath(const std::string& path) = 0; virtual void write(const std::unique_ptr& image) const = 0; -}; \ No newline at end of file +}; diff --git a/test/web/TestSvgWriter.cpp b/src/video/BasicVideoConverter.cpp similarity index 100% rename from test/web/TestSvgWriter.cpp rename to src/video/BasicVideoConverter.cpp diff --git a/src/video/BasicVideoConverter.cppcd b/src/video/BasicVideoConverter.cppcd new file mode 100644 index 0000000..e69de29 diff --git a/src/video/BasicVideoConverter.h b/src/video/BasicVideoConverter.h new file mode 100644 index 0000000..e69de29 diff --git a/src/video/CMakeLists.txt b/src/video/CMakeLists.txt index 97949c2..aca3a9d 100644 --- a/src/video/CMakeLists.txt +++ b/src/video/CMakeLists.txt @@ -1,40 +1,50 @@ list(APPEND video_HEADERS Video.h - FfmpegInterface.h + BasicVideoConverter.h + IVideoConverter.h ) list(APPEND video_LIB_INCLUDES Video.cpp - FfmegInterface.cpp + BasicVideoConverter.cpp ) + +list(APPEND video_DEFINES "") + +find_package(PkgConfig QUIET) +set(_HAS_FFMPEG Off) +if(PkgConfig) + pkg_check_modules(LIBAV IMPORTED_TARGET + libavdevice + libavfilter + libavformat + libavcodec + libswresample + libswscale + libavutil + ) + list(APPEND video_LIBS PkgConfig::LIBAV) + list(APPEND video_HEADERS + FfmpegInterface.h + ) + list(APPEND video_LIB_INCLUDES + FfmegInterface.cpp + ) + list(APPEND video_DEFINES "HAS_FFMPEG") + set(_HAS_FFMPEG ON) +else() + message(STATUS "LIBRARY CHECK: PkgConfig not found - disabling ffmpeg based video i/o.") +endif() + +set(HAS_FFMPEG ${_HAS_FFMPEG} CACHE BOOL "Can build with FFMPEG") add_library(video SHARED ${video_LIB_INCLUDES} ${video_HEADERS}) -target_include_directories(video PUBLIC - "${CMAKE_CURRENT_SOURCE_DIR}" - ) +target_include_directories(video PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") set_target_properties( video PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON ) list(APPEND video_LIBS image) -find_package(PkgConfig QUIET) - -if(PkgConfig) -pkg_check_modules(LIBAV IMPORTED_TARGET - libavdevice - libavfilter - libavformat - libavcodec - libswresample - libswscale - libavutil -) -list(APPEND video_LIBS PkgConfig::LIBAV) -else() -message(STATUS "LIBRARY CHECK: PkgConfig not found - disabling ffmpeg based video i/o.") -endif() - target_link_libraries( video PUBLIC ${video_LIBS}) - -set_property(TARGET video PROPERTY FOLDER src) \ No newline at end of file +set_property(TARGET video PROPERTY FOLDER src) diff --git a/src/video/IVideoConverter.h b/src/video/IVideoConverter.h new file mode 100644 index 0000000..e69de29 diff --git a/src/windows/CMakeLists.txt b/src/windows/CMakeLists.txt index 935a2c5..94d6fe9 100644 --- a/src/windows/CMakeLists.txt +++ b/src/windows/CMakeLists.txt @@ -1,59 +1,68 @@ set (platform_INCLUDES "") set (platform_LIBS "") -if(UNIX) -list(APPEND platform_INCLUDES - ui_interfaces/x11/XcbInterface.cpp - ui_interfaces/x11/XcbEventInterface.cpp - ui_interfaces/x11/XcbWindow.cpp - ui_interfaces/x11/XcbScreen.cpp - ui_interfaces/x11/XcbWindowInterface.cpp - ui_interfaces/x11/XcbLayerInterface.cpp - ui_interfaces/x11/XcbTextInterface.cpp - ui_interfaces/x11/XcbKeyboard.cpp - ui_interfaces/x11/GlxInterface.cpp - - ui_interfaces/wayland/WaylandWindowInterface.cpp - ui_interfaces/wayland/WaylandSurface.cpp - ui_interfaces/wayland/WaylandBuffer.cpp - ) +set(_HAS_WAYLAND Off) -list(APPEND platform_LIBS - X11 X11-xcb xcb ) - +if(UNIX) + list(APPEND platform_INCLUDES + ui_interfaces/x11/XcbInterface.cpp + ui_interfaces/x11/XcbEventInterface.cpp + ui_interfaces/x11/XcbWindow.cpp + ui_interfaces/x11/XcbScreen.cpp + ui_interfaces/x11/XcbWindowInterface.cpp + ui_interfaces/x11/XcbLayerInterface.cpp + ui_interfaces/x11/XcbTextInterface.cpp + ui_interfaces/x11/XcbKeyboard.cpp + ui_interfaces/x11/GlxInterface.cpp + ) + + list(APPEND platform_LIBS + X11 X11-xcb xcb ) + find_path( WAYLAND_CLIENT_INCLUDE_DIR NAMES wayland-client.h - ) + ) + list(APPEND WAYLAND_INCLUDE_DIRS ${WAYLAND_CLIENT_INCLUDE_DIR}) find_path( WAYLAND_EXTENSIONS_INCLUDE_DIR NAMES xdg-shell-client-protocol.h HINTS ENV WAYLAND_EXTENSION_DIR - ) - - find_library( - WAYLAND_CLIENT_LIBRARY - NAMES wayland-client libwayland-client - ) - - list(APPEND platform_INCLUDES - ui_interfaces/win32/Win32UIInterface.h - ${WAYLAND_EXTENSIONS_INCLUDE_DIR}/xdg-shell-protocol.cpp - ) + ) + if(NOT ${WAYLAND_EXTENSIONS_INCLUDE_DIR-NOTFOUND}) + find_library( + WAYLAND_CLIENT_LIBRARY + NAMES wayland-client libwayland-client + ) + + list(APPEND WAYLAND_INCLUDE_DIRS ${WAYLAND_EXTENSIONS_INCLUDE_DIR}) + + list(APPEND platform_INCLUDES + ui_interfaces/wayland/WaylandWindowInterface.cpp + ui_interfaces/wayland/WaylandSurface.cpp + ui_interfaces/wayland/WaylandBuffer.cpp + ${WAYLAND_EXTENSIONS_INCLUDE_DIR}/xdg-shell-protocol.cpp + ) + set(_HAS_WAYLAND ON) + else() + message(STATUS "Wayland Extensions Header not found - not building Wayland support") + endif() else() -list(APPEND platform_INCLUDES - ui_interfaces/win32/Win32UIInterface.h - ui_interfaces/win32/Win32UIInterface.cpp - ui_interfaces/win32/Win32WindowInterface.h - ui_interfaces/win32/Win32WindowInterface.cpp - ui_interfaces/win32/Win32Window.h - ui_interfaces/win32/Win32Window.cpp - ) + list(APPEND platform_INCLUDES + ui_interfaces/win32/Win32UIInterface.h + ui_interfaces/win32/Win32UIInterface.cpp + ui_interfaces/win32/Win32WindowInterface.h + ui_interfaces/win32/Win32WindowInterface.cpp + ui_interfaces/win32/Win32Window.h + ui_interfaces/win32/Win32Window.cpp + ) endif() +set(HAS_WAYLAND ${_HAS_WAYLAND} CACHE BOOL "Can build with Wayland") + list(APPEND windows_LIB_INCLUDES managers/WindowManager.cpp managers/DesktopManager.cpp @@ -73,11 +82,10 @@ target_include_directories(windows PUBLIC "${PROJECT_SOURCE_DIR}/src/graphics" "${PROJECT_SOURCE_DIR}/src/ui_elements" "${PROJECT_SOURCE_DIR}/src/ui_elements/widgets" - ${WAYLAND_CLIENT_INCLUDE_DIR} - ${WAYLAND_EXTENSIONS_INCLUDE_DIR} + ${WAYLAND_INCLUDE_DIRS} ) target_link_libraries(windows PUBLIC ${platform_LIBS} core geometry graphics ui_elements ${WAYLAND_CLIENT_LIBRARY}) set_property(TARGET windows PROPERTY FOLDER src) -set_target_properties( windows PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON ) \ No newline at end of file +set_target_properties( windows PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON ) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 860e3a7..6072d9e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -22,12 +22,21 @@ list(APPEND TestFiles image/TestPngWriter.cpp network/TestNetworkManagerClient.cpp network/TestNetworkManagerServer.cpp - publishing/TestPdfWriter.cpp - video/TestVideoDecoder.cpp - windows/TestWaylandWindow.cpp - web/TestMarkdownParser.cpp - web/TestSvgWriter.cpp + publishing/TestPdfWriter.cpp + web/TestMarkdownParser.cpp web/TestXmlParser.cpp) + +if (${HAS_FFMPEG}) +list(APPEND TestFiles + video/TestVideoDecoder.cpp +) +endif() + +if (${HAS_WAYLAND}) +list(APPEND TestFiles + windows/TestWaylandWindow.cpp + ) +endif() find_package(PkgConfig) pkg_check_modules(DBUS dbus-1) diff --git a/test/image/TestPngWriter.cpp b/test/image/TestPngWriter.cpp index 0786e0f..b877858 100644 --- a/test/image/TestPngWriter.cpp +++ b/test/image/TestPngWriter.cpp @@ -1,5 +1,6 @@ #include "Image.h" #include "PngWriter.h" +#include "PngWriterImpl.h" #include diff --git a/test/video/TestVideoDecoder.cpp b/test/video/TestVideoDecoder.cpp index 30e3913..45cbc1a 100644 --- a/test/video/TestVideoDecoder.cpp +++ b/test/video/TestVideoDecoder.cpp @@ -2,6 +2,7 @@ #include "Image.h" #include "FfmpegInterface.h" #include "PngWriter.h" +#include "PngWriterImpl.h" #include int main()