加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
CMakeLists_one.txt 5.20 KB
一键复制 编辑 原始数据 按行查看 历史
think3r 提交于 2022-09-24 18:13 . half simpleperf 使用
# @think3r 直接生成可执行测试文件;
#====================================================================================================================
# cmake 内置命令支持大写、小写或者混合使用; 而内置变量是区分大小写的,或者干脆就说,cmake的所有变量都是区分大小写的
# cmake最低版本需求,不加入此行会受到警告信息
cmake_minimum_required(VERSION 3.0.0)
# 配置交叉编译工具链
# 自动导入
set(ANDROID_NDK "/Users/think3r/bin/android-ndk-r23")
set(CMAKE_TOOLCHAIN_FILE "${ANDROID_NDK}/build/cmake/android.toolchain.cmake")
#set(CMAKE_TOOLCHAIN_FILE "$ENV{ANDROID_NDK}/build/cmake/android.toolchain.cmake")
#set(ANDROID_TOOLCHAIN "gcc")
set(ANDROID_ABI "arm64-v8a")
#set(ANDROID_ABI "armeabi-v7a")
set(ANDROID_PLATFORM "android-24")
# 手动配置
# set(CMAKE_SYSTEM_NAME Linux)
# set(ndk_path "/home/think3r/bin/android-ndk-r14b")
# set(ndk_toolchains_prefix "${ndk_path}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-")
# set(CMAKE_C_COMPILER "${ndk_toolchains_prefix}gcc")
# set(CMAKE_CXX_COMPILER "${ndk_toolchains_prefix}g++")
# set(CMAKE_SYSROOT "${ndk_path}/platforms/android-14/arch-arm") # --sysroot 选项
#====================================================================================================================
project(Osd_Neon_Draw_Project C CXX ASM) #项目名称
set(Library_OutPutName "neonOsd")
set(My_Target "neonOsdDemo") #可执行文件名称
# 是否导出编译过程到 compile_commands.json 文件中
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
message(STATUS "----------------------------------------->")
message(STATUS "project name: " ${PROJECT_NAME})
message(STATUS "PROJECT_BINARY_DIR:" ${PROJECT_BINARY_DIR})
message(STATUS "PROJECT_SOURCE_DIR:" ${PROJECT_SOURCE_DIR})
message(STATUS "CMAKE_C_COMPILER:" ${CMAKE_C_COMPILER})
message(STATUS "CMAKE_CXX_COMPILER:" ${CMAKE_CXX_COMPILER})
message(STATUS "CMAKE_SYSROOT:" ${CMAKE_SYSROOT})
message(STATUS "<-----------------------------------------")
#message(SEND_ERROR "test apoidjacposidjcapsoidj")
#message(FATAL_ERROR "test apoidjacposidjcapsoidj")
# 配置编译的宏
set(gnu_flags " -Wall -Wno-unused -Wconversion -Wno-uninitialized -Wno-sign-conversion ")
set(neno_flags "-mfloat-abi=softfp -mfpu=neon-vfpv4 ")
set(android_5_flags "-fPIE -pie ")
set(CMAKE_CXX_FLAGS " ${gnu_flags} ${neno_flags} ${android_5_flags} ")
set(CMAKE_C_FLAGS " ${gnu_flags} ${neno_flags} ${android_5_flags} ")
#======================================== 库的生成 =================================================================
# 头文件/源文件包含路径
include_directories(./osd_Draw)
aux_source_directory(./osd_Draw src_base_List)
# libneonOsd.so 和 libneonOsd.a
add_library(${Library_OutPutName}_shared SHARED ${src_base_List}) # add_library 模块名字不能一样;
add_library(${Library_OutPutName}_static STATIC ${src_base_List})
# 重命名 add_library 中的模块名字,
set_target_properties(${Library_OutPutName}_shared PROPERTIES
OUTPUT_NAME ${Library_OutPutName}
COMPILE_FLAGS " -O2 ")
set_target_properties(${Library_OutPutName}_static PROPERTIES
OUTPUT_NAME ${Library_OutPutName}
COMPILE_FLAGS " -O2 ")
# 设置动态库版本号, 主要是为了解决 linux 上的 dll-hell 问题;
# [LINUX下动态库及版本号控制](https://blog.csdn.net/David_xtd/article/details/7045792)
# {libname.so.x.y.z (real name) -> x是主版本号(Major Version Number),y是次版本号(Minor Version Number),z是发布版本号(Release Version Number) }
set_target_properties(${Library_OutPutName}_shared PROPERTIES VERSION 1.2.3 SOVERSION 1)
# 安装共享库和头文件:
# 设置库文件文件输出目录
#set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/install/lib)
install(TARGETS ${Library_OutPutName}_shared ${Library_OutPutName}_static
LIBRARY DESTINATION ${PROJECT_SOURCE_DIR}/install/lib
ARCHIVE DESTINATION ${PROJECT_SOURCE_DIR}/install/lib)
file(GLOB lib_include_files ./osd_Draw/*.h)
install(FILES ${lib_include_files}
DESTINATION ${PROJECT_SOURCE_DIR}/install/include)
#========================================== 测试 demo 的生成 =======================================================
# 头文件/源文件包含路径
include_directories(./demo/inc/)
include_directories(${PROJECT_SOURCE_DIR}/osd_Draw/)
# 把当前 src下所有源代码文件和头文件加入变量中
aux_source_directory(./demo/src/ src_demo_List)
# 链接文件夹路径 (使用绝对路径可避免报错)
link_directories(${PROJECT_BINARY_DIR}/)
# link_libraries -> Link libraries to all targets added later.
# 静态库 (add_executable 之前指定)
link_libraries(lib${Library_OutPutName}.a)
add_executable(${My_Target} ${src_demo_List})
target_link_libraries(${My_Target} -lm -ldl -v)
# 配置依赖关系(需在对应 target 添加之后进行配置);
add_dependencies(${My_Target} ${Library_OutPutName}_shared ${Library_OutPutName}_static )
# make install
install(TARGETS ${My_Target} DESTINATION ${PROJECT_SOURCE_DIR}/install
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE)
install(FILES ${PROJECT_SOURCE_DIR}/demo/ASCII8 ${PROJECT_SOURCE_DIR}/demo/HZK16
DESTINATION ${PROJECT_SOURCE_DIR}/install)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化