cmake recode


1. 创建build文件夹

2.在工程目录下创建CMakeLists.txt

cmake_minimum_required(VERSION 3.5)

project(HELLO)

set(SRC_LIST hello.c)
add_executable(hello ${SRC_LIST})

在build目录下执行命令 cmake ..

在build目录下执行命令 make

3.在工程目录下创建arm-linux-setip.cmake(交叉编译用)

set(CMAKE_SYSTEM_NAME Linux)        #设置目标系统名字
set(CMAKE_SYSTEM_PROCESSOR arm)     #设置目标处理器架构

#指定编译器的sysroot路径
set(TOOLCHAIN_DIR /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots)
set(CMAKE_SYSROOT ${TOOLCHAIN_DIR}/cortexa7hf-neon-poky-linux-gnueabi)
set(CMAKE_C_COMPILER ${TOOLCHAIN_DIR}/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++)

#为编译器添加编译选项
set(CMAKE_C_FLAGS "-march=armv7ve -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7")
set(CMAKE_CXX_FLAGS "-march=armv7ve -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7")

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

在build目录下执行命令

cmake -DCMAKE_TOOLCHAIN_FILE=../arm-linux-setup.cmake ..

在build目录下执行命令 make

你可能感兴趣的:(cmake)