From 66e7ac19546b1158c7fd3ce8e088b0ad5f385a33 Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Fri, 18 Mar 2022 04:31:36 -0700 Subject: [PATCH] Meta: Error out on find_program errors with CMake less than 3.18 We have seen some cases where the build fails for folks, and they are missing unzip/tar/gzip etc. We can catch some of these in CMake itself, so lets make sure to handle that uniformly across the build system. The REQUIRED flag to `find_program` was only added on in CMake 3.18 and above, so we can't rely on that to actually halt the program execution. --- CMakeLists.txt | 9 +++------ Meta/CMake/check_for_dependencies.cmake | 23 +++++++++++++++++++++++ Meta/CMake/time_zone_data.cmake | 2 +- Meta/CMake/unicode_data.cmake | 2 +- Meta/CMake/wasm_spec_tests.cmake | 4 ++-- Meta/Lagom/CMakeLists.txt | 1 + 6 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 Meta/CMake/check_for_dependencies.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d1caa6db3e..867c5168965 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,10 +49,7 @@ endif() if (NOT HACKSTUDIO_BUILD) - # FIXME: With cmake 3.18, we can change unzip/untar steps to use - # file( ARCHIVE_EXTRACT) instead - find_program(UNZIP unzip REQUIRED) - find_program(TAR tar REQUIRED) + include(check_for_dependencies) # Host tools, required to generate files for the build find_package(Lagom CONFIG REQUIRED) @@ -309,7 +306,7 @@ endif() if(EXISTS ${PCI_IDS_GZ_PATH} AND NOT EXISTS ${PCI_IDS_INSTALL_PATH}) message(STATUS "Extracting PCI ID database from ${PCI_IDS_GZ_PATH}...") file(MAKE_DIRECTORY ${CMAKE_INSTALL_DATAROOTDIR}) - execute_process(COMMAND gzip -d -c "${PCI_IDS_GZ_PATH}" OUTPUT_FILE "${PCI_IDS_INSTALL_PATH}") + execute_process(COMMAND "${GZIP_TOOL}" -d -c "${PCI_IDS_GZ_PATH}" OUTPUT_FILE "${PCI_IDS_INSTALL_PATH}") endif() set(USB_IDS_FILE usb.ids) @@ -325,5 +322,5 @@ endif() if(EXISTS ${USB_IDS_GZ_PATH} AND NOT EXISTS ${USB_IDS_INSTALL_PATH}) message(STATUS "Extracting USB ID database from ${USB_IDS_GZ_PATH}...") file(MAKE_DIRECTORY ${CMAKE_INSTALL_DATAROOTDIR}) - execute_process(COMMAND gzip -d -c "${USB_IDS_GZ_PATH}" OUTPUT_FILE "${USB_IDS_INSTALL_PATH}") + execute_process(COMMAND "${GZIP_TOOL}" -d -c "${USB_IDS_GZ_PATH}" OUTPUT_FILE "${USB_IDS_INSTALL_PATH}") endif() diff --git a/Meta/CMake/check_for_dependencies.cmake b/Meta/CMake/check_for_dependencies.cmake new file mode 100644 index 00000000000..6ab71c9c43c --- /dev/null +++ b/Meta/CMake/check_for_dependencies.cmake @@ -0,0 +1,23 @@ +# +# Check for the dependencies that the Serenity (target) and Lagom (host) builds require. +# + +# FIXME: With cmake 3.18, we can change unzip/untar/gzip steps to use +# file( ARCHIVE_EXTRACT) instead +# +# Additionally we have to emit an error message for each tool, +# as REQUIRED only works with cmake 3.18 and above. +find_program(UNZIP_TOOL unzip REQUIRED) +if (NOT UNZIP_TOOL) + message(FATAL_ERROR "Failed to locate unzip on your machine, please install it and re-read the SerenityOS build documentation.") +endif() + +find_program(TAR_TOOL tar REQUIRED) +if (NOT TAR_TOOL) + message(FATAL_ERROR "Failed to locate tar on your machine, please install it and re-read the SerenityOS build documentation.") +endif() + +find_program(GZIP_TOOL gzip REQUIRED) +if (NOT GZIP_TOOL) + message(FATAL_ERROR "Failed to locate gzip on your machine, please install it and re-read the SerenityOS build documentation.") +endif() diff --git a/Meta/CMake/time_zone_data.cmake b/Meta/CMake/time_zone_data.cmake index 032aad100d7..f60ce486cd9 100644 --- a/Meta/CMake/time_zone_data.cmake +++ b/Meta/CMake/time_zone_data.cmake @@ -41,7 +41,7 @@ set(TZDB_ZONE_1970_PATH "${TZDB_PATH}/${TZDB_ZONE_1970_SOURCE}") function(extract_tzdb_file source path) if(EXISTS "${TZDB_ZIP_PATH}" AND NOT EXISTS "${path}") message(STATUS "Extracting TZDB ${source} from ${TZDB_ZIP_PATH}...") - execute_process(COMMAND tar -C "${TZDB_PATH}" -xf "${TZDB_ZIP_PATH}" "${source}" RESULT_VARIABLE tar_result) + execute_process(COMMAND "${TAR_TOOL}" -C "${TZDB_PATH}" -xf "${TZDB_ZIP_PATH}" "${source}" RESULT_VARIABLE tar_result) if (NOT tar_result EQUAL 0) message(FATAL_ERROR "Failed to unzip ${source} from ${TZDB_ZIP_PATH} with status ${tar_result}") endif() diff --git a/Meta/CMake/unicode_data.cmake b/Meta/CMake/unicode_data.cmake index 1d89f132538..c4965a473a3 100644 --- a/Meta/CMake/unicode_data.cmake +++ b/Meta/CMake/unicode_data.cmake @@ -91,7 +91,7 @@ set(CLDR_UNITS_PATH "${CLDR_PATH}/${CLDR_UNITS_SOURCE}") function(extract_cldr_file source path) if(EXISTS "${CLDR_ZIP_PATH}" AND NOT EXISTS "${path}") message(STATUS "Extracting CLDR ${source} from ${CLDR_ZIP_PATH}...") - execute_process(COMMAND unzip -q "${CLDR_ZIP_PATH}" "${source}/**" -d "${CLDR_PATH}" RESULT_VARIABLE unzip_result) + execute_process(COMMAND "${UNZIP_TOOL}" -q "${CLDR_ZIP_PATH}" "${source}/**" -d "${CLDR_PATH}" RESULT_VARIABLE unzip_result) if (NOT unzip_result EQUAL 0) message(FATAL_ERROR "Failed to unzip ${source} from ${CLDR_ZIP_PATH} with status ${unzip_result}") endif() diff --git a/Meta/CMake/wasm_spec_tests.cmake b/Meta/CMake/wasm_spec_tests.cmake index 6b90373ecf1..17c9110e711 100644 --- a/Meta/CMake/wasm_spec_tests.cmake +++ b/Meta/CMake/wasm_spec_tests.cmake @@ -22,8 +22,8 @@ if(INCLUDE_WASM_SPEC_TESTS) if(EXISTS ${WASM_SPEC_TEST_GZ_PATH} AND NOT EXISTS ${WASM_SPEC_TEST_PATH}) message(STATUS "Extracting the WebAssembly testsuite from ${WASM_SPEC_TEST_GZ_PATH}...") file(MAKE_DIRECTORY ${WASM_SPEC_TEST_PATH}) - execute_process(COMMAND gzip -k -d ${WASM_SPEC_TEST_GZ_PATH}) - execute_process(COMMAND tar -xf ${WASM_SPEC_TEST_TAR_PATH}) + execute_process(COMMAND "${GZIP_TOOL}" -k -d ${WASM_SPEC_TEST_GZ_PATH}) + execute_process(COMMAND "${TAR_TOOL}" -xf ${WASM_SPEC_TEST_TAR_PATH}) execute_process(COMMAND rm ${WASM_SPEC_TEST_TAR_PATH}) file(GLOB WASM_TESTS "${CMAKE_BINARY_DIR}/testsuite-main/*.wast") foreach(PATH ${WASM_TESTS}) diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt index 4ca364be406..b4c29c8cf9c 100644 --- a/Meta/Lagom/CMakeLists.txt +++ b/Meta/Lagom/CMakeLists.txt @@ -32,6 +32,7 @@ if(NOT COMMAND serenity_option) endmacro() endif() +include(check_for_dependencies) include(lagom_options) if(ENABLE_ALL_THE_DEBUG_MACROS)