CMakeLists方式交叉编译CMakeLists.txt模板: 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152# 设置工程名称project (Fire_control)# 设置可执行文件名称set(MY_TARGET Fire_test)# 需要链接的动态链接库set(EXTRA_LIBS libpthread-2.19-2014.07.so )# CMAKE最小版本cmake_minimum_required (VERSION 2.6)# 设置目标平台系统set(CMAKE_SYSTEM_NAME Linux)# 设置交叉编译库路径set(CMAKE_FIND_ROOT_PATH /usr/arm-linux-gnueabi/lib /usr/arm-linux-gnueabi/include /usr/local/arm/arm-linux-gnueabihf-4.9)set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)#只在交叉编译库路径中寻找set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)# 设置交叉编译器set(CMAKE_C_COMPILER /usr/local/arm/arm-linux-gnueabihf-4.9/bin/arm-linux-gnueabihf-gcc)set(CMAKE_CXX_COMPILER /usr/local/arm/arm-linux-gnueabihf-4.9/bin/arm-linux-gnueabihf-g++)set(CMAKE_C_EXTENSIONS "-pipe -g -Wall -W -fPIE")set(CMAKE_CXX_EXTENSIONS "-pipe -g -Wall -W -fPIE")#设置执行文件输出目录set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)#设置库输出路径set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)message("++++++++++++++Start Build+++++++++++++++++")# 添加头文件目录include_directories(${PROJECT_SOURCE_DIR}/HARDWARE/inc ${PROJECT_SOURCE_DIR}/COMMON/inc )# 添加源文件目录aux_source_directory(${PROJECT_SOURCE_DIR}/HARDWARE/src HARDWARESRC)aux_source_directory(${PROJECT_SOURCE_DIR}/COMMON/src COMMONSRC)aux_source_directory(${PROJECT_SOURCE_DIR}/USER USRSRC)# 添加子目录 子目录里面放一些别的编译好的模块#ADD_SUBDIRECTORY(src)# 链接库搜索路径link_directories(/usr/local/arm/arm-linux-gnueabihf-4.9/arm-linux-gnueabihf/libc/lib/arm-linux-gnueabihf/)# 添加动态库link_libraries(${EXTRA_LIBS})# 添加可执行文件(可执行文件名 [配置] 源文件)add_executable(${MY_TARGET} ${USRSRC} ${HARDWARESRC} ${COMMONSRC} )# 执行文件链接属性TARGET_LINK_LIBRARIES(${MY_TARGET} ${EXTRA_LIBS})