Skip to content

Commit

Permalink
Meta: Use CMake functions to extract files
Browse files Browse the repository at this point in the history
Newer cmake's have internal functions to un-compress files. These
functions will work on pure windows - as well as linux. This
eliminates the need to search for external tools (TAR,GZIP,ZIP) - and
helps fixing SerenityOS#9866.

In order to finally fix SerenityOS#9866 we need to decide to bump the cmake
version requirements and remove the checks. If we demand a newer cmake
version, we will loose Ubuntu 20.04 as a build target - as it ships
with CMake 3.16.

For now - we keep compatibility with CMake 3.16 - and only if CMake
3.18 as been found - we use its new functionality.
  • Loading branch information
diegoiast authored and AtkinsSJ committed Sep 9, 2022
1 parent 5ab3fcf commit 8b30b69
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 22 deletions.
12 changes: 10 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,11 @@ endif()
if(EXISTS ${PCI_IDS_GZ_PATH} AND NOT EXISTS ${CMAKE_STAGING_PREFIX}/${PCI_IDS_INSTALL_PATH})
message(STATUS "Extracting PCI ID database from ${PCI_IDS_GZ_PATH}...")
file(MAKE_DIRECTORY "${CMAKE_STAGING_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}")
execute_process(COMMAND "${GZIP_TOOL}" -d -c "${PCI_IDS_GZ_PATH}" OUTPUT_FILE "${CMAKE_STAGING_PREFIX}/${PCI_IDS_INSTALL_PATH}")
if (CMAKE_VERSION VERSION_LESS 3.18.0)
execute_process(COMMAND "${GZIP_TOOL}" -d -c "${PCI_IDS_GZ_PATH}" OUTPUT_FILE "${CMAKE_STAGING_PREFIX}/${PCI_IDS_INSTALL_PATH}")
else()
file(ARCHIVE_EXTRACT INPUT "${PCI_IDS_GZ_PATH}" DESTINATION "${PCI_IDS_GZ_PATH}" PATTERNS "${CMAKE_STAGING_PREFIX}/${PCI_IDS_INSTALL_PATH}")
endif()
endif()

set(USB_IDS_FILE usb.ids)
Expand All @@ -273,5 +277,9 @@ endif()
if(EXISTS ${USB_IDS_GZ_PATH} AND NOT EXISTS ${CMAKE_STAGING_PREFIX}/${USB_IDS_INSTALL_PATH})
message(STATUS "Extracting USB ID database from ${USB_IDS_GZ_PATH}...")
file(MAKE_DIRECTORY "${CMAKE_STAGING_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}")
execute_process(COMMAND "${GZIP_TOOL}" -d -c "${USB_IDS_GZ_PATH}" OUTPUT_FILE "${CMAKE_STAGING_PREFIX}/${USB_IDS_INSTALL_PATH}")
if (CMAKE_VERSION VERSION_LESS 3.18.0)
execute_process(COMMAND "${GZIP_TOOL}" -d -c "${USB_IDS_GZ_PATH}" OUTPUT_FILE "${CMAKE_STAGING_PREFIX}/${USB_IDS_INSTALL_PATH}")
else()
file(ARCHIVE_EXTRACT INPUT "${PCI_IDS_GZ_PATH}" DESTINATION "${USB_IDS_GZ_PATH}" PATTERNS "${CMAKE_STAGING_PREFIX}/${USB_IDS_INSTALL_PATH}")
endif()
endif()
29 changes: 17 additions & 12 deletions Meta/CMake/check_for_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@
#
# 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()
if (CMAKE_VERSION VERSION_LESS 3.18.0)
find_program(UNZIP_TOOL unzip REQUIRED)
message(STATUS "Found cmake ${CMAKE_VERSION} - testing for external tools to uncompress")
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(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()
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()
else()
message(STATUS "Found cmake ${CMAKE_VERSION} - using CMake to uncompress")
endif()
13 changes: 9 additions & 4 deletions Meta/CMake/time_zone_data.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ 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_TOOL}" -C "${TZDB_PATH}" -xzf "${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}")
if (CMAKE_VERSION VERSION_LESS 3.18.0)
message(STATUS "Extracting using ${TAR_TOOL} file ${source}")
execute_process(COMMAND "${TAR_TOOL}" -C "${TZDB_PATH}" -xzf "${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()
else()
message(STATUS "Extracting using cmake ${source}")
file(ARCHIVE_EXTRACT INPUT "${TZDB_ZIP_PATH}" DESTINATION "${TZDB_PATH}" PATTERNS "${source}")
endif()
endif()
endfunction()
Expand Down
13 changes: 9 additions & 4 deletions Meta/CMake/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,15 @@ endfunction()

function(extract_path dest_dir zip_path source_path dest_path)
if (EXISTS "${zip_path}" AND NOT EXISTS "${dest_path}")
message(STATUS "Extracting ${source_path} from ${zip_path}")
execute_process(COMMAND "${UNZIP_TOOL}" -q "${zip_path}" "${source_path}" -d "${dest_dir}" RESULT_VARIABLE unzip_result)
if (NOT unzip_result EQUAL 0)
message(FATAL_ERROR "Failed to unzip ${source_path} from ${zip_path} with status ${unzip_result}")
if (CMAKE_VERSION VERSION_LESS 3.18.0)
message(STATUS "Extracting using ${UNZIP_TOOL} ${source_path} from ${zip_path}")
execute_process(COMMAND "${UNZIP_TOOL}" -q "${zip_path}" "${source_path}" -d "${dest_dir}" RESULT_VARIABLE unzip_result)
if (NOT unzip_result EQUAL 0)
message(FATAL_ERROR "Failed to unzip ${source_path} from ${zip_path} with status ${unzip_result}")
endif()
else()
message(STATUS "Extracting using cmake ${source_path}")
file(ARCHIVE_EXTRACT INPUT "${zip_path}" DESTINATION "${dest_dir}" PATTERNS "${source_path}")
endif()
endif()
endfunction()

0 comments on commit 8b30b69

Please sign in to comment.