Skip to content

Commit

Permalink
Merge pull request #907 from llange/fix-cmake-build-ovms_webserver
Browse files Browse the repository at this point in the history
ESP-IDFv4+: fix cmake build of ovms_webserver
  • Loading branch information
llange committed Jun 2, 2023
2 parents 01c6b12 + 915f9e3 commit 0f16f53
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 67 deletions.
55 changes: 28 additions & 27 deletions vehicle/OVMS.V3/components/ovms_webserver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
set(srcs)
set(include_dirs)
set(ovms_webserver_mtimes ${COMPONENT_DIR}/src/ovms_webserver_mtimes.h)
set(embedded_files "assets/script.js.gz" "assets/charts.js.gz" "assets/tables.js.gz" "assets/style.css.gz" "assets/zones.json.gz" "assets/favicon.png")

if (CONFIG_OVMS_SC_GPL_MONGOOSE AND CONFIG_OVMS_COMP_WEBSERVER)
list(APPEND srcs "src/ovms_commandstream.cpp" "src/ovms_webserver.cpp" "src/ovms_websockethandler.cpp" "src/web_cfg.cpp" "src/web_cfg_init.cpp" "src/web_displays.cpp" "src/web_framework.cpp" "${ovms_webserver_mtimes}")
list(APPEND srcs "src/ovms_commandstream.cpp" "src/ovms_webserver.cpp" "src/ovms_websockethandler.cpp" "src/web_cfg.cpp" "src/web_cfg_init.cpp" "src/web_displays.cpp" "src/web_framework.cpp")
list(APPEND include_dirs "src" "assets")
endif ()

Expand All @@ -22,38 +21,40 @@ find_package(Perl REQUIRED)

function(concat_to_from destination)
set(source ${ARGN})
add_custom_command(
OUTPUT ${destination}
COMMENT "Concat from ${source} to ${destination}"
DEPENDS ${source}
COMMAND cat ${source} | dos2unix > ${destination}
# BYPRODUCTS
VERBATIM)
# Any modification of the source files (individual unconcatened files) will trigger a CMake reconfigure
# so that we can concatenate them again etc...
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${source}")
message(STATUS "ovms_webserver: Writing ${destination} from concatenation of: ${source}" )
execute_process(
COMMAND cat ${source}
COMMAND dos2unix
OUTPUT_FILE ${destination}
)
endfunction()

function(compress_to_from destination source)
add_custom_command(
OUTPUT ${destination}
COMMENT "Compressing from ${source} to ${destination}"
DEPENDS ${source}
COMMAND cat ${source} | gzip -9 --to-stdout > ${destination}
# BYPRODUCTS
VERBATIM)
message(STATUS "ovms_webserver: Compressing ${source} to: ${destination}" )
execute_process(
COMMAND cat ${source}
COMMAND gzip -9 --to-stdout
OUTPUT_FILE ${destination}
)
endfunction()

function(write_mtime_header)
set(depends)
foreach(argi RANGE 1 ${ARGC} 2)
list(GET ARGV ${argi} filename)
list(APPEND depends ${filename})
math(EXPR stop "${ARGC}-1")
foreach(argi RANGE 0 ${stop} 2)
list(GET ARGV ${argi} define)
math(EXPR argj "${argi}+1")
list(GET ARGV ${argj} filename)
message(STATUS "ovms_webserver: Recording modification time for: ${filename}" )
execute_process(
COMMAND perl -e "print +(stat \"${filename}\")[9]"
OUTPUT_VARIABLE ${define}
OUTPUT_STRIP_TRAILING_WHITESPACE
)
component_compile_definitions("${define}=${${define}}LL")
endforeach()
add_custom_target(gen_mtime_header
COMMENT "Generating ${define} from ${file}"
DEPENDS ${depends}
COMMAND "${COMPONENT_DIR}/helper.sh" "${ovms_webserver_mtimes}" ${ARGV}
BYPRODUCTS ${ovms_webserver_mtimes}
VERBATIM)
add_dependencies(${COMPONENT_LIB} gen_mtime_header)
endfunction()


Expand Down
31 changes: 7 additions & 24 deletions vehicle/OVMS.V3/components/ovms_webserver/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ COMPONENT_EXTRA_CLEAN := \
assets/tables.js.gz \
assets/style.css \
assets/style.css.gz \
assets/zones.json.gz \
$(COMPONENT_PATH)/src/ovms_webserver_mtimes.h
assets/zones.json.gz
COMPONENT_EMBED_FILES := \
assets/script.js.gz \
assets/charts.js.gz \
Expand Down Expand Up @@ -91,28 +90,12 @@ src/web_framework.o: \
$(COMPONENT_PATH)/assets/favicon.png \
$(COMPONENT_PATH)/assets/zones.json.gz

# When porting this component makefile to CMake we encountered and issue and
# were not able to reproduce this set of defines based on generated files.
# The workaround is to generate a header file instead of the defines, and to
# have an helper shell do the generation.
#
# We may revert when we have found a way to make it work with CMake.
src/ovms_webserver.o src/ovms_commandstream.o src/ovms_websockethandler.o src/web_cfg.o src/web_cfg_init.o src/web_displays.o src/web_framework.o: $(COMPONENT_PATH)/src/ovms_webserver_mtimes.h

$(COMPONENT_PATH)/src/ovms_webserver_mtimes.h: \
$(COMPONENT_PATH)/assets/script.js.gz \
$(COMPONENT_PATH)/assets/charts.js.gz \
$(COMPONENT_PATH)/assets/tables.js.gz \
$(COMPONENT_PATH)/assets/style.css.gz \
$(COMPONENT_PATH)/assets/favicon.png \
$(COMPONENT_PATH)/assets/zones.json.gz
$(COMPONENT_PATH)/helper.sh "$@" \
"MTIME_ASSETS_SCRIPT_JS" "$(COMPONENT_PATH)/assets/script.js.gz" \
"MTIME_ASSETS_CHARTS_JS" "$(COMPONENT_PATH)/assets/charts.js.gz" \
"MTIME_ASSETS_TABLES_JS" "$(COMPONENT_PATH)/assets/tables.js.gz" \
"MTIME_ASSETS_STYLE_CSS" "$(COMPONENT_PATH)/assets/style.css.gz" \
"MTIME_ASSETS_FAVICON_PNG" "$(COMPONENT_PATH)/assets/favicon.png" \
"MTIME_ASSETS_ZONES_JSON" "$(COMPONENT_PATH)/assets/zones.json.gz"
CPPFLAGS += -DMTIME_ASSETS_SCRIPT_JS=$(shell perl -e 'print +(stat "$(COMPONENT_PATH)/assets/script.js.gz")[9]')LL
CPPFLAGS += -DMTIME_ASSETS_CHARTS_JS=$(shell perl -e 'print +(stat "$(COMPONENT_PATH)/assets/charts.js.gz")[9]')LL
CPPFLAGS += -DMTIME_ASSETS_TABLES_JS=$(shell perl -e 'print +(stat "$(COMPONENT_PATH)/assets/tables.js.gz")[9]')LL
CPPFLAGS += -DMTIME_ASSETS_STYLE_CSS=$(shell perl -e 'print +(stat "$(COMPONENT_PATH)/assets/style.css.gz")[9]')LL
CPPFLAGS += -DMTIME_ASSETS_FAVICON_PNG=$(shell perl -e 'print +(stat "$(COMPONENT_PATH)/assets/favicon.png")[9]')LL
CPPFLAGS += -DMTIME_ASSETS_ZONES_JSON=$(shell perl -e 'print +(stat "$(COMPONENT_PATH)/assets/zones.json.gz")[9]')LL

endif
endif
15 changes: 0 additions & 15 deletions vehicle/OVMS.V3/components/ovms_webserver/helper.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
#include "ovms_netmanager.h"
#include "ovms_utils.h"
#include "log_buffers.h"
#include "ovms_webserver_mtimes.h"

// The setup wizard currently is tailored to be used with a WiFi enabled module:
#ifdef CONFIG_OVMS_COMP_WIFI
Expand Down

0 comments on commit 0f16f53

Please sign in to comment.