提交
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
#声明编译环境
|
||||
|
||||
get_filename_component(MY_DIR_NAME "${CMAKE_SOURCE_DIR}" NAME)
|
||||
|
||||
#设备类型宏定义
|
||||
include($ENV{PROJECT_ROOT}/build/cmake/detect_target_product.cmake)
|
||||
|
||||
|
||||
# 定义宏 POWEROAD_COMPILED_LIB
|
||||
add_compile_definitions(POWEROAD_COMPILED_LIB)
|
||||
|
||||
#指定模块/程序名称 #-- 强制使用g++
|
||||
project(${MY_DIR_NAME} LANGUAGES CXX)
|
||||
|
||||
set(SRC_DIR "./")
|
||||
|
||||
message("--------------------------------cmake start [${PROJECT_NAME}]--------------------------------")
|
||||
|
||||
set(CURRENT_VERSION "${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}")
|
||||
|
||||
#通用编译选项
|
||||
list(APPEND generic_compile_flags "-fPIC" "-Wno-psabi" "-Wno-unused-result" "-Wno-narrowing")
|
||||
|
||||
#根据环境变量配置编译参数
|
||||
if ($ENV{pd_complier_name} STREQUAL "complier_arm")
|
||||
#配置处理器
|
||||
set(CMAKE_SYSTEM_PROCESSOR arm)
|
||||
else()
|
||||
#配置处理器
|
||||
set(CMAKE_SYSTEM_PROCESSOR arm64)
|
||||
endif()
|
||||
|
||||
# 设置 C++ 标准
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
#配置系统名称
|
||||
set(CMAKE_SYSTEM_NAME Linux)#配置编译器
|
||||
message("-- Ready to set ${TARGET_PRODUCT} compile flags: $ENV{arm_compile_flags}")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} $ENV{arm_compile_flags}")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} $ENV{arm_compile_flags}")
|
||||
|
||||
#配置sysroot路径
|
||||
set(CMAKE_SYSROOT $ENV{arm_sysroot_path})
|
||||
message("-- Ready to set ${TARGET_PRODUCT} sysroot path: $ENV{arm_sysroot_path}")
|
||||
|
||||
#根据编译器类型,声明导出库路径
|
||||
set(LIB_A_PATH "$ENV{PROJECT_ROOT}/out/$ENV{TARGET_PRODUCT}/lib/lib_a")
|
||||
set(LIB_SO_PATH "$ENV{PROJECT_ROOT}/out/$ENV{TARGET_PRODUCT}/lib/lib_so")
|
||||
|
||||
#配置输出目录
|
||||
set(LIB_EXE_OUT_PATH "$ENV{PROJECT_ROOT}/out/$ENV{TARGET_PRODUCT}/bin")
|
||||
message("-- Ready to set ${TARGET_PRODUCT} LIB_EXE_OUT_PATH: $ENV{LIB_EXE_OUT_PATH}")
|
||||
|
||||
#配置查找路径
|
||||
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)
|
||||
|
||||
|
||||
|
||||
#设置debug模式,断点有用
|
||||
set(CMAKE_BUILD_TYPE "Release") #Debug/Release
|
||||
|
||||
#依赖头文件路径
|
||||
include_directories(${CMAKE_SOURCE_DIR}/../../../include/public
|
||||
${CMAKE_SOURCE_DIR}/../../../include/interface
|
||||
${CMAKE_SOURCE_DIR}/../../../include/open
|
||||
${CMAKE_SOURCE_DIR}/../../../include/general_type
|
||||
${CMAKE_SOURCE_DIR}/../../../include/utility
|
||||
${CMAKE_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
# 查找src目录下的所有*.cpp,*.c源文件,并将文件列表保存到 DIR_LIB_SRCS 变量
|
||||
# 递归地查找所有.cpp文件
|
||||
file(GLOB_RECURSE CPP_SOURCES ${CMAKE_SOURCE_DIR}/${SRC_DIR}/*.cpp )
|
||||
# 递归地查找所有.c文件 #实测没用,只能编cpp
|
||||
file(GLOB_RECURSE C_SOURCES ${CMAKE_SOURCE_DIR}/${SRC_DIR}/*.c)
|
||||
|
||||
# 将两者合并到SRC_LIST列表中
|
||||
set(SRC_LIST ${C_SOURCES} ${CPP_SOURCES} )
|
||||
|
||||
|
||||
# 排除 demo/ 目录下的所有文件
|
||||
foreach(SOURCE IN LISTS SRC_LIST)
|
||||
if("${SOURCE}" MATCHES ".*/demo/.*" OR "${SOURCE}" MATCHES ".*/build/.*")
|
||||
list(REMOVE_ITEM SRC_LIST ${SOURCE})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
#message("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n ${SRC_LIST} \n################################################")
|
||||
|
||||
|
||||
# 提取current目录的父目录名称
|
||||
get_filename_component(PARENT_DIR "${CMAKE_SOURCE_DIR}" PATH)
|
||||
get_filename_component(PARENT_DIR_NAME "${PARENT_DIR}" NAME)
|
||||
|
||||
# 根据父目录名称决定编译为静态库还是动态库
|
||||
if("${PARENT_DIR_NAME}" STREQUAL "a_src")
|
||||
message("=========.a=======PARENT_DIR_NAME = ${PARENT_DIR_NAME}")
|
||||
#--------------------设置输出静态库-----------------------------------
|
||||
#设置生成目录
|
||||
set(LIBRARY_OUTPUT_PATH ${LIB_A_PATH})
|
||||
|
||||
#生成静态库.a文件
|
||||
add_library(${PROJECT_NAME} STATIC ${SRC_LIST})
|
||||
|
||||
#设置编译选项
|
||||
message("-- Ready to set generic compile flags: ${generic_compile_flags}")
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE ${generic_compile_flags})
|
||||
|
||||
elseif("${PARENT_DIR_NAME}" STREQUAL "so_src")
|
||||
message("=========.so=======PARENT_DIR_NAME = ${PARENT_DIR_NAME}")
|
||||
|
||||
|
||||
|
||||
#动态库输出路径
|
||||
set(LIBRARY_OUTPUT_PATH ${LIB_SO_PATH})
|
||||
add_library(${PROJECT_NAME} SHARED ${SRC_LIST})
|
||||
#设置编译选项
|
||||
message("-- Ready to set generic compile flags: ${generic_compile_flags}")
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE ${generic_compile_flags} "-fPIC")
|
||||
# =========================设置输出路径 ===============================
|
||||
# #生成动态库.so文件
|
||||
message(" PROJECT_NAME= ${PROJECT_NAME}")
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${LIB_SO_PATH})
|
||||
|
||||
else()
|
||||
message("=========.exc=======PARENT_DIR_NAME = ${PARENT_DIR_NAME}")
|
||||
message(FATAL_ERROR "sqlite directory not found in expected locations.")
|
||||
endif()
|
||||
@@ -0,0 +1,87 @@
|
||||
#!/bin/bash
|
||||
|
||||
cd "$(dirname "$(readlink -f "$0")")"
|
||||
|
||||
script_name=$(basename "$0")
|
||||
#if [ "$0" = "$script_name" ]; then echo "脚本被自身调用,请检查无效路径"; exit 1 ;fi
|
||||
|
||||
# 显示脚本执行时间
|
||||
start_time=$(date +%s); trap 'echo "$(print_execution_time $?)"' EXIT
|
||||
|
||||
# 计算并打印脚本执行时间函数
|
||||
function print_execution_time {
|
||||
end_time=$(date +%s); execution_time=$((end_time - start_time)); execution_time_formatted=$(date -u -d @$execution_time +"%T")
|
||||
if [ $1 -eq 0 ];then SET_COLOR="\e[32m "; else SET_COLOR="\e[31m error at $(pwd) \n\e[1m"; fi
|
||||
mydir_name="$(d=$(pwd); echo ${d##*/})"
|
||||
echo -e "${SET_COLOR} [$1] Compilation Time: $execution_time_formatted ( $mydir_name )\e[0m "
|
||||
}
|
||||
|
||||
current_project_path=$(pwd)
|
||||
export current_project_name=`echo ${current_project_path##*/}`
|
||||
echo "current_project_path = ${current_project_path}"
|
||||
|
||||
echo "=========================build shell start [lib${current_project_name}]============================="
|
||||
|
||||
pd_complier_type=${TARGET_PRODUCT}
|
||||
|
||||
if [ -z ${TARGET_PRODUCT} ];then
|
||||
PROJECT_ROOT=$(while [ ! -f "build/envsetup.sh" ]; do [ "$(pwd)" = "/" ] && exit 1; cd ..; done; pwd)
|
||||
if [ ! -z ${PROJECT_ROOT} ];then
|
||||
source ${PROJECT_ROOT}/build/envsetup.sh && lunch LAST
|
||||
if [ $? -eq 255 ];then exit 0; fi
|
||||
pd_complier_type=${TARGET_PRODUCT}
|
||||
fi
|
||||
fi
|
||||
echo -e " ready to build\e[34;1m ${pd_complier_type} \e[0m target [\e[34;1m ${current_project_name}\e[0m ] ......"
|
||||
unset LD_LIBRARY_PATH
|
||||
export pd_complier_name="$(if [[ "${TARGET_PRODUCT}" =~ "imx"* ]]; then echo "complier_arm"; else echo "complier_x86"; fi)"
|
||||
|
||||
export arm_sysroot_path=${SYSROOT}
|
||||
export arm_compile_flags=${CFLAGS}
|
||||
|
||||
echo "============================build shell start [lib${current_project_name}]===================================================="
|
||||
|
||||
|
||||
# set obj at: platform/out/build/xxxx/build
|
||||
check_dirs() { # check dir: process/ script/
|
||||
local dir="$1"; if [[ -d "$dir/process" && -d "$dir/script" ]]; then echo "$dir"; exit 0;fi
|
||||
local parent="${dir%/*}"; if [[ "$parent" != "$dir" ]]; then check_dirs "$parent"; else echo "$(pwd)"; fi
|
||||
}
|
||||
base_folder="$(echo ${PROJECT_ROOT}|tr -s '/')"
|
||||
|
||||
if [[ $current_project_path =~ "$base_folder" ]] && [ ! -z $base_folder ]; then
|
||||
echo ""
|
||||
else
|
||||
echo "base_folder = $base_folder"
|
||||
echo "current_project_path = $current_project_path"
|
||||
echo -e "\e[31m Error: 环境配置不匹配,在当前项目下请重新配置:\n\e[35m\t source build/envsetup.sh \e[0m"
|
||||
fi
|
||||
|
||||
build_path=$(echo "$current_project_path" | sed "s|${base_folder}|${base_folder}/out/build/${pd_complier_type}/|g")
|
||||
echo "build_path = ${build_path}"
|
||||
|
||||
if [[ $1 == "clean" ]] || [[ $1 == "-c" ]] || [[ $1 == "all" ]];then
|
||||
if [[ "$build_path" == *"/out/build/"* ]]; then
|
||||
rm -rvf ${build_path}
|
||||
else
|
||||
if [ -d ${build_path} ];then
|
||||
find "${build_path}" -name '*.o' -print0 | xargs -r0 rm -f
|
||||
find ${build_path} -name 'cmake_install.cmake' -print0 | xargs -r0 rm -f
|
||||
find ${build_path} -name 'CMakeCache.txt' -print0 | xargs -r0 rm -f
|
||||
find ${build_path} -type d -name 'CMakeFiles' -print0 | xargs -r0 rm -rf
|
||||
fi
|
||||
fi
|
||||
echo " clean done."
|
||||
echo "====================================================build shell end [lib${current_project_name}]===================================================="
|
||||
if [[ $1 != "all" ]];then exit 0; fi
|
||||
fi
|
||||
|
||||
|
||||
# build path
|
||||
mkdir -p ${build_path}
|
||||
cmake -B ${build_path}
|
||||
echo "----------------make start----------------"
|
||||
cmake --build "${build_path}" -j4 || exit $?
|
||||
|
||||
echo "===============================build shell end [lib${current_project_name}] [${pd_complier_type}]===================================================="
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,22 @@
|
||||
|
||||
MYNAME = $(notdir $(CURDIR))
|
||||
|
||||
|
||||
.PHONY: build all clean run
|
||||
|
||||
build:
|
||||
./build.sh $@
|
||||
|
||||
all: clean
|
||||
./build.sh $@
|
||||
|
||||
#rebuild: clean build
|
||||
# ./build.sh clean && ./build.sh
|
||||
|
||||
clean:
|
||||
./build.sh clean
|
||||
|
||||
|
||||
run: build
|
||||
../../board_dir/bin/$(MYNAME)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user