From 0889d966fbc7a554ba2c8f056a3fae062442f0bd Mon Sep 17 00:00:00 2001 From: Hyeongseok Oh Date: Fri, 27 Dec 2024 14:57:23 +0900 Subject: [PATCH] [infra/onert] Update cmake toolchain file (#14498) This commit updates cmake toolchain file - Remove tizen cross build toolchain file: not used - Support clang build: Set USE_CLANG=1 environment variable - Remove deprecated include: CMakeForceCompiler - Remove using envoption() ONE-DCO-1.0-Signed-off-by: Hyeongseok Oh --- .../config/config_armv7l-linux.cmake | 8 ++- .../cross/toolchain_aarch64-linux.cmake | 25 ++++++--- .../cross/toolchain_aarch64-tizen.cmake | 56 ------------------- .../cross/toolchain_armv7l-linux.cmake | 23 +++++--- 4 files changed, 38 insertions(+), 74 deletions(-) delete mode 100644 infra/nnfw/cmake/buildtool/cross/toolchain_aarch64-tizen.cmake diff --git a/infra/nnfw/cmake/buildtool/config/config_armv7l-linux.cmake b/infra/nnfw/cmake/buildtool/config/config_armv7l-linux.cmake index f3c52d7cc52..0bd7e40c898 100644 --- a/infra/nnfw/cmake/buildtool/config/config_armv7l-linux.cmake +++ b/infra/nnfw/cmake/buildtool/config/config_armv7l-linux.cmake @@ -14,5 +14,11 @@ set(FLAGS_COMMON ${FLAGS_COMMON} "-mfloat-abi=hard" "-mfpu=neon-vfpv4" "-ftree-vectorize" - "-mfp16-format=ieee" ) + +# "fp16-format=ieee" is default and not supported flag on Clang +include(CheckCXXCompilerFlag) +check_cxx_compiler_flag(-mfp16-format=ieee COMPILER_SUPPORTS_FP16_FORMAT_I3E) +if(COMPILER_SUPPORTS_FP16_FORMAT_I3E) + set(FLAGS_COMMON ${FLAGS_COMMON} "-mfp16-format=ieee") +endif() diff --git a/infra/nnfw/cmake/buildtool/cross/toolchain_aarch64-linux.cmake b/infra/nnfw/cmake/buildtool/cross/toolchain_aarch64-linux.cmake index 07b26a93717..7a19fdc28c7 100644 --- a/infra/nnfw/cmake/buildtool/cross/toolchain_aarch64-linux.cmake +++ b/infra/nnfw/cmake/buildtool/cross/toolchain_aarch64-linux.cmake @@ -1,20 +1,27 @@ # # config for aarch64-linux # -include(CMakeForceCompiler) +# Set CMAKE_SYSTEM_NAME to notify to cmake that we are cross compiling set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR aarch64) -set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) -set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) - -# where is the target environment -set(NNAS_PROJECT_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../../..") -set(ROOTFS_AARCH64 "${NNAS_PROJECT_SOURCE_DIR}/tools/cross/rootfs/aarch64") -include("${NNAS_PROJECT_SOURCE_DIR}/infra/cmake/modules/OptionTools.cmake") +if(DEFINED ENV{USE_CLANG} AND "$ENV{USE_CLANG}" STREQUAL "1") + set(CMAKE_C_COMPILER clang) + set(CMAKE_CXX_COMPILER clang++) + set(CMAKE_C_COMPILER_TARGET arm-linux-gnueabihf) + set(CMAKE_CXX_COMPILER_TARGET arm-linux-gnueabihf) +else() + set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) + set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) +endif() -envoption(ROOTFS_DIR ${ROOTFS_AARCH64}) +# where is the target RootFS +if(DEFINED ENV{ROOTFS_DIR}) + set(ROOTFS_DIR $ENV{ROOTFS_DIR}) +else() + set(ROOTFS_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../../../tools/cross/rootfs/aarch64") +endif() if(NOT EXISTS "${ROOTFS_DIR}/lib/aarch64-linux-gnu") message(FATAL_ERROR "Please prepare RootFS for AARCH64") endif() diff --git a/infra/nnfw/cmake/buildtool/cross/toolchain_aarch64-tizen.cmake b/infra/nnfw/cmake/buildtool/cross/toolchain_aarch64-tizen.cmake deleted file mode 100644 index cab7325dda1..00000000000 --- a/infra/nnfw/cmake/buildtool/cross/toolchain_aarch64-tizen.cmake +++ /dev/null @@ -1,56 +0,0 @@ -# -# config for aarch64-linux -# -include(CMakeForceCompiler) - -set(CMAKE_SYSTEM_NAME Linux) -set(CMAKE_SYSTEM_PROCESSOR aarch64) - -set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) -set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) - -set(TIZEN_TOOLCHAIN "aarch64-tizen-linux-gnu/6.2.1") - -# where is the target environment -set(NNAS_PROJECT_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../../..") -set(ROOTFS_AARCH64 "${NNAS_PROJECT_SOURCE_DIR}/tools/cross/rootfs/aarch64") -include("${NNAS_PROJECT_SOURCE_DIR}/infra/cmake/modules/OptionTools.cmake") - -envoption(ROOTFS_DIR ${ROOTFS_AARCH64}) -if(NOT EXISTS "${ROOTFS_DIR}/usr/lib64/gcc/${TIZEN_TOOLCHAIN}") - message(FATAL_ERROR "Please prepare RootFS for tizen aarch64") -endif() - -set(CMAKE_SYSROOT ${ROOTFS_DIR}) -set(CMAKE_FIND_ROOT_PATH ${ROOTFS_DIR}) - -# search for programs in the build host directories -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) - -# for libraries and headers in the target directories -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) - -# Set cache variable to ignore try-run error by find_package(Threads REQUIRED) on cross build -set(THREADS_PTHREAD_ARG "2" CACHE STRING "Result from TRY_RUN" FORCE) - -add_compile_options(--sysroot=${ROOTFS_DIR}) - -set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --sysroot=${ROOTFS_DIR}") - -set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --sysroot=${ROOTFS_DIR}") - -include_directories(SYSTEM ${ROOTFS_DIR}/usr/lib64/gcc/${TIZEN_TOOLCHAIN}/include/c++/) -include_directories(SYSTEM ${ROOTFS_DIR}/usr/lib64/gcc/${TIZEN_TOOLCHAIN}/include/c++/aarch64-tizen-linux-gnu) -add_compile_options(-Wno-deprecated-declarations) # compile-time option -add_compile_options(-D__extern_always_inline=inline) # compile-time option - -set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -B${ROOTFS_DIR}/usr/lib64/gcc/${TIZEN_TOOLCHAIN}") -set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L${ROOTFS_DIR}/lib64") -set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L${ROOTFS_DIR}/usr/lib64") -set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L${ROOTFS_DIR}/usr/lib64/gcc/${TIZEN_TOOLCHAIN}") - -set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -B${ROOTFS_DIR}/usr/lib64/gcc/${TIZEN_TOOLCHAIN}") -set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${ROOTFS_DIR}/lib64") -set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${ROOTFS_DIR}/usr/lib64") -set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${ROOTFS_DIR}/usr/lib64/gcc/${TIZEN_TOOLCHAIN}") diff --git a/infra/nnfw/cmake/buildtool/cross/toolchain_armv7l-linux.cmake b/infra/nnfw/cmake/buildtool/cross/toolchain_armv7l-linux.cmake index c69259f8500..5562f3dc076 100644 --- a/infra/nnfw/cmake/buildtool/cross/toolchain_armv7l-linux.cmake +++ b/infra/nnfw/cmake/buildtool/cross/toolchain_armv7l-linux.cmake @@ -1,20 +1,27 @@ # # config for arm-linux # -include(CMakeForceCompiler) +# Set CMAKE_SYSTEM_NAME to notify to cmake that we are cross compiling set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR armv7l) -set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc) -set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++) +if(DEFINED ENV{USE_CLANG} AND "$ENV{USE_CLANG}" STREQUAL "1") + set(CMAKE_C_COMPILER clang) + set(CMAKE_CXX_COMPILER clang++) + set(CMAKE_C_COMPILER_TARGET arm-linux-gnueabihf) + set(CMAKE_CXX_COMPILER_TARGET arm-linux-gnueabihf) +else() + set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc) + set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++) +endif() # where is the target environment -set(NNAS_PROJECT_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../../..") -set(ROOTFS_ARM "${NNAS_PROJECT_SOURCE_DIR}/tools/cross/rootfs/arm") -include("${NNAS_PROJECT_SOURCE_DIR}/infra/cmake/modules/OptionTools.cmake") - -envoption(ROOTFS_DIR ${ROOTFS_ARM}) +if(DEFINED ENV{ROOTFS_DIR}) + set(ROOTFS_DIR $ENV{ROOTFS_DIR}) +else() + set(ROOTFS_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../../../tools/cross/rootfs/arm") +endif() if(NOT EXISTS "${ROOTFS_DIR}/lib/arm-linux-gnueabihf") message(FATAL_ERROR "Please prepare RootFS for ARM") endif()