diff --git a/CMakeLists.txt b/CMakeLists.txt index a56daef..f79ae2e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,13 +1,13 @@ cmake_minimum_required(VERSION 3.5.1) +project(n-adb) + if ((CMAKE_HOST_SYSTEM_NAME MATCHES "Linux") AND (NOT (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64"))) set(CMAKE_C_COMPILER /usr/bin/clang) set(CMAKE_CXX_COMPILER /usr/bin/clang++) set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -stdlib=libc++") endif() -project(n-adb) - set(CMAKE_EXPORT_COMPILE_COMMANDS ON) add_compile_options(-g) diff --git a/README.md b/README.md index 4599df4..7ee9eda 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ $ make CFLAGS=-fPIC CC=aarch64-linux-gnu-gcc DEB_HOST_ARCH=arm64 -f debian/libcr $ make CXXFLAGS=-fPIC CXX=aarch64-linux-gnu-g++ DEB_HOST_ARCH=arm64 -f debian/libssl.mk ``` -### build adb for linxu x86-64 +### build adb for linux x86-64 **build on command line** @@ -60,13 +60,23 @@ $ make -j8 you need an remote linux pc, then config clion/vscode with it's remote development feature, it is so easy! -## build adb target for linux aarch64 +### build adb target for linux aarch64 + +**first, install toolchain** ```bash -$ mkdir build && cd build -$ cmake -DCMAKE_TOOLCHAIN_FILE=../aarch64_linux_toolchain.cmake ../ -$ make -j8 +$ wget 'https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz\?revision\=61c3be5d-5175-4db6-9030-b565aae9f766\&la\=en\&hash\=0A37024B42028A9616F56A51C2D20755C5EBBCD7' -O gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz +$ tar xvf gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz --strip-components=1 +``` + +**build with cmake** + ``` +$ CC=clang CXX=clang++ cmake . -Bbuild-arm64 -DCMAKE_TOOLCHAIN_FILE=cmake/linux/toolchain-aarch64.cmake +$ cmake --build build-arm64 --config Release +``` + +NOTE: please install a cmake with the newest version! ## build adb target for windows(only 32-bit supported!) diff --git a/aarch64_linux_toolchain.cmake b/aarch64_linux_toolchain.cmake deleted file mode 100644 index a750a60..0000000 --- a/aarch64_linux_toolchain.cmake +++ /dev/null @@ -1,13 +0,0 @@ -# ref: https://cmake.org/cmake/help/v3.9/manual/cmake-toolchains.7.html#cross-compiling-for-linux - -set(CMAKE_SYSTEM_NAME Linux) -set(CMAKE_SYSTEM_PROCESSOR aarch64) - -set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) -set(CMAKE_CXX_COMPILER arch64-linux-gnu-g++) - -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) - diff --git a/cmake/linux/toolchain-aarch64.cmake b/cmake/linux/toolchain-aarch64.cmake new file mode 100644 index 0000000..b3a0c78 --- /dev/null +++ b/cmake/linux/toolchain-aarch64.cmake @@ -0,0 +1,25 @@ +set (CMAKE_SYSTEM_NAME "Linux") +set (CMAKE_SYSTEM_PROCESSOR "aarch64") +set (CMAKE_C_COMPILER_TARGET "aarch64-linux-gnu") +set (CMAKE_CXX_COMPILER_TARGET "aarch64-linux-gnu") +set (CMAKE_ASM_COMPILER_TARGET "aarch64-linux-gnu") +set (CMAKE_SYSROOT "${CMAKE_CURRENT_LIST_DIR}/../toolchain/linux-aarch64/aarch64-none-linux-gnu/libc") + +# We don't use compiler from toolchain because it's gcc-8, and we provide support only for gcc-9. +set (CMAKE_AR "${CMAKE_CURRENT_LIST_DIR}/../toolchain/linux-aarch64/bin/aarch64-none-linux-gnu-ar" CACHE FILEPATH "" FORCE) +set (CMAKE_RANLIB "${CMAKE_CURRENT_LIST_DIR}/../toolchain/linux-aarch64/bin/aarch64-none-linux-gnu-ranlib" CACHE FILEPATH "" FORCE) + +set (CMAKE_C_FLAGS_INIT "${CMAKE_C_FLAGS} --gcc-toolchain=${CMAKE_CURRENT_LIST_DIR}/../toolchain/linux-aarch64") +set (CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS} --gcc-toolchain=${CMAKE_CURRENT_LIST_DIR}/../toolchain/linux-aarch64") +set (CMAKE_ASM_FLAGS_INIT "${CMAKE_ASM_FLAGS} --gcc-toolchain=${CMAKE_CURRENT_LIST_DIR}/../toolchain/linux-aarch64") + +#set (LINKER_NAME "lld" CACHE STRING "" FORCE) +# +#set (CMAKE_EXE_LINKER_FLAGS_INIT "-fuse-ld=lld") +#set (CMAKE_SHARED_LINKER_FLAGS_INIT "-fuse-ld=lld") +# +#set (HAS_PRE_1970_EXITCODE "0" CACHE STRING "Result from TRY_RUN" FORCE) +#set (HAS_PRE_1970_EXITCODE__TRYRUN_OUTPUT "" CACHE STRING "Output from TRY_RUN" FORCE) +# +#set (HAS_POST_2038_EXITCODE "0" CACHE STRING "Result from TRY_RUN" FORCE) +#set (HAS_POST_2038_EXITCODE__TRYRUN_OUTPUT "" CACHE STRING "Output from TRY_RUN" FORCE) diff --git a/cmake/toolchain/linux-aarch64/README.txt b/cmake/toolchain/linux-aarch64/README.txt new file mode 100644 index 0000000..11141ac --- /dev/null +++ b/cmake/toolchain/linux-aarch64/README.txt @@ -0,0 +1,2 @@ +wget 'https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz\?revision\=61c3be5d-5175-4db6-9030-b565aae9f766\&la\=en\&hash\=0A37024B42028A9616F56A51C2D20755C5EBBCD7' -O gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz +tar xvf gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz --strip-components=1