mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
209 lines
6.8 KiB
CMake
209 lines
6.8 KiB
CMake
cmake_minimum_required(VERSION 3.5)
|
|
|
|
unset(CLANG_TIDY_EXE CACHE)
|
|
set(CMAKE_SOURCE_DIR_IPCSDK "${CMAKE_CURRENT_SOURCE_DIR}" CACHE STRING INTERNAL)
|
|
include(build/global_config.cmake)
|
|
|
|
project(fancycode)
|
|
|
|
# set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
|
|
|
|
message("platform = ${TARGET_PLATFORM}")
|
|
message("platform PATH = ${PLATFORM_PATH}")
|
|
|
|
add_custom_target(
|
|
sdk_clean
|
|
COMMAND echo "sdk clean finished."
|
|
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
|
)
|
|
|
|
# Gdb debug
|
|
include(build/sdk_config.cmake)
|
|
|
|
# 查看是工具链支持情况
|
|
include(CheckCXXCompilerFlag)
|
|
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
|
|
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
|
|
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
|
|
|
|
# 获取所有修改过的文件
|
|
execute_process(
|
|
COMMAND git diff --name-only --diff-filter=ACMRT
|
|
OUTPUT_VARIABLE MODIFIED_FILES
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
|
)
|
|
set(ALL_MODEFIED_FILES "")
|
|
string(LENGTH "${MODIFIED_FILES}" GIT_RESULT_STRING_LENGTH)
|
|
if(GIT_RESULT_STRING_LENGTH EQUAL 0)
|
|
message("Nothing changed.")
|
|
else()
|
|
string(REPLACE "\n" ";" MODIFIED_FILES_LIST ${MODIFIED_FILES})
|
|
endif()
|
|
# 遍历每个文件
|
|
foreach(FILE ${MODIFIED_FILES_LIST})
|
|
# 检查文件扩展名,只格式化.cpp和.h文件
|
|
get_filename_component(FILE_EXT ${FILE} EXT)
|
|
if(FILE_EXT MATCHES "\\.(c|cpp|h)$")
|
|
set(ALL_MODEFIED_FILES "${ALL_MODEFIED_FILES};${FILE}")
|
|
endif()
|
|
endforeach()
|
|
# 获取未跟踪的文件
|
|
execute_process(
|
|
COMMAND git ls-files --others --exclude-standard
|
|
OUTPUT_VARIABLE UNTRACKED_FILES
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
|
)
|
|
string(LENGTH "${UNTRACKED_FILES}" GIT_RESULT_STRING_LENGTH)
|
|
if(GIT_RESULT_STRING_LENGTH EQUAL 0)
|
|
else()
|
|
string(REPLACE "\n" ";" UNTRACKED_FILES_LIST ${UNTRACKED_FILES})
|
|
endif()
|
|
# 遍历每个文件
|
|
foreach(FILE ${UNTRACKED_FILES_LIST})
|
|
# 检查文件扩展名,只格式化.cpp和.h文件
|
|
get_filename_component(FILE_EXT ${FILE} EXT)
|
|
if(FILE_EXT MATCHES "\\.(c|cpp|h)$")
|
|
set(ALL_MODEFIED_FILES "${ALL_MODEFIED_FILES};${FILE}")
|
|
endif()
|
|
endforeach()
|
|
string(LENGTH "${ALL_MODEFIED_FILES}" MODIFIED_STRING_LENGTH)
|
|
# find the clang-tidy tools
|
|
unset(CLANG_TIDY_EXE CACHE)
|
|
unset(CLANG_TIDY_FIND CACHE)
|
|
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
|
|
find_program(CLANG_TIDY_FIND NAMES clang-tidy PATHS ${LLVM_PATH}/build/bin)
|
|
if(CLANG_TIDY_FIND)
|
|
message(STATUS "clang-tidy found: ${CLANG_TIDY_FIND}")
|
|
# set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE}" "-header-filter=no.h -system-headers=no.h -checks=modernize-use-override")
|
|
set(CLANG_TIDY_EXE ${CLANG_TIDY_FIND} CACHE STRING INTERNAL)
|
|
message("CLANG_TIDY_EXE = ${CLANG_TIDY_EXE}")
|
|
|
|
if(MODIFIED_STRING_LENGTH GREATER 0)
|
|
add_custom_target(
|
|
check_modified_code
|
|
COMMAND ${CLANG_TIDY_EXE}
|
|
-checks='${CLANG_TIDY_CHECKS}'
|
|
--header-filter=.*
|
|
--system-headers=false
|
|
${ALL_MODEFIED_FILES}
|
|
${CLANG_TIDY_CONFIG}
|
|
--line-filter='[{\"name\":\"${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include/getest/*.h\"}]'
|
|
-p ${PLATFORM_PATH}/cmake-shell
|
|
WORKING_DIRECTORY ${PLATFORM_PATH}
|
|
)
|
|
endif()
|
|
|
|
else()
|
|
# message(FATAL_ERROR "See ${CMAKE_SOURCE_DIR_IPCSDK}/doc.")
|
|
message(FATAL_ERROR "You set support clang-tidy, but clang-tidy not found.
|
|
Check path ${LLVM_PATH}/build/bin, weather clang-tidy exist.
|
|
How to install tools?
|
|
See ${IPC_SDK_PATH}/doc/clang-tidy_user_guide.md
|
|
How to disable clang-tidy tool?
|
|
Modify: set(CLANG_TIDY_SUPPORT \"false\")
|
|
See:${IPC_SDK_PATH}/builde/global_config.cmake")
|
|
endif()
|
|
endif()
|
|
# find the clang-format tools
|
|
unset(CLANG_FORMAT_EXE CACHE)
|
|
unset(CLANG_FORMAT_FIND CACHE)
|
|
if ("${CLANG_FORMAT_SUPPORT}" MATCHES "true")
|
|
find_program(CLANG_FORMAT_FIND NAMES clang-format PATHS ${LLVM_PATH}/build/bin)
|
|
if(CLANG_FORMAT_FIND)
|
|
message(STATUS "clang-format found: ${CLANG_FORMAT_FIND}")
|
|
set(CLANG_FORMAT_EXE ${CLANG_FORMAT_FIND} CACHE STRING INTERNAL)
|
|
message("CLANG_FORMAT_EXE = ${CLANG_FORMAT_EXE}")
|
|
|
|
if(MODIFIED_STRING_LENGTH GREATER 0)
|
|
add_custom_target(
|
|
format_modified_code
|
|
COMMAND ${CLANG_FORMAT_EXE}
|
|
-style=file
|
|
-i ${ALL_MODEFIED_FILES}
|
|
WORKING_DIRECTORY ${PLATFORM_PATH}
|
|
)
|
|
endif()
|
|
|
|
else()
|
|
message(FATAL_ERROR "You set support clang-format, but clang-format not found.
|
|
Check path ${LLVM_PATH}/build/bin, weather clang-format exist.
|
|
How to install tools?
|
|
See ${IPC_SDK_PATH}/doc/clang-tidy_user_guide.md
|
|
How to disable clang-format tool?
|
|
Modify: set(CLANG_FORMAT_SUPPORT \"false\")
|
|
See:${IPC_SDK_PATH}/builde/global_config.cmake")
|
|
endif()
|
|
endif()
|
|
|
|
if(MODIFIED_STRING_LENGTH GREATER 0)
|
|
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true" AND "${CLANG_FORMAT_SUPPORT}" MATCHES "true")
|
|
add_custom_target(
|
|
improve_modified_code
|
|
DEPENDS format_modified_code check_modified_code
|
|
)
|
|
endif()
|
|
endif()
|
|
|
|
if(${TARGET_PLATFORM} MATCHES ${DEFINE_LINUX})
|
|
# execute_process(COMMAND sh build_lvgl_for_cmakelist.sh ${TARGET_PLATFORM} ${CMAKE_SOURCE_DIR_IPCSDK} WORKING_DIRECTORY ${EXTERNAL_SOURCE_PATH}/lvglLinux-x86/)
|
|
# add_subdirectory(external/lvglLinux-x86)
|
|
endif()
|
|
|
|
#Add macro definition
|
|
# add_definitions(-DCONFIG_FILE_PATH=\"${CONFIG_FILE_PATH}\")
|
|
|
|
# Config message of main thread
|
|
unset(MAIN_INCLUDE_PATH CACHE)
|
|
set(MAIN_INCLUDE_PATH "" CACHE STRING INTERNAL)
|
|
unset(MAIN_SRC_FILE CACHE)
|
|
set(MAIN_SRC_FILE "" CACHE STRING INTERNAL)
|
|
unset(MAIN_LINK_LIB CACHE)
|
|
set(MAIN_LINK_LIB "" CACHE STRING INTERNAL)
|
|
|
|
# Config message for test code.
|
|
unset(TEST_LINK_LIB CACHE)
|
|
set(TEST_LINK_LIB "" CACHE STRING INTERNAL)
|
|
unset(TEST_LINUX_MOCK CACHE)
|
|
set(TEST_LINUX_MOCK "" CACHE STRING INTERNAL)
|
|
# if(${TARGET_PLATFORM} MATCHES ${DEFINE_LINUX})
|
|
set(TEST_LINK_LIB "testUtils" CACHE STRING INTERNAL FORCE)
|
|
# endif()
|
|
|
|
# 添加编译目录
|
|
add_subdirectory(external)
|
|
# 检查子目录 application 是否存在,存在再添加
|
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
|
|
message(STATUS "application exists, add application to project.")
|
|
add_subdirectory(application)
|
|
else()
|
|
message(STATUS "application not exists.")
|
|
endif()
|
|
add_subdirectory(middleware)
|
|
add_subdirectory(utils)
|
|
add_subdirectory(hal)
|
|
# add_subdirectory(customization)
|
|
|
|
string(COMPARE EQUAL "${PLATFORM_PATH}" "" value)
|
|
message("The platform path is \"${PLATFORM_PATH}\".")
|
|
if (value EQUAL 0) #变量被设置了
|
|
message("build chip board code.")
|
|
# add_subdirectory(${PLATFORM_PATH})
|
|
# aux_source_directory(${PLATFORM_PATH})
|
|
endif()
|
|
|
|
message("MAIN_INCLUDE_PATH = ${MAIN_INCLUDE_PATH}")
|
|
message("MAIN_SRC_FILE = ${MAIN_SRC_FILE}")
|
|
message("MAIN_LINK_LIB = ${MAIN_LINK_LIB}")
|
|
# 检查子目录 test 是否存在,存在再添加
|
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
|
|
message(STATUS "test exists, add test to project.")
|
|
add_subdirectory(test)
|
|
else()
|
|
message(STATUS "test not exists.")
|
|
endif()
|
|
|
|
# include(build/global_config.cmake) |