aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2021-10-25 14:35:32 +0200
committerToni Uhlig <matzeton@googlemail.com>2021-10-25 14:41:11 +0200
commit8c2089dd8117835cfbfaed2c8f50cd34e666487f (patch)
tree5954b63122b1f71903469907a76ac74e36f81ec7
parent47a838f292439b9d1ce921a79341e4a7170d0810 (diff)
Added CMake install targets and reworked wwwroot folder structure.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r--CMakeLists.txt11
-rw-r--r--src/main.cpp28
-rw-r--r--wwwroot/blog/my-second-blog-entry.json (renamed from blog/my-second-blog-entry.json)0
-rw-r--r--wwwroot/blog/my-second-blog-entry.md (renamed from blog/my-second-blog-entry.md)0
-rw-r--r--wwwroot/blog/my-third-blog-entry.json (renamed from blog/my-third-blog-entry.json)0
-rw-r--r--wwwroot/blog/my-third-blog-entry.md (renamed from blog/my-third-blog-entry.md)0
-rw-r--r--wwwroot/blog/my-very-first-blog-entry.json (renamed from blog/my-very-first-blog-entry.json)0
-rw-r--r--wwwroot/blog/my-very-first-blog-entry.md (renamed from blog/my-very-first-blog-entry.md)0
-rw-r--r--wwwroot/pages/index.md (renamed from pages/index.md)0
-rw-r--r--wwwroot/static/test.txt1
10 files changed, 21 insertions, 19 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1de9b72..6494836 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,14 @@
cmake_minimum_required(VERSION 3.1.9)
project(cpp-web)
+set(CPACK_PACKAGE_CONTACT "toni@impl.cc")
+set(CPACK_DEBIAN_PACKAGE_NAME "cpp-web")
+set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
+set(CPACK_PACKAGE_VERSION_MAJOR 1)
+set(CPACK_PACKAGE_VERSION_MINOR 0)
+
+include(CPack)
+
set(CMAKE_CXX_FLAGS "-Wall -Wextra -std=c++17")
set(CMAKE_CXX_FLAGS_DEBUG "-g3 -fpic -fno-omit-frame-pointer -fno-rtti -ffunction-sections -fdata-sections -fsanitize=address -fsanitize=leak")
set(CMAKE_CXX_FLAGS_RELEASE "-Os -fpic -fomit-frame-pointer -ffunction-sections -fdata-sections -flto")
@@ -33,3 +41,6 @@ if(CMAKE_BUILD_TYPE MATCHES Release)
set_target_properties(cpp-web PROPERTIES LINK_FLAGS "-no-pie -flto -Wl,--gc-sections -Wl,-z,norelro -Wl,--hash-style=gnu -Wl,--build-id=none")
endif()
target_link_libraries(cpp-web stdc++fs pthread event magic)
+
+install(TARGETS cpp-web RUNTIME DESTINATION bin)
+install(DIRECTORY ${PROJECT_SOURCE_DIR}/wwwroot/ DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cpp-web/wwwroot)
diff --git a/src/main.cpp b/src/main.cpp
index 61407d8..8256717 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -19,7 +19,7 @@ int main(int argc, char ** argv)
if (argc <= 1 || argc > 5)
{
- std::cout << "usage: cpp-web [HOST] [PORT] [STATIC-WWWROOT] [DYNAMIC-WWWROOT]" << std::endl;
+ std::cout << "usage: cpp-web [HOST] [PORT] [WWWROOT]" << std::endl;
if (argc > 5)
{
return 1;
@@ -34,6 +34,10 @@ int main(int argc, char ** argv)
{
port = atoi(argv[2]);
}
+ if (argc > 3)
+ {
+ wwwroot = argv[3];
+ }
std::shared_ptr<TemplateManager> tmgr = std::make_shared<TemplateManager>();
std::shared_ptr<ContentManager> cmgr = std::make_shared<ContentManager>();
@@ -41,36 +45,22 @@ int main(int argc, char ** argv)
{
std::shared_ptr<Filesystem> static_fs = std::make_shared<Filesystem>();
- if (argc > 3)
- {
- if (static_fs->Scan(argv[3]) != true)
- {
- return 1;
- }
- }
- std::cout << "Static fs: " << wwwroot << std::endl;
- static_fs->Scan(wwwroot, {"html", "tmpl"}, true);
+ std::cout << "Static fs: " << wwwroot + "/static" << std::endl;
+ static_fs->Scan(wwwroot + "/static", {"html", "tmpl"}, true);
cmgr->RegisterModule(std::make_shared<Static>("/static", static_fs));
}
{
Filesystem dynamic_fs;
- if (argc > 4)
- {
- if (dynamic_fs.Scan(argv[4]) != true)
- {
- return 1;
- }
- }
std::cout << "Dynamic fs: " << wwwroot << std::endl;
dynamic_fs.Scan(wwwroot, {"html", "tmpl"}, false);
tmgr->ParseTemplates(dynamic_fs);
}
- cmgr->RegisterModule(std::make_shared<Markdown>("/", "./pages", "index.html"));
- cmgr->RegisterModule(std::make_shared<Blog>("/blog", "./blog", "blog/index.html"));
+ cmgr->RegisterModule(std::make_shared<Markdown>("/", wwwroot + "/pages", "index.html"));
+ cmgr->RegisterModule(std::make_shared<Blog>("/blog", wwwroot + "/blog", "blog/index.html"));
if (cmgr->InitAll() == false)
{
diff --git a/blog/my-second-blog-entry.json b/wwwroot/blog/my-second-blog-entry.json
index ecb2b8b..ecb2b8b 100644
--- a/blog/my-second-blog-entry.json
+++ b/wwwroot/blog/my-second-blog-entry.json
diff --git a/blog/my-second-blog-entry.md b/wwwroot/blog/my-second-blog-entry.md
index 054046a..054046a 100644
--- a/blog/my-second-blog-entry.md
+++ b/wwwroot/blog/my-second-blog-entry.md
diff --git a/blog/my-third-blog-entry.json b/wwwroot/blog/my-third-blog-entry.json
index 9682cd2..9682cd2 100644
--- a/blog/my-third-blog-entry.json
+++ b/wwwroot/blog/my-third-blog-entry.json
diff --git a/blog/my-third-blog-entry.md b/wwwroot/blog/my-third-blog-entry.md
index 292b1e1..292b1e1 100644
--- a/blog/my-third-blog-entry.md
+++ b/wwwroot/blog/my-third-blog-entry.md
diff --git a/blog/my-very-first-blog-entry.json b/wwwroot/blog/my-very-first-blog-entry.json
index 52f52f7..52f52f7 100644
--- a/blog/my-very-first-blog-entry.json
+++ b/wwwroot/blog/my-very-first-blog-entry.json
diff --git a/blog/my-very-first-blog-entry.md b/wwwroot/blog/my-very-first-blog-entry.md
index 017cbfc..017cbfc 100644
--- a/blog/my-very-first-blog-entry.md
+++ b/wwwroot/blog/my-very-first-blog-entry.md
diff --git a/pages/index.md b/wwwroot/pages/index.md
index 99bd385..99bd385 100644
--- a/pages/index.md
+++ b/wwwroot/pages/index.md
diff --git a/wwwroot/static/test.txt b/wwwroot/static/test.txt
new file mode 100644
index 0000000..50bb49a
--- /dev/null
+++ b/wwwroot/static/test.txt
@@ -0,0 +1 @@
+This is a static text file.