-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
82 lines (67 loc) · 2.6 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
cmake_minimum_required(VERSION 3.20.0 FATAL_ERROR)
# Set up compiler and mcu arch
set(COMPILER_TYPE "arm-none-eabi") # options: 'armcc' or 'arm-none-eabi'
set(MCU_ARCH_TYPE "cortex_m4") # options: 'cortex_m0', 'cortex_m3' ...
set(MCU_MFPU_TYPE "default") # options: 'sp', 'dp', 'none', 'default'
# Set up flasher config
set(FLASHER_TYPE_NAME "jlink")
set(FLASHER_PORT_TYPE "swd")
set(FLASHER_MCPU_NAME "STM32F407ZG")
# toolchain options
option(NO_SPEC_FLAGS "No Default SPEC FLAGS" ON)
# Include toolchain and flasher config
include(${CMAKE_SOURCE_DIR}/cmake/toolchain/${COMPILER_TYPE}/${MCU_ARCH_TYPE}.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/utils/kconfig.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/flasher/${FLASHER_TYPE_NAME}-${FLASHER_PORT_TYPE}.cmake)
# Set up project name
set(PRJ_NAME "liteos_cmake")
# Set up the project
project(${PRJ_NAME}
VERSION "0.1.0"
LANGUAGES C ASM CXX)
# limit compiler version
check_compiler_version("8.3")
# Include kconfig
kconfig_include(".config"
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
OUTPUT_HEADER_NAME "menuconfig.h")
# Global config
include(config.cmake)
# Redirect static lib path
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
link_directories(${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
# Auto add subdirectory
file(GLOB sub_files RELATIVE "${CMAKE_CURRENT_LIST_DIR}" "${CMAKE_CURRENT_LIST_DIR}/*")
foreach(file_name ${sub_files})
if(IS_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/${file_name}")
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${file_name}/CMakeLists.txt")
add_subdirectory("${file_name}")
endif()
endif()
endforeach()
# Add executable
add_executable(${CMAKE_PROJECT_NAME} $<TARGET_OBJECTS:${LITEOS_PLATFORM}>)
target_link_libraries(${CMAKE_PROJECT_NAME} ${LITEOS_BASELIB})
# Output .hex .bin file
output_binary_files(${CMAKE_PROJECT_NAME})
output_flash_command(${CMAKE_PROJECT_NAME})
# support menuconfig
add_custom_target(menuconfig
COMMAND python "${CMAKE_SOURCE_DIR}/tools/menuconfig/usr_config.py"
COMMAND ${CMAKE_COMMAND} -E rm -f ${LITEOS_MENUCONFIG_H}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
USES_TERMINAL VERBATIM)
# flash command
if(CMAKE_HOST_WIN32)
add_custom_target(flash
COMMAND cmd /C .\\flash.bat
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
USES_TERMINAL VERBATIM)
else()
add_custom_target(flash
COMMAND bash ./flash.bat
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
USES_TERMINAL VERBATIM)
endif()