Skip to content

Commit

Permalink
Meta: Error out on find_program errors with CMake less than 3.18
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bgianfo committed Mar 19, 2022
1 parent 6b5f0d1 commit 66e7ac1
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
9 changes: 3 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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()
23 changes: 23 additions & 0 deletions Meta/CMake/check_for_dependencies.cmake
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion Meta/CMake/time_zone_data.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion Meta/CMake/unicode_data.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions Meta/CMake/wasm_spec_tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
1 change: 1 addition & 0 deletions Meta/Lagom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ if(NOT COMMAND serenity_option)
endmacro()
endif()

include(check_for_dependencies)
include(lagom_options)

if(ENABLE_ALL_THE_DEBUG_MACROS)
Expand Down

0 comments on commit 66e7ac1

Please sign in to comment.