Fix up build and start site generator.

This commit is contained in:
jmsgrogan 2022-10-03 07:45:10 +01:00
parent d471609712
commit bd60a28eef
15 changed files with 267 additions and 96 deletions

View file

@ -28,3 +28,13 @@ target_link_libraries(sample_console PUBLIC console core network
set_property(TARGET sample_console PROPERTY FOLDER apps) set_property(TARGET sample_console PROPERTY FOLDER apps)
set_property(TARGET sample_gui PROPERTY FOLDER apps) 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)

129
apps/website-generator.cpp Normal file
View file

@ -0,0 +1,129 @@
#include "CommandLineArgs.h"
#include <string>
#include <iostream>
#include <vector>
#include <filesystem>
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<ContentPage> 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;
}

View file

@ -7,22 +7,22 @@ CommandLineArgs::CommandLineArgs()
} }
std::unique_ptr<CommandLineArgs> CommandLineArgs::CreateUnique() std::unique_ptr<CommandLineArgs> CommandLineArgs::Create()
{ {
return std::make_unique<CommandLineArgs>(); return std::make_unique<CommandLineArgs>();
} }
std::filesystem::path CommandLineArgs::GetLaunchPath() std::filesystem::path CommandLineArgs::getLaunchPath()
{ {
return mLaunchPath; return mLaunchPath;
} }
void CommandLineArgs::RecordLaunchPath() void CommandLineArgs::recordLaunchPath()
{ {
mLaunchPath = std::filesystem::current_path(); mLaunchPath = std::filesystem::current_path();
} }
void CommandLineArgs::Process(int argc, char *argv[]) void CommandLineArgs::process(int argc, char *argv[])
{ {
for(int idx=0; idx<argc; idx++) for(int idx=0; idx<argc; idx++)
{ {
@ -30,17 +30,17 @@ void CommandLineArgs::Process(int argc, char *argv[])
} }
} }
void CommandLineArgs::Process(const std::vector<std::string>& args) void CommandLineArgs::process(const std::vector<std::string>& args)
{ {
mArugments = args; mArugments = args;
} }
std::size_t CommandLineArgs::GetNumberOfArgs() const std::size_t CommandLineArgs::getNumberOfArgs() const
{ {
return mArugments.size(); return mArugments.size();
} }
std::string CommandLineArgs::GetArg(std::size_t index) const std::string CommandLineArgs::getArg(std::size_t index) const
{ {
if(index<mArugments.size()) if(index<mArugments.size())
{ {

View file

@ -6,26 +6,27 @@
class CommandLineArgs class CommandLineArgs
{ {
std::vector<std::string> mArugments;
std::filesystem::path mLaunchPath;
public: public:
CommandLineArgs(); CommandLineArgs();
static std::unique_ptr<CommandLineArgs> CreateUnique(); static std::unique_ptr<CommandLineArgs> 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<std::string>& args); void process(int argc, char *argv[]);
std::size_t GetNumberOfArgs() const; void process(const std::vector<std::string>& args);
std::string GetArg(std::size_t index) const; void recordLaunchPath();
private:
std::vector<std::string> mArugments;
std::filesystem::path mLaunchPath;
}; };
using CommandLineArgsUPtr = std::unique_ptr<CommandLineArgs>; using CommandLineArgsUPtr = std::unique_ptr<CommandLineArgs>;

View file

@ -17,13 +17,13 @@ list(APPEND image_DEFINES "")
find_package(PNG QUIET) find_package(PNG QUIET)
if(PNG_FOUND) if(PNG_FOUND)
list(APPEND image_LIBS PNG::PNG) list(APPEND image_LIBS PNG::PNG)
list(APPEND image_LIB_INCLUDES list(APPEND image_LIB_INCLUDES
PngWriterLibPng.cpp PngWriterLibPng.cpp
) )
list(APPEND image_DEFINES HAS_LIBPNG) list(APPEND image_DEFINES HAS_LIBPNG)
else() 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() endif()

View file

@ -8,6 +8,8 @@ class Image;
class PngWriterImpl class PngWriterImpl
{ {
public: public:
virtual ~PngWriterImpl() = default;
virtual void setPath(const std::string& path) = 0; virtual void setPath(const std::string& path) = 0;
virtual void write(const std::unique_ptr<Image>& image) const = 0; virtual void write(const std::unique_ptr<Image>& image) const = 0;

View file

View file

View file

@ -1,26 +1,20 @@
list(APPEND video_HEADERS list(APPEND video_HEADERS
Video.h Video.h
FfmpegInterface.h BasicVideoConverter.h
IVideoConverter.h
) )
list(APPEND video_LIB_INCLUDES list(APPEND video_LIB_INCLUDES
Video.cpp Video.cpp
FfmegInterface.cpp BasicVideoConverter.cpp
) )
add_library(video SHARED ${video_LIB_INCLUDES} ${video_HEADERS}) list(APPEND video_DEFINES "")
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) find_package(PkgConfig QUIET)
set(_HAS_FFMPEG Off)
if(PkgConfig) if(PkgConfig)
pkg_check_modules(LIBAV IMPORTED_TARGET pkg_check_modules(LIBAV IMPORTED_TARGET
libavdevice libavdevice
libavfilter libavfilter
libavformat libavformat
@ -28,13 +22,29 @@ pkg_check_modules(LIBAV IMPORTED_TARGET
libswresample libswresample
libswscale libswscale
libavutil libavutil
) )
list(APPEND video_LIBS PkgConfig::LIBAV) 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() else()
message(STATUS "LIBRARY CHECK: PkgConfig not found - disabling ffmpeg based video i/o.") message(STATUS "LIBRARY CHECK: PkgConfig not found - disabling ffmpeg based video i/o.")
endif() 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}")
set_target_properties( video PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
list(APPEND video_LIBS image)
target_link_libraries( video PUBLIC ${video_LIBS}) target_link_libraries( video PUBLIC ${video_LIBS})
set_property(TARGET video PROPERTY FOLDER src) set_property(TARGET video PROPERTY FOLDER src)

View file

View file

@ -1,8 +1,10 @@
set (platform_INCLUDES "") set (platform_INCLUDES "")
set (platform_LIBS "") set (platform_LIBS "")
set(_HAS_WAYLAND Off)
if(UNIX) if(UNIX)
list(APPEND platform_INCLUDES list(APPEND platform_INCLUDES
ui_interfaces/x11/XcbInterface.cpp ui_interfaces/x11/XcbInterface.cpp
ui_interfaces/x11/XcbEventInterface.cpp ui_interfaces/x11/XcbEventInterface.cpp
ui_interfaces/x11/XcbWindow.cpp ui_interfaces/x11/XcbWindow.cpp
@ -12,13 +14,9 @@ list(APPEND platform_INCLUDES
ui_interfaces/x11/XcbTextInterface.cpp ui_interfaces/x11/XcbTextInterface.cpp
ui_interfaces/x11/XcbKeyboard.cpp ui_interfaces/x11/XcbKeyboard.cpp
ui_interfaces/x11/GlxInterface.cpp ui_interfaces/x11/GlxInterface.cpp
ui_interfaces/wayland/WaylandWindowInterface.cpp
ui_interfaces/wayland/WaylandSurface.cpp
ui_interfaces/wayland/WaylandBuffer.cpp
) )
list(APPEND platform_LIBS list(APPEND platform_LIBS
X11 X11-xcb xcb ) X11 X11-xcb xcb )
@ -26,25 +24,34 @@ list(APPEND platform_LIBS
WAYLAND_CLIENT_INCLUDE_DIR WAYLAND_CLIENT_INCLUDE_DIR
NAMES wayland-client.h NAMES wayland-client.h
) )
list(APPEND WAYLAND_INCLUDE_DIRS ${WAYLAND_CLIENT_INCLUDE_DIR})
find_path( find_path(
WAYLAND_EXTENSIONS_INCLUDE_DIR WAYLAND_EXTENSIONS_INCLUDE_DIR
NAMES xdg-shell-client-protocol.h NAMES xdg-shell-client-protocol.h
HINTS ENV WAYLAND_EXTENSION_DIR HINTS ENV WAYLAND_EXTENSION_DIR
) )
if(NOT ${WAYLAND_EXTENSIONS_INCLUDE_DIR-NOTFOUND})
find_library( find_library(
WAYLAND_CLIENT_LIBRARY WAYLAND_CLIENT_LIBRARY
NAMES wayland-client libwayland-client NAMES wayland-client libwayland-client
) )
list(APPEND WAYLAND_INCLUDE_DIRS ${WAYLAND_EXTENSIONS_INCLUDE_DIR})
list(APPEND platform_INCLUDES list(APPEND platform_INCLUDES
ui_interfaces/win32/Win32UIInterface.h ui_interfaces/wayland/WaylandWindowInterface.cpp
ui_interfaces/wayland/WaylandSurface.cpp
ui_interfaces/wayland/WaylandBuffer.cpp
${WAYLAND_EXTENSIONS_INCLUDE_DIR}/xdg-shell-protocol.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() else()
list(APPEND platform_INCLUDES list(APPEND platform_INCLUDES
ui_interfaces/win32/Win32UIInterface.h ui_interfaces/win32/Win32UIInterface.h
ui_interfaces/win32/Win32UIInterface.cpp ui_interfaces/win32/Win32UIInterface.cpp
ui_interfaces/win32/Win32WindowInterface.h ui_interfaces/win32/Win32WindowInterface.h
@ -54,6 +61,8 @@ list(APPEND platform_INCLUDES
) )
endif() endif()
set(HAS_WAYLAND ${_HAS_WAYLAND} CACHE BOOL "Can build with Wayland")
list(APPEND windows_LIB_INCLUDES list(APPEND windows_LIB_INCLUDES
managers/WindowManager.cpp managers/WindowManager.cpp
managers/DesktopManager.cpp managers/DesktopManager.cpp
@ -73,8 +82,7 @@ target_include_directories(windows PUBLIC
"${PROJECT_SOURCE_DIR}/src/graphics" "${PROJECT_SOURCE_DIR}/src/graphics"
"${PROJECT_SOURCE_DIR}/src/ui_elements" "${PROJECT_SOURCE_DIR}/src/ui_elements"
"${PROJECT_SOURCE_DIR}/src/ui_elements/widgets" "${PROJECT_SOURCE_DIR}/src/ui_elements/widgets"
${WAYLAND_CLIENT_INCLUDE_DIR} ${WAYLAND_INCLUDE_DIRS}
${WAYLAND_EXTENSIONS_INCLUDE_DIR}
) )
target_link_libraries(windows PUBLIC ${platform_LIBS} core geometry graphics ui_elements ${WAYLAND_CLIENT_LIBRARY}) target_link_libraries(windows PUBLIC ${platform_LIBS} core geometry graphics ui_elements ${WAYLAND_CLIENT_LIBRARY})

View file

@ -23,12 +23,21 @@ list(APPEND TestFiles
network/TestNetworkManagerClient.cpp network/TestNetworkManagerClient.cpp
network/TestNetworkManagerServer.cpp network/TestNetworkManagerServer.cpp
publishing/TestPdfWriter.cpp publishing/TestPdfWriter.cpp
video/TestVideoDecoder.cpp
windows/TestWaylandWindow.cpp
web/TestMarkdownParser.cpp web/TestMarkdownParser.cpp
web/TestSvgWriter.cpp
web/TestXmlParser.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) find_package(PkgConfig)
pkg_check_modules(DBUS dbus-1) pkg_check_modules(DBUS dbus-1)
include_directories(${DBUS_INCLUDE_DIRS}) include_directories(${DBUS_INCLUDE_DIRS})

View file

@ -1,5 +1,6 @@
#include "Image.h" #include "Image.h"
#include "PngWriter.h" #include "PngWriter.h"
#include "PngWriterImpl.h"
#include <iostream> #include <iostream>

View file

@ -2,6 +2,7 @@
#include "Image.h" #include "Image.h"
#include "FfmpegInterface.h" #include "FfmpegInterface.h"
#include "PngWriter.h" #include "PngWriter.h"
#include "PngWriterImpl.h"
#include <iostream> #include <iostream>
int main() int main()