kunlang_tbox/CMakeLists.txt

109 lines
3.3 KiB
CMake
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

cmake_minimum_required(VERSION 3.12)
project(kunlang_remake LANGUAGES C CXX)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# =================================================
# 调试符号配置(关键修改)
# =================================================
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DDEBUG")
set(CMAKE_C_FLAGS_DEBUG "-O0 -g -DDEBUG")
# Release 也保留符号(方便现场 gdb
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -g -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "-O2 -g -DNDEBUG")
# =================================================
# 基本配置
# =================================================
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif()
# 构建产物输出到项目根目录/bin
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
# =================================================
# 编译 / 链接选项
# =================================================
# 通用警告
add_compile_options(
-Wall
-Wextra
-ffunction-sections
-fdata-sections
)
# 根据构建类型追加编译选项
if(CMAKE_BUILD_TYPE STREQUAL "Release")
add_compile_options(-O2)
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(-O0)
endif()
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} -static -Wl,--gc-sections"
)
# =================================================
# 源文件
# =================================================
file(GLOB_RECURSE SOURCES_CPP CONFIGURE_DEPENDS src/*.cpp)
file(GLOB_RECURSE SOURCES_C CONFIGURE_DEPENDS src/*.c)
set(SOURCES ${SOURCES_CPP} ${SOURCES_C})
add_executable(${PROJECT_NAME} ${SOURCES})
# =================================================
# 头文件路径
# =================================================
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/include/common
${CMAKE_SOURCE_DIR}/include/network
${CMAKE_SOURCE_DIR}/include/can
${CMAKE_SOURCE_DIR}/include/serial
${CMAKE_SOURCE_DIR}/include/protocol
${CMAKE_SOURCE_DIR}/include/business
${CMAKE_SOURCE_DIR}/include/business/instance
${CMAKE_SOURCE_DIR}/include/business/remote_ctrl
${CMAKE_SOURCE_DIR}/include/business/tbox
${CMAKE_SOURCE_DIR}/include/config
$ENV{HOME}/aarch64_env
$ENV{HOME}/aarch64_env/openssl/include
$ENV{HOME}/aarch64_env/paho/include
)
# =================================================
# 目标级编译选项
# =================================================
target_compile_options(${PROJECT_NAME} PRIVATE
-static
-static-libstdc++
-static-libgcc
)
# =================================================
# 静态库链接
# =================================================
target_link_libraries(${PROJECT_NAME}
$ENV{HOME}/aarch64_env/toolchain/aarch64-linux-musl/lib/libpthread.a
$ENV{HOME}/aarch64_env/toolchain/aarch64-linux-musl/lib/libdl.a
$ENV{HOME}/aarch64_env/toolchain/aarch64-linux-musl/lib/libm.a
$ENV{HOME}/aarch64_env/toolchain/aarch64-linux-musl/lib/libc.a
# $ENV{HOME}/aarch64_env/paho/lib/libpaho-mqtt3as.a
$ENV{HOME}/aarch64_env/paho/lib/libpaho-mqtt3a.a
$ENV{HOME}/aarch64_env/paho/lib/libpaho-mqttpp3.a
# $ENV{HOME}/aarch64_env/openssl/lib/libssl.a
# $ENV{HOME}/aarch64_env/openssl/lib/libcrypto.a
)