master
cmake 83 lines 2.82 KB
Raw
1 # SPDX-License-Identifier: GPL-3.0-or-later
2 # CMake module to handle fetching and installing the dashboard code
3
4 include(NetdataUtil)
5
6 function(handle_braindead_versioning_insanity prefix)
7 if(IS_DIRECTORY "${prefix}/v2" AND NOT IS_DIRECTORY "${prefix}/v3")
8 message(STATUS " Fixing incorrectly versioned paths generated by poorly written CI")
9 file(RENAME "${prefix}/v2" "${prefix}/v3")
10
11 if(IS_DIRECTORY "${prefix}/v3" AND NOT IS_DIRECTORY "${prefix}/v2")
12 message(STATUS " Fixing incorrectly versioned paths generated by poorly written CI -- Done")
13 else()
14 message(FATAL_ERROR "Failed to fix incorrectly versioned paths")
15 endif()
16 endif()
17 endfunction()
18
19 # Bundle the dashboard code for inclusion during install.
20 #
21 # This is unfortunately complicated due to how we need to handle the
22 # generation of the CMakeLists file for the dashboard code.
23 function(bundle_dashboard)
24 include(ExternalProject)
25
26 set(dashboard_src_dir "${CMAKE_BINARY_DIR}/dashboard-src")
27 set(dashboard_src_prefix "${dashboard_src_dir}/dist/agent")
28 set(dashboard_bin_dir "${CMAKE_BINARY_DIR}/dashboard-bin")
29 set(DASHBOARD_URL "https://app.netdata.cloud/agent.tar.gz" CACHE STRING
30 "URL used to fetch the local agent dashboard code")
31
32 message(STATUS "Preparing local agent dashboard code")
33
34 message(STATUS " Fetching ${DASHBOARD_URL}")
35 file(DOWNLOAD
36 "${DASHBOARD_URL}"
37 "${CMAKE_BINARY_DIR}/dashboard.tar.gz"
38 TIMEOUT 180
39 STATUS fetch_status)
40
41 list(GET fetch_status 0 result)
42
43 if(result)
44 message(FATAL_ERROR "Failed to fetch dashboard code")
45 else()
46 message(STATUS " Fetching ${DASHBOARD_URL} -- Done")
47 endif()
48
49 message(STATUS " Extracting dashboard code")
50 extract_gzipped_tarball(
51 "${CMAKE_BINARY_DIR}/dashboard.tar.gz"
52 "${dashboard_src_dir}"
53 )
54 message(STATUS " Extracting dashboard code -- Done")
55
56 handle_braindead_versioning_insanity("${dashboard_src_prefix}")
57
58 message(STATUS " Generating CMakeLists.txt file for dashboard code")
59 set(rules "")
60
61 subdirlist(dash_dirs "${dashboard_src_prefix}")
62
63 foreach(dir IN LISTS dash_dirs)
64 file(GLOB files
65 LIST_DIRECTORIES FALSE
66 RELATIVE "${dashboard_src_dir}"
67 "${dashboard_src_prefix}/${dir}/*")
68
69 set(rules "${rules}install(FILES ${files} COMPONENT dashboard DESTINATION ${WEB_DEST}/${dir})\n")
70 endforeach()
71
72 file(GLOB files
73 LIST_DIRECTORIES FALSE
74 RELATIVE "${dashboard_src_dir}"
75 "${dashboard_src_prefix}/*")
76
77 set(rules "${rules}install(FILES ${files} COMPONENT dashboard DESTINATION ${WEB_DEST})\n")
78
79 file(WRITE "${dashboard_src_dir}/CMakeLists.txt" "${rules}")
80 message(STATUS " Generating CMakeLists.txt file for dashboard code -- Done")
81 add_subdirectory("${dashboard_src_dir}" "${dashboard_bin_dir}")
82 message(STATUS "Preparing local agent dashboard code -- Done")
83 endfunction()