Skip to content

Commit a4cb90c

Browse files
committed
init
0 parents  commit a4cb90c

29 files changed

+1306
-0
lines changed

.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4
6+
charset = utf-8
7+
trim_trailing_whitespace = false
8+
insert_final_newline = false

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "kendryte-standalone-sdk"]
2+
path = kendryte-standalone-sdk
3+
url = https://github.com/kendryte/kendryte-standalone-sdk.git
4+
[submodule "wasm3"]
5+
path = wasm3
6+
url = https://github.com/wasm3/wasm3.git

components/cmake/CMakeLists.txt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
### This file is used for build library standalone.
2+
3+
# set this will supress some warnings
4+
set(BUILDING_SDK "yes" CACHE INTERNAL "")
5+
6+
# basic config
7+
cmake_minimum_required(VERSION 3.0)
8+
include(./common.cmake)
9+
project(kendryte)
10+
11+
# config self use headers
12+
include(./macros.internal.cmake)
13+
header_directories(${SDK_ROOT}/lib)
14+
15+
# include lib make file
16+
include(../lib/CMakeLists.txt)
17+
18+
# find headers files to INSTALL
19+
file(GLOB_RECURSE LIB_HEADERS
20+
"../lib/*.h"
21+
"../lib/*.hpp"
22+
)
23+
set_target_properties(kendryte PROPERTIES PUBLIC_HEADER "${LIB_HEADERS}")
24+
25+
# copy .a file and headers
26+
install(TARGETS kendryte
27+
EXPORT kendryte
28+
ARCHIVE
29+
DESTINATION ${CMAKE_BINARY_DIR}/archive
30+
PUBLIC_HEADER DESTINATION ${CMAKE_BINARY_DIR}/archive/include
31+
)
32+
33+
# copy utils files
34+
install(DIRECTORY
35+
../lds
36+
../utils
37+
../cmake
38+
DESTINATION ${CMAKE_BINARY_DIR}/archive
39+
PATTERN "*internal*" EXCLUDE
40+
PATTERN "CMakeLists.txt" EXCLUDE
41+
)
42+
43+
# show information
44+
include(./dump-config.cmake)

components/cmake/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
prepend `common.cmake` before
2+
3+
append `executable.cmake` after

components/cmake/common.cmake

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
cmake_minimum_required(VERSION 3.0)
2+
3+
include(${CMAKE_CURRENT_LIST_DIR}/macros.cmake)
4+
5+
global_set(CMAKE_C_COMPILER_WORKS 1)
6+
global_set(CMAKE_CXX_COMPILER_WORKS 1)
7+
8+
global_set(CMAKE_SYSTEM_NAME "Generic")
9+
if (NOT CMAKE_BUILD_TYPE)
10+
global_set(CMAKE_BUILD_TYPE Debug)
11+
else ()
12+
if ((NOT CMAKE_BUILD_TYPE STREQUAL "Debug") AND (NOT CMAKE_BUILD_TYPE STREQUAL "Release"))
13+
message(FATAL_ERROR "CMAKE_BUILD_TYPE must either be Debug or Release instead of ${CMAKE_BUILD_TYPE}")
14+
endif ()
15+
endif ()
16+
17+
# - Debug & Release
18+
IF (CMAKE_BUILD_TYPE STREQUAL Debug)
19+
add_definitions(-DDEBUG=1)
20+
ENDIF ()
21+
22+
# definitions in macros
23+
add_definitions(-DCONFIG_LOG_LEVEL=LOG_VERBOSE -DCONFIG_LOG_ENABLE -DCONFIG_LOG_COLORS -DLOG_KERNEL -D__riscv64 -DLV_CONF_INCLUDE_SIMPLE)
24+
25+
if (NOT SDK_ROOT)
26+
get_filename_component(_SDK_ROOT ${CMAKE_CURRENT_LIST_DIR} DIRECTORY)
27+
global_set(SDK_ROOT ${_SDK_ROOT})
28+
endif ()
29+
30+
include(${CMAKE_CURRENT_LIST_DIR}/toolchain.cmake)
31+
32+
include(${CMAKE_CURRENT_LIST_DIR}/compile-flags.cmake)
33+
34+
include(${CMAKE_CURRENT_LIST_DIR}/fix-9985.cmake)

