From e18488ba0ee7dda682793b2524dd1b7d9ae6d5ce Mon Sep 17 00:00:00 2001 From: amass <168062547@qq.com> Date: Fri, 28 Mar 2025 18:09:49 +0800 Subject: [PATCH] first commit --- .clang-format | 17 ++++++++++ .gitignore | 44 ++++++++++++++++++++++++++ CMakeLists.txt | 1 + Readme.md | 1 + main.cpp | 6 ++++ resources/build.sh | 66 +++++++++++++++++++++++++++++++++++++++ resources/toolchain.cmake | 18 +++++++++++ 7 files changed, 153 insertions(+) create mode 100644 .clang-format create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 Readme.md create mode 100644 main.cpp create mode 100755 resources/build.sh create mode 100644 resources/toolchain.cmake diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..f3960e2 --- /dev/null +++ b/.clang-format @@ -0,0 +1,17 @@ +BasedOnStyle: LLVM + +ObjCBlockIndentWidth: 4 +IndentWidth: 4 +TabWidth: 4 +AccessModifierOffset: -4 +ColumnLimit: 120 + +#模板声明后换行 +AlwaysBreakTemplateDeclarations: true + +# 是否允许短if单行 If true, if (a) return; 可以放到同一行 +AllowShortIfStatementsOnASingleLine: true + +#短句 while (true) continue; 能被放到单行。 +AllowShortLoopsOnASingleLine: true +AllowShortFunctionsOnASingleLine: false \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..590eab1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,44 @@ +# C++ objects and libs +*.slo +*.lo +*.o +*.a +*.la +*.lai +*.so +*.dll +*.dylib + +# Qt-es +object_script.*.Release +object_script.*.Debug +*_plugin_import.cpp +/.qmake.cache +/.qmake.stash +*.pro.user +*.pro.user.* +*.qbs.user +*.qbs.user.* +*.moc +moc_*.h +*.qmlc +*.jsc +Makefile* +*build-* + +# Qt unit tests +target_wrapper.* + +# QtCreator +*.autosave + +# QtCreator Qml +*.qmlproject.user +*.qmlproject.user.* + +# QtCreator CMake +CMakeLists.txt.user* +.idea +build +Frontend/node_modules +Frontend/package-lock.json diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a3f8dca --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1 @@ +add_executable(app main.cpp) \ No newline at end of file diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..b10afb4 --- /dev/null +++ b/Readme.md @@ -0,0 +1 @@ +这是一个使用 CMake 交叉编译的初始代码。 \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..05ec3da --- /dev/null +++ b/main.cpp @@ -0,0 +1,6 @@ +#include + +int main(int argc, char const *argv[]) { + std::cout << "hello world." << std::endl; + return 0; +} diff --git a/resources/build.sh b/resources/build.sh new file mode 100755 index 0000000..d1d1a95 --- /dev/null +++ b/resources/build.sh @@ -0,0 +1,66 @@ +#!/bin/bash + + +base_path=$(pwd) +if [[ $base_path == /home/* || $base_path == /root/* ]]; then + build_path=${base_path}/build +else + build_path=/tmp/build +fi +echo "build directory: $build_path" + +function cmake_scan() { + if [ ! -d ${build_path} ]; then + mkdir ${build_path} + fi + cmake \ + -G Ninja \ + -S ${base_path} \ + -B ${build_path} \ + -DCMAKE_TOOLCHAIN_FILE=resources/toolchain.cmake \ + -DCMAKE_BUILD_TYPE=Debug +} + +function build() { + if [ ! -f "${build_path}/CMakeCache.txt" ]; then + cmake_scan + fi + if [ $? -ne 0 ]; then + exit 1 + fi + cmake \ + --build ${build_path} \ + --target all + if [ $? -ne 0 ]; then + exit 1 + fi +} + +function clean() { + if [ -d ${build_path} ]; then + rm -fr ${build_path} + fi +} + +function main() { + local cmd=$1 + shift 1 + case $cmd in + build) + build $@ + ;; + scan) + cmake_scan + ;; + clean) + clean + ;; + *) + build + ;; + esac +} + +main $@ + + diff --git a/resources/toolchain.cmake b/resources/toolchain.cmake new file mode 100644 index 0000000..d870b5a --- /dev/null +++ b/resources/toolchain.cmake @@ -0,0 +1,18 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR arm) + +# which compilers to use for C and C++ +set(CMAKE_C_COMPILER arm-buildroot-linux-gnueabihf-gcc) +set(CMAKE_CXX_COMPILER arm-buildroot-linux-gnueabihf-g++) + +# where is the target environment located +# set(CMAKE_FIND_ROOT_PATH /usr/i586-mingw32msvc +# /home/alex/mingw-install) + +# adjust the default behavior of the FIND_XXX() commands: +# search programs in the host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + +# search headers and libraries in the target environment +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) \ No newline at end of file