From d00073970bd4216a126da4602278d760cdeba556 Mon Sep 17 00:00:00 2001 From: dfrib Date: Tue, 23 Oct 2018 22:55:40 +0200 Subject: [PATCH] -DSYSTEM_CLANG=OFF: allow using Ubuntu 14.04 In the 6.0.1 -> 7.0.0 LLVM migration of f27639babfd7a29c8c76681e99c015d1f3e4a676, archive hashes were added for the LLVM 7.0.0 binaries not only for Ubuntu 16.04, but also for Ubuntu 14.04. The DownloadAndExtractClang.cmake functionality would never allow making use of the latter, however; always using the Ubuntu 16.04 LLVM 7.0.0 binary in case of OS Linux. This commit generalizes the archive name derivation for when the current platform is Ubuntu, while persisting using Ubuntu 16.04 as default archive in case CMAKE_SYSTEM_NAME is Linux (even if the actual dist is not Ubuntu). This change will also facilitate keeping backwards compatibility with Ubuntu 16.04 (possibly 14.04) for the upcoming LLVM 8.0.0 migration, where an archive for Bionic (18.04) is expected to be included (which may be chosen as the default). --- cmake/DownloadAndExtractClang.cmake | 37 +++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/cmake/DownloadAndExtractClang.cmake b/cmake/DownloadAndExtractClang.cmake index 9365b188..c064150a 100644 --- a/cmake/DownloadAndExtractClang.cmake +++ b/cmake/DownloadAndExtractClang.cmake @@ -12,8 +12,41 @@ set(CLANG_ARCHIVE_EXT .tar.xz) if(${CMAKE_SYSTEM_NAME} STREQUAL Linux) # Default to Ubuntu 16.04 - set(CLANG_ARCHIVE_NAME - clang+llvm-${CLANG_VERSION}-x86_64-linux-gnu-ubuntu-16.04) + set(DEFAULT_UBUNTU_VERSION_NUMBER 16.04) + + # Select a Clang archive for other Ubuntu releases if the current platform + # differs from the default one + set(UBUNTU_VERSION_NUMBER ${DEFAULT_UBUNTU_VERSION_NUMBER}) + find_program(LSB_RELEASE_EXECUTABLE lsb_release) + + if(NOT LSB_RELEASE_EXECUTABLE) + message(WARNING "Could not find lsb_release executable. \ +Falling back to default Linux platform: Clang/LLVM archive for \ +Ubuntu ${DEFAULT_UBUNTU_VERSION_NUMBER}.") + + else() + execute_process(COMMAND ${LSB_RELEASE_EXECUTABLE} -si + OUTPUT_VARIABLE LSB_RELEASE_ID + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + if(${LSB_RELEASE_ID} STREQUAL Ubuntu) + execute_process(COMMAND ${LSB_RELEASE_EXECUTABLE} -sr + OUTPUT_VARIABLE LSB_RELEASE_NUMBER + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + set(UBUNTU_VERSION_NUMBER ${LSB_RELEASE_NUMBER}) + + else() + message(WARNING "Identified other Linux platform than Ubuntu. Falling \ +back to default: Clang/LLVM for Ubuntu ${DEFAULT_UBUNTU_VERSION_NUMBER}.") + + endif() + endif() + + set(CLANG_ARCHIVE_NAME "clang+llvm-${CLANG_VERSION}-x86_64-\ +linux-gnu-ubuntu-${UBUNTU_VERSION_NUMBER}") elseif(${CMAKE_SYSTEM_NAME} STREQUAL Darwin)