diff --git a/CMakeLists.txt b/CMakeLists.txt index 14653dc..c4173d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ project(libsdr) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake) include(InstallHeadersWithDirectory) +include(LinkResources) OPTION(BUILD_EXAMPLES "Build examples" OFF) OPTION(BUILD_UNIT_TESTS "Build unit tests" OFF) diff --git a/cmake/LinkResources.cmake b/cmake/LinkResources.cmake new file mode 100644 index 0000000..f71c428 --- /dev/null +++ b/cmake/LinkResources.cmake @@ -0,0 +1,7 @@ +macro(link_resources HEADER_NAME) + #create_resources("${CMAKE_CURRENT_BINARY_DIR}/${HEADER_NAME}.hh" ${ARGN}) + add_custom_target(${HEADER_NAME} ALL + COMMAND ${CMAKE_COMMAND} -DOUTPUT="${CMAKE_CURRENT_BINARY_DIR}/${HEADER_NAME}.hh" -DRESOURCE_PATH="${CMAKE_CURRENT_SOURCE_DIR}" -DFILES="${ARGN}" -P "${PROJECT_SOURCE_DIR}/cmake/create_resources.cmake" + DEPENDS ${ARGN} SOURCES ${ARGN}) +endmacro(link_resources) + diff --git a/cmake/create_resources.cmake b/cmake/create_resources.cmake new file mode 100644 index 0000000..da88045 --- /dev/null +++ b/cmake/create_resources.cmake @@ -0,0 +1,22 @@ +# +# Implements the packing of resource files into a header file +# +get_filename_component(OUTPUT_FILE ${OUTPUT} NAME) +message(STATUS "Generate resource file '${OUTPUT_FILE}' from: ${FILES}") +# Create empty file +file(WRITE ${OUTPUT} "") +# For each resource file +foreach(file ${FILES}) + # Normalize filename + string(REGEX MATCH "([^/]+)$" filename ${file}) + string(REGEX REPLACE "\\.| " "_" filename ${filename}) + # Read and convert file content + file(READ "${RESOURCE_PATH}/${file}" filedata HEX) + string(REGEX REPLACE "([0-9a-fA-F][0-9a-fA-F])" "0x\\1," filedata ${filedata}) + # Update output file + file(APPEND ${OUTPUT} + "extern \"C\" {\n" + " static char ${filename}[] = {${filedata}};\n" + " static unsigned ${filename}_size = sizeof(${filename});\n" + "}\n") +endforeach() diff --git a/cmd/CMakeLists.txt b/cmd/CMakeLists.txt index 33a0d17..bb11808 100644 --- a/cmd/CMakeLists.txt +++ b/cmd/CMakeLists.txt @@ -1,4 +1,8 @@ -#add_subdirectory(libhttpd) + +# Creates a header file including the shared resources +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) +link_resources(sdr_cmd_resources shared/index.html) add_executable(sdr_cmd main.cc) -target_link_libraries(sdr_cmd ${LIBS} libsdr) +add_dependencies(sdr_cmd sdr_cmd_resources) +target_link_libraries(sdr_cmd ${LIBS} libsdr ) diff --git a/cmd/json.cc b/cmd/json.cc deleted file mode 100644 index 7422728..0000000 --- a/cmd/json.cc +++ /dev/null @@ -1,5 +0,0 @@ -#include "json.hh" - -JSON::JSON() -{ -} diff --git a/cmd/json.hh b/cmd/json.hh deleted file mode 100644 index 5e2d2d9..0000000 --- a/cmd/json.hh +++ /dev/null @@ -1,5 +0,0 @@ -#ifndef __SDR_HTTP_JSON_HH__ -#define __SDR_HTTP_JSON_HH__ - - -#endif // __SDR_HTTP_JSON_HH__ diff --git a/cmd/main.cc b/cmd/main.cc index c0e9f63..1b2ce87 100644 --- a/cmd/main.cc +++ b/cmd/main.cc @@ -6,6 +6,7 @@ #include #include +#include "sdr_cmd_resources.hh" using namespace sdr; @@ -27,14 +28,6 @@ static void __sigint_handler(int signo) { server->stop(true); } -const char *index_html = "" - "" - "" - "It is alive!" - "" - ""; - - int main(int argc, char *argv[]) { Application app; server = new http::Server(8080); @@ -47,9 +40,8 @@ int main(int argc, char *argv[]) { signal(SIGINT, __sigint_handler); // Register callbacks - server->addStatic("/", index_html, "text/html"); + server->addStatic("/", std::string(index_html, index_html_size), "text/html"); server->addJSON("/echo", &app, &Application::echo); - // start server server->start(true); diff --git a/cmd/shared/index.html b/cmd/shared/index.html new file mode 100644 index 0000000..f94428c --- /dev/null +++ b/cmd/shared/index.html @@ -0,0 +1,71 @@ + + + sdr-aprs — An APRS receiver using libsdr. + + + + + + + + + +
+

Can not load Google Maps view. Check your internet conenction!

+
+ +