components/cmake/compile-flags.cmake

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
add_compile_flags(LD
2+
-nostartfiles
3+
-static
4+
-Wl,--gc-sections
5+
-Wl,-static
6+
-Wl,--start-group
7+
-Wl,--whole-archive
8+
-Wl,--no-whole-archive
9+
-Wl,--end-group
10+
-Wl,-EL
11+
-Wl,--no-relax
12+
-T ../lds/kendryte.ld
13+
)
14+
15+
# C Flags Settings
16+
add_compile_flags(BOTH
17+
-mcmodel=medany
18+
-mabi=lp64f
19+
-march=rv64imafc
20+
-fno-common
21+
-ffunction-sections
22+
-fdata-sections
23+
-fstrict-volatile-bitfields
24+
-fno-zero-initialized-in-bss
25+
-ffast-math
26+
-fno-math-errno
27+
-fsingle-precision-constant
28+
-Os
29+
)
30+
31+
add_compile_flags(C -std=gnu11 -Wno-pointer-to-int-cast)
32+
add_compile_flags(CXX -std=gnu++17)
33+
34+
if (BUILDING_SDK)
35+
add_compile_flags(BOTH
36+
-Wall
37+
-Werror=all
38+
-Wno-error=unused-function
39+
-Wno-error=unused-but-set-variable
40+
-Wno-error=unused-variable
41+
-Wno-error=deprecated-declarations
42+
-Wextra
43+
-Werror=frame-larger-than=32768
44+
-Wno-unused-parameter
45+
-Wno-sign-compare
46+
-Wno-error=missing-braces
47+
-Wno-error=return-type
48+
-Wno-error=pointer-sign
49+
-Wno-missing-braces
50+
-Wno-strict-aliasing
51+
-Wno-implicit-fallthrough
52+
-Wno-missing-field-initializers
53+
-Wno-int-to-pointer-cast
54+
-Wno-error=comment
55+
-Wno-error=logical-not-parentheses
56+
-Wno-error=duplicate-decl-specifier
57+
-Wno-error=parentheses
58+
)
59+
60+
add_compile_flags(C -Wno-old-style-declaration)
61+
else ()
62+
add_compile_flags(BOTH -L${SDK_ROOT}/include/)
63+
endif ()
64+

components/cmake/dump-config.cmake

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
message("")
2+
message("Project: ${PROJECT_NAME}")
3+
message(" LIST_FILE=${CMAKE_PARENT_LIST_FILE}")
4+
message(" TOOLCHAIN=${TOOLCHAIN}")
5+
message(" KENDRYTE_IDE=${KENDRYTE_IDE}")
6+
message(" BUILDING_SDK=${BUILDING_SDK}")
7+
message("")
8+
message(" CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
9+
message(" CMAKE_C_COMPILER=${CMAKE_C_COMPILER}")
10+
message(" CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
11+
message(" CMAKE_LINKER=${CMAKE_LINKER}")
12+
message(" CMAKE_OBJCOPY=${CMAKE_OBJCOPY}")
13+
message(" CMAKE_OBJDUMP=${CMAKE_OBJDUMP}")
14+
message(" CMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}")
15+
message("")
16+
message(" CMAKE_C_FLAGS=${CMAKE_C_FLAGS}")
17+
message(" CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}")
18+
message(" LDFLAGS=${LDFLAGS}")
19+
message(" CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}")
20+
message("Makefile created.")
21+
message("")
22+
message("")

components/cmake/executable.cmake

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
if (NOT BUILDING_SDK)
2+
if(EXISTS ${SDK_ROOT}/libkendryte.a)
3+
add_library(kendryte STATIC IMPORTED)
4+
set_property(TARGET kendryte PROPERTY IMPORTED_LOCATION ${SDK_ROOT}/libkendryte.a)
5+
include_directories(${SDK_ROOT}/include/)
6+
else()
7+
header_directories(${SDK_ROOT}/lib)
8+
add_subdirectory(${SDK_ROOT}/lib)
9+
endif()
10+
endif ()
11+
12+
removeDuplicateSubstring(${CMAKE_C_FLAGS} CMAKE_C_FLAGS)
13+
removeDuplicateSubstring(${CMAKE_CXX_FLAGS} CMAKE_CXX_FLAGS)
14+
15+
message("SOURCE_FILES=${SOURCE_FILES}")
16+
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
17+
18+
19+
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE C)
20+
21+
target_link_libraries(${PROJECT_NAME}
22+
-Wl,--start-group
23+
gcc m c
24+
-Wl,--whole-archive
25+
kendryte
26+
-Wl,--no-whole-archive
27+
-Wl,--end-group
28+
)
29+
30+
if (EXISTS ${SDK_ROOT}/src/${PROJ}/project.cmake)
31+
include(${SDK_ROOT}/src/${PROJ}/project.cmake)
32+
endif ()
33+
34+
IF(SUFFIX)
35+
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SUFFIX ${SUFFIX})
36+
ENDIF()
37+
38+
# Build target
39+
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
40+
COMMAND ${CMAKE_OBJCOPY} --output-format=binary ${CMAKE_BINARY_DIR}/${PROJECT_NAME}${SUFFIX} ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.bin
41+
DEPENDS ${PROJECT_NAME}
42+
COMMENT "Generating .bin file ...")
43+
44+
# show information
45+
include(${CMAKE_CURRENT_LIST_DIR}/dump-config.cmake)

components/cmake/fix-9985.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### http://www.cmake.org/Bug/view.php?id=9985
2+
string(REPLACE "-rdynamic" "" CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS}")
3+
string(REPLACE "-rdynamic" "" CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS}")

0 commit comments

Comments
 (0)