已经大半个月没有更新文章了,大家还记得之前作者写的一篇关于RT-Thread的微内核移植的文章吗?如果不记得没关系。看如下是文章链接。
《如何移植RTT微内核到树莓派3B》
《CMake,大型项目采用的构建工具》
《CMake 静态库与动态库构建》
《CMake 教你如何链接共享库》
cmake_minimum_required(VERSION 3.10)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CONFIG_PREFIX "/opt/gcc-arm-none-eabi/bin/arm-none-eabi-")
set(CMAKE_C_COMPILER "${CONFIG_PREFIX}gcc")
set(CMAKE_CXX_COMPILER "${CONFIG_PREFIX}g++")
set(CMAKE_ASM_COMPILER "${CONFIG_PREFIX}gcc")
set(CMAKE_OBJCOPY "${CONFIG_PREFIX}objcopy")
set(CMAKE_C_AR "${CONFIG_PREFIX}ar")
set(CMAKE_SIZE "${CONFIG_PREFIX}size")
#Disable compiler checks
set(CMAKE_C_COMPILER_FORCED TRUE)
set(CMAKE_CXX_COMPILER_FORCED TRUE)
set(microkernel_sdk_dir "${CMAKE_SOURCE_DIR}/sdk")
set(microkernel_apps_dir "${CMAKE_SOURCE_DIR}/apps")
project(rtt_microkernel)
enable_language(C ASM)
add_definitions(
"-D__ASSEMBLY__"
"-DRT_USING_NEWLIB"
"-DHAVE_CCONFIG_H"
"-D__STDC_ISO_10646__=201206L"
"-D_STDC_PREDEF_H"
)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv7-a -marm -msoft-float -Werror -Wall -O0 -g -gdwarf-2 -n -pie -fpie -fPIC -fpic --static -nostdinc")
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -march=armv7-a -marm -msoft-float -x assembler-with-cpp -O0 -g -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv7-a -marm -msoft-float -Werror -Wall -Woverloaded-virtual -fno-exceptions -fno-rtti -O0 -g -gdwarf-2 -n -pie -fpie -fPIC -fpic --static -nostdinc")
set(CMAKE_EXE_LINKER_FLAGS "-march=armv7-a -marm -msoft-float -nostartfiles -nostdlib -n -pie -fpie -fPIC -fpic -Wl,-pie")
set(microkernel_sdk_inc
"${CMAKE_SOURCE_DIR}"
"${microkernel_sdk_dir}/crt/rt-thread/components/dfs"
"${microkernel_sdk_dir}/crt/rt-thread/components/drivers"
"${microkernel_sdk_dir}/crt/rt-thread/components/net"
"${microkernel_sdk_dir}/crt/rt-thread/components/net/netdev"
"${microkernel_sdk_dir}/crt/rt-thread/components/lwip-2.1.0"
"${microkernel_sdk_dir}/crt/rt-thread/include"
"${microkernel_sdk_dir}/crt/rt-thread/include/libc"
"${microkernel_sdk_dir}/crt/gcc"
"${microkernel_sdk_dir}/libc/include"
)
set(microkernel_apps_inc
"${microkernel_apps_dir}/hello"
)
set(microkernel_sdk_src
"${microkernel_sdk_dir}/crt/cplusplus/cxx_crt.cpp"
"${microkernel_sdk_dir}/crt/gcc/arch/arm/syscall.S"
"${microkernel_sdk_dir}/crt/rt-thread/src/rt_channel.c"
"${microkernel_sdk_dir}/crt/rt-thread/src/rt_completion.c"
"${microkernel_sdk_dir}/crt/rt-thread/src/rt_device.c"
"${microkernel_sdk_dir}/crt/rt-thread/src/rt_ipc.c"
"${microkernel_sdk_dir}/crt/rt-thread/src/rt_net.c"
"${microkernel_sdk_dir}/crt/rt-thread/src/rt_syscall.c"
"${microkernel_sdk_dir}/crt/rt-thread/src/rt_thread.c"
"${microkernel_sdk_dir}/crt/rt-thread/src/rt_timer.c"
"${microkernel_sdk_dir}/crt/rt-thread/src/stub.c"
)
set(microkernel_apps_src
"${microkernel_apps_dir}/hello/main.c"
)
set(CMAKE_EXECUTABLE_SUFFIX ".elf")
add_executable(${PROJECT_NAME} ${microkernel_apps_src} ${microkernel_sdk_src})
target_include_directories(${PROJECT_NAME} PRIVATE ${microkernel_sdk_inc} ${microkernel_apps_inc})
target_link_libraries(${PROJECT_NAME}
PRIVATE
-Wl,--start-group
"${CMAKE_SOURCE_DIR}/sdk/libc/lib/libc.a"
"${CMAKE_SOURCE_DIR}/sdk/libc/lib/libm.a"
"${CMAKE_SOURCE_DIR}/sdk/libc/lib/libcrt.a"
"libgcc.a"
-Wl,--end-group
-T ${microkernel_sdk_dir}/crt/gcc/arch/arm/gcc_arm.ld
)
cmake_minimum_required(VERSION 3.10)
CMAKE_SYSTEM_NAME:这个变量被设置,cmake才认为采用交叉编译,CMAKE_SYSTEM_NAME即目标机target所在的操作系统名称,比如ARM或者Linux你就需要写”Linux”,如果Android平台你就写”Android”,如果你的嵌入式平台没有相关OS你即需要写成”Generic”。
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_C_COMPILER_FORCED TRUE)
set(CMAKE_CXX_COMPILER_FORCED TRUE)
set(microkernel_sdk_dir "${CMAKE_SOURCE_DIR}/sdk")
set(microkernel_apps_dir "${CMAKE_SOURCE_DIR}/apps")
project(rtt_microkernel)
enable_language(C ASM)
add_definitions(
"-D__ASSEMBLY__"
"-DRT_USING_NEWLIB"
"-DHAVE_CCONFIG_H"
"-D__STDC_ISO_10646__=201206L"
"-D_STDC_PREDEF_H"
)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv7-a -marm -msoft-float -Werror -Wall -O0 -g -gdwarf-2 -n -pie -fpie -fPIC -fpic --static -nostdinc")
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -march=armv7-a -marm -msoft-float -x assembler-with-cpp -O0 -g -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv7-a -marm -msoft-float -Werror -Wall -Woverloaded-virtual -fno-exceptions -fno-rtti -O0 -g -gdwarf-2 -n -pie -fpie -fPIC -fpic --static -nostdinc")
set(CMAKE_EXE_LINKER_FLAGS "-march=armv7-a -marm -msoft-float -nostartfiles -nostdlib -n -pie -fpie -fPIC -fpic -Wl,-pie")
set(microkernel_sdk_inc
"${CMAKE_SOURCE_DIR}"
"${microkernel_sdk_dir}/crt/rt-thread/components/dfs"
"${microkernel_sdk_dir}/crt/rt-thread/components/drivers"
"${microkernel_sdk_dir}/crt/rt-thread/components/net"
"${microkernel_sdk_dir}/crt/rt-thread/components/net/netdev"
"${microkernel_sdk_dir}/crt/rt-thread/components/lwip-2.1.0"
"${microkernel_sdk_dir}/crt/rt-thread/include"
"${microkernel_sdk_dir}/crt/rt-thread/include/libc"
"${microkernel_sdk_dir}/crt/gcc"
"${microkernel_sdk_dir}/libc/include"
)
set(microkernel_apps_inc
"${microkernel_apps_dir}/hello"
)
set(microkernel_sdk_src
"${microkernel_sdk_dir}/crt/cplusplus/cxx_crt.cpp"
"${microkernel_sdk_dir}/crt/gcc/arch/arm/syscall.S"
"${microkernel_sdk_dir}/crt/rt-thread/src/rt_channel.c"
"${microkernel_sdk_dir}/crt/rt-thread/src/rt_completion.c"
"${microkernel_sdk_dir}/crt/rt-thread/src/rt_device.c"
"${microkernel_sdk_dir}/crt/rt-thread/src/rt_ipc.c"
"${microkernel_sdk_dir}/crt/rt-thread/src/rt_net.c"
"${microkernel_sdk_dir}/crt/rt-thread/src/rt_syscall.c"
"${microkernel_sdk_dir}/crt/rt-thread/src/rt_thread.c"
"${microkernel_sdk_dir}/crt/rt-thread/src/rt_timer.c"
"${microkernel_sdk_dir}/crt/rt-thread/src/stub.c"
)
set(microkernel_apps_src
"${microkernel_apps_dir}/hello/main.c"
)
set(CMAKE_EXECUTABLE_SUFFIX ".elf")
add_executable(${PROJECT_NAME} ${microkernel_apps_src} ${microkernel_sdk_src})
target_include_directories(${PROJECT_NAME} PRIVATE ${microkernel_sdk_inc} ${microkernel_apps_inc})
target_link_libraries(${PROJECT_NAME}
PRIVATE
-Wl,--start-group
"${CMAKE_SOURCE_DIR}/sdk/libc/lib/libc.a"
"${CMAKE_SOURCE_DIR}/sdk/libc/lib/libm.a"
"${CMAKE_SOURCE_DIR}/sdk/libc/lib/libcrt.a"
"libgcc.a"
-Wl,--end-group
-T ${microkernel_sdk_dir}/crt/gcc/arch/arm/gcc_arm.ld
)
编译测试:
如上是整个测试以及CMakeLists.txt讲解。有疑问,请私聊作者。
1.第二期“嵌入式与物联网开发技术”线上分享——RISC-V处理器嵌入式开发与应用
2.数字货币水到渠成,第三方支付功不可没,媒体不必过度解读!
3.有效利用Raspberry Pi的秘笈在这里!
4.为什么单片机内部RAM这么少?
5.PCB的未来发展趋势如何?
6.Imagination支持Google的Android GPU Inspector
免责声明:本文系网络转载,版权归原作者所有。如涉及作品版权问题,请与我们联系,我们将根据您提供的版权证明材料确认版权并支付稿酬或者删除内容。