From d11580dfb3b81ea5d00775502737d59c155adfb2 Mon Sep 17 00:00:00 2001 From: Trinketer22 <109865562+Trinketer22@users.noreply.github.com> Date: Tue, 20 Sep 2022 22:26:59 +0300 Subject: [PATCH] Compiler -march fix for not supported arch (#444) I think there is an issue with the way -march flag is handled in the current build system. It is set to native (heavy cpu specific optimizations) via TON_ARCH and it is never checked if it is supported by the compiler. That's what is causing all those issues with apple m1 builds or any other arm system. Without checking early, build will only fail at link stage. Strict arch support checking is due. 1. Check if "-march=${TON_ARCH}" flag is supported by the compiler Adds it to CXX_FLAGS if al good 2. Otherwise if such flag is not supported but TON_ARCH is set to default we continue execution without setting march and leaving arch decisions to cmake build system 3. Otherwise user specified TON_ARCH intentionally and current arch is not supported by the compiler. Therefore we terminate build process immediately and let user know what's the matter. Co-authored-by: Trinketer22 --- CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 44dbae8b..b3daab9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,10 +197,13 @@ find_package(Threads REQUIRED) find_package(ZLIB REQUIRED) if (TON_ARCH AND NOT MSVC) + CHECK_CXX_COMPILER_FLAG( "-march=${TON_ARCH}" COMPILER_OPT_ARCH_SUPPORTED ) if (TON_ARCH STREQUAL "apple-m1") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=${TON_ARCH}") - else() + elseif(COMPILER_OPT_ARCH_SUPPORTED) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=${TON_ARCH}") + elseif(NOT TON_ARCH STREQUAL "native") + message(FATAL_ERROR "Compiler doesn't support arch ${TON_ARCH}") endif() endif() if (THREADS_HAVE_PTHREAD_ARG)