-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
executable file
·138 lines (123 loc) · 3.87 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# ------------------------------------------------------------------------
# Author : Weilun Fong | wlf@zhishan-iot.tk
# Date : 2022-03-03
# Description: project Makefile
# E-mail : mcu@zhishan-iot.tk
# Make-tool : CMake
# Page : https://hw.zhishan-iot.tk/page/hml/detail/fwlib_st11.html
# Project : HML_FwLib_STC11
# Version : v0.0.2
# ------------------------------------------------------------------------
# CMake require
cmake_minimum_required(VERSION 3.17 FATAL_ERROR)
# Config toolchain
set(CMAKE_TOOLCHAIN_FILE cmake/toolchain.cmake)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
# Project define
project(
HML_FwLib_STC11
DESCRIPTION "A lite firmware library for STC micro STC11 series MCU based on SDCC complier"
LANGUAGES C)
# Path define
set(BUILDDIR ${CMAKE_SOURCE_DIR}/build)
set(CMAKEDIR ${CMAKE_SOURCE_DIR}/cmake)
# File define
set(LIB libhml_stc11)
set(EXECUTABLE_NAME output)
aux_source_directory(${CMAKE_SOURCE_DIR}/src SOURCES)
# ----------------------------------------
# Compile rule
# ----------------------------------------
# Load config
include(${CMAKEDIR}/config.cmake)
include(${CMAKEDIR}/version.cmake)
include(${CMAKEDIR}/cflags.cmake)
# Print control
set(CMAKE_VERBOSE_MAKEFILE ${VERBOSE})
# Build library
include_directories(${CMAKE_SOURCE_DIR}/inc)
add_library(${LIB} STATIC ${SOURCES})
# Build executable
if(DEFINED EXECUTABLE_C)
add_executable(${EXECUTABLE_NAME} ${EXECUTABLE_C})
target_link_libraries(${EXECUTABLE_NAME} ${LIB})
# generate a bin file after build
add_custom_command(TARGET ${EXECUTABLE_NAME} POST_BUILD
COMMENT
"Generate .hex file finally"
DEPENDS
${EXECUTABLE_NAME}.ihx
COMMAND
${PACKIHX} ${EXECUTABLE_NAME}.ihx > ${EXECUTABLE_NAME}.hex
)
# custom clean
SET(additional_clean_files ${EXECUTABLE_NAME}.lk ${EXECUTABLE_NAME}.map ${EXECUTABLE_NAME}.mem ${EXECUTABLE_NAME}.hex)
set_target_properties(
${EXECUTABLE_NAME}
PROPERTIES
ADDITIONAL_CLEAN_FILES "${additional_clean_files}"
)
endif()
# ----------------------------------------
# Custom targets
# ----------------------------------------
# target <distclean>: clean all temporay and output files
add_custom_target(distclean
COMMENT
"Clean all temporay files"
COMMAND
rm -rf ${BUILDDIR}/*
)
# target <library>: build library file
add_custom_target(library
DEPENDS
${LIB}
)
# target <rebuild>: clean all temporay and output files
add_custom_target(rebuild
COMMENT
"Rebuild project"
COMMAND
${CMAKE_COMMAND} --build . -- clean && rm -f ${EXECUTABLE_NAME}*
COMMAND
nproc | xargs ${CMAKE_COMMAND} --build . --parallel
VERBATIM
)
# target <version>: show version information
add_custom_target(version
COMMAND
echo -e "\
\\n\
General purpose CMakeLists for HML firmware library. \\n\
Copyright(c) 2021-2022 ZHISHAN-IoT, all rights reserved. \\n\
\\n\
Adapted for ${PROJECT_NAME} v${PROJECT_VERSION} by Weilun Fong <wlf@zhishan-iot.tk> \\n\
Report bugs and patches to <wlf@zhishan-iot.tk>\\n"
VERBATIM
)
# target <usage>: show usage
add_custom_target(usage
COMMAND
echo -e "\
\\n\
Build: \\n\
all - Build target, include HML library file and user code. \\n\
library - Only build HML library file. \\n\
rebuild - Rebuild project. \\n\
\\n\
Clean: \\n\
clean - Delete all temporary and output files.\\n\
distclean - Delete all files generated by CMake. \\n\
\\n\
Info: \\n\
help - CMake builtin target, list all executable targets. \\n\
usage - Show usage. \\n\
version - Show version information. \\n\
\\n\
Report bugs and patches to <wlf@zhishan-iot.tk>\\n"
VERBATIM
)
# ----------------------------------------
# Show build information
# ----------------------------------------
include(${CMAKEDIR}/info.cmake)