Skip to content

Commit

Permalink
Update docs CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielskeenan committed Sep 8, 2024
1 parent 1117e83 commit ca81fb2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 44 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
else ()
set(PROJECT_WEBUI_PATH "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/web")
endif ()
add_subdirectory(mobile_sacn_webui)

find_package(Python3 COMPONENTS Interpreter)
option(BUILD_DOC "Build documentation (Requires Python)" ${Python3_FOUND})
Expand Down Expand Up @@ -69,7 +70,6 @@ if (BUILD_EXEC)
)
qt_standard_project_setup()

add_subdirectory(mobile_sacn_webui)
add_subdirectory(messages)
add_subdirectory(src)

Expand Down
91 changes: 48 additions & 43 deletions mobile_sacn_webui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
set(WEBUI_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/dist")
# The config assumes a relative path and will explode directories in the source dir if it is not given one.
cmake_path(RELATIVE_PATH WEBUI_BUILD_DIR BASE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" OUTPUT_VARIABLE WEBUI_BUILD_DIR_REL)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/vite.config.ts.in" "${CMAKE_CURRENT_SOURCE_DIR}/vite.config.ts" @ONLY)

# Ensure favicon is correct.
file(MAKE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/public")
file(COPY_FILE "${PROJECT_SOURCE_DIR}/resources/logo.svg" "${CMAKE_CURRENT_SOURCE_DIR}/public/mobile_sacn.svg" ONLY_IF_DIFFERENT)
file(COPY_FILE "${PROJECT_SOURCE_DIR}/resources/logo.svg" "${CMAKE_CURRENT_SOURCE_DIR}/src/assets/mobile_sacn.svg" ONLY_IF_DIFFERENT)

# Install Javascript deps
file(GLOB_RECURSE WEBUI_SOURCES LIST_DIRECTORIES false CONFIGURE_DEPENDS
public/*
src/*
index.html
package-lock.json
tsconfig.json
tsconfig.app.json
tsconfig.node.json
vite.config.ts
)
if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
set(_NPM_NAME npm.cmd)
else ()
Expand All @@ -31,28 +10,54 @@ execute_process(
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND_ERROR_IS_FATAL ANY
)
# Build site
add_custom_target(mobile_sacn_webui
COMMENT "Building Web UI..."
COMMAND "${npm_PROG}" run build
SOURCES ${WEBUI_SOURCES}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
DEPENDS mobile_sacn_messages_ts
VERBATIM
)
# Ensure make clean does what it should.
set_property(TARGET mobile_sacn_webui APPEND PROPERTY ADDITIONAL_CLEAN_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/node_modules"
"${WEBUI_BUILD_DIR}"
)

if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
# Need extra logic to ensure it ends up inside the app bundle.
add_custom_command(TARGET mobile_sacn_webui POST_BUILD
COMMAND "${CMAKE_COMMAND}"
-E copy_directory "${WEBUI_BUILD_DIR}/"
\"$<TARGET_BUNDLE_DIR:${PROJECT_NAME}>/Contents/${PROJECT_WEBUI_PATH}\"
# Because the NPM deps are also used for doc, need an extra check to see if we really want to build the web UI.
if (BUILD_EXEC)
set(WEBUI_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/dist")
# The config assumes a relative path and will explode directories in the source dir if it is not given one.
cmake_path(RELATIVE_PATH WEBUI_BUILD_DIR BASE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" OUTPUT_VARIABLE WEBUI_BUILD_DIR_REL)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/vite.config.ts.in" "${CMAKE_CURRENT_SOURCE_DIR}/vite.config.ts" @ONLY)

# Ensure favicon is correct.
file(MAKE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/public")
file(COPY_FILE "${PROJECT_SOURCE_DIR}/resources/logo.svg" "${CMAKE_CURRENT_SOURCE_DIR}/public/mobile_sacn.svg" ONLY_IF_DIFFERENT)
file(COPY_FILE "${PROJECT_SOURCE_DIR}/resources/logo.svg" "${CMAKE_CURRENT_SOURCE_DIR}/src/assets/mobile_sacn.svg" ONLY_IF_DIFFERENT)

# Install Javascript deps
file(GLOB_RECURSE WEBUI_SOURCES LIST_DIRECTORIES false CONFIGURE_DEPENDS
public/*
src/*
index.html
package-lock.json
tsconfig.json
tsconfig.app.json
tsconfig.node.json
vite.config.ts
)
else ()
install(DIRECTORY "${WEBUI_BUILD_DIR}/" DESTINATION "${PROJECT_WEBUI_PATH}")

# Build site
add_custom_target(mobile_sacn_webui
COMMENT "Building Web UI..."
COMMAND "${npm_PROG}" run build
SOURCES ${WEBUI_SOURCES}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
DEPENDS mobile_sacn_messages_ts
VERBATIM
)
# Ensure make clean does what it should.
set_property(TARGET mobile_sacn_webui APPEND PROPERTY ADDITIONAL_CLEAN_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/node_modules"
"${WEBUI_BUILD_DIR}"
)

if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
# Need extra logic to ensure it ends up inside the app bundle.
add_custom_command(TARGET mobile_sacn_webui POST_BUILD
COMMAND "${CMAKE_COMMAND}"
-E copy_directory "${WEBUI_BUILD_DIR}/"
\"$<TARGET_BUNDLE_DIR:${PROJECT_NAME}>/Contents/${PROJECT_WEBUI_PATH}\"
)
else ()
install(DIRECTORY "${WEBUI_BUILD_DIR}/" DESTINATION "${PROJECT_WEBUI_PATH}")
endif ()
endif ()

0 comments on commit ca81fb2

Please sign in to comment.