-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from Embedded-System-Lovers/add-cmake-support
Fixes #3 via add cmake support
- Loading branch information
Showing
6 changed files
with
202 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
# | ||
# Root CMakeLists.txt | ||
# | ||
cmake_minimum_required (VERSION 3.15) | ||
project(BareMetal_WCH_V307_RISC-V ASM C CXX) | ||
|
||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
set(CMAKE_C_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD 20) | ||
|
||
set(DEPLOY_DIR "${CMAKE_CURRENT_BINARY_DIR}") | ||
set(EXECUTABLE_NAME "${CMAKE_PROJECT_NAME}") | ||
set(EXECUTABLE_FORMAT elf) | ||
set(EXECUTABLE "${EXECUTABLE_NAME}.${EXECUTABLE_FORMAT}") | ||
set(SRC_DIR "${CMAKE_SOURCE_DIR}/Code") | ||
set(LD_SCRIPT "${SRC_DIR}/Memory_Map.ld") | ||
set(MAP_FILE "${DEPLOY_DIR}/${EXECUTABLE_NAME}.map") | ||
|
||
# Set default build type if not defined | ||
if(NOT CMAKE_BUILD_TYPE) | ||
set(CMAKE_BUILD_TYPE Release) | ||
endif() | ||
|
||
# Listed flags | ||
# Architecture | ||
set(ARCH_FLAGS_LIST | ||
-march=rv32imafc | ||
-mabi=ilp32f | ||
-msmall-data-limit=0 | ||
-falign-functions=4 | ||
) | ||
|
||
# Optimization | ||
set(OPT_RELEASE_FLAGS_LIST | ||
-O2 | ||
-fno-reorder-blocks-and-partition | ||
-fno-reorder-functions | ||
) | ||
|
||
set(OPT_DEBUG_FLAGS_LIST | ||
-O0 | ||
) | ||
|
||
if(CMAKE_BUILD_TYPE MATCHES Release) | ||
set(OPT_FLAGS_LIST ${OPT_RELEASE_FLAGS_LIST}) | ||
else() | ||
set(OPT_FLAGS_LIST ${OPT_DEBUG_FLAGS_LIST}) | ||
endif() | ||
|
||
# C flags | ||
set(C_FLAGS_LIST | ||
${OPT_FLAG_LIST} | ||
${ARCH_FLAGS_LIST} | ||
-ffast-math | ||
-g3 | ||
-Wconversion | ||
-Wsign-conversion | ||
-Wunused-parameter | ||
-Wuninitialized | ||
-Wmissing-declarations | ||
-Wshadow | ||
-Wunreachable-code | ||
-Wmissing-include-dirs | ||
-Wall | ||
-Wextra | ||
-fomit-frame-pointer | ||
-gdwarf-2 | ||
-fomit-frame-pointer | ||
-fsingle-precision-constant | ||
) | ||
|
||
# C++ flags | ||
set(CXX_FLAGS_LIST | ||
${C_FLAGS_LIST} | ||
-fno-exceptions | ||
-fno-rtti | ||
-fno-use-cxa-atexit | ||
-fno-nonansi-builtins | ||
-fno-threadsafe-statics | ||
-fno-enforce-eh-specs | ||
-ftemplate-depth=128 | ||
-Wzero-as-null-pointer-constant | ||
) | ||
|
||
# Assembler flags | ||
set(ASM_FLAGS_LIST | ||
-march=rv32imafc | ||
-alh | ||
) | ||
|
||
# LD flags | ||
set(LD_FLAGS_LIST | ||
-nostartfiles | ||
-nostdlib | ||
-Wl,-T ${LD_SCRIPT} | ||
-Wl,--print-memory-usage | ||
-Wl,--print-map | ||
-Wl,-Map="${MAP_FILE}" | ||
) | ||
|
||
# Concatenate listed flags so that they can be parsed when assigned to CMAKE_<X>_FLAGS symbols | ||
string(REPLACE ";" " " C_FLAGS "${C_FLAGS_LIST}") | ||
string(REPLACE ";" " " CXX_FLAGS "${CXX_FLAGS_LIST}") | ||
string(REPLACE ";" " " ASM_FLAGS "${ASM_FLAGS_LIST}") | ||
string(REPLACE ";" " " LD_FLAGS "${LD_FLAGS_LIST}") | ||
|
||
# Bind toolchain defintions | ||
set(CMAKE_ASM_COMPILER ${CPP}) | ||
set(CMAKE_C_COMPILER ${CC}) | ||
set(CMAKE_CXX_COMPILER ${CPP}) | ||
set(CMAKE_ASM_FLAGS "${CXX_FLAGS}") | ||
set(CMAKE_C_FLAGS "${C_FLAGS}") | ||
set(CMAKE_CXX_FLAGS "${CXX_FLAGS}") | ||
set(CMAKE_EXE_LINKER_FLAGS "${LD_FLAGS}") | ||
set(CMAKE_VERBOSE_MAKEFILE OFF) # Set it to ON to have verbose build output | ||
|
||
# Construct executable | ||
add_executable(${EXECUTABLE} | ||
${SRC_DIR}/Mcal/Mcu.c | ||
${SRC_DIR}/Mcal/Port.c | ||
${SRC_DIR}/Mcal/SysTick.c | ||
${SRC_DIR}/Startup/boot.s | ||
${SRC_DIR}/Startup/intvect.c | ||
${SRC_DIR}/Startup/Startup.c | ||
${SRC_DIR}/Appli/main.c | ||
) | ||
|
||
target_include_directories(${EXECUTABLE} | ||
PRIVATE | ||
${SRC_DIR} | ||
${SRC_DIR}/Mcal | ||
) | ||
|
||
target_link_libraries(${EXECUTABLE} | ||
PRIVATE | ||
) | ||
|
||
target_link_directories(${EXECUTABLE} | ||
PRIVATE | ||
) | ||
|
||
target_link_options(${EXECUTABLE} | ||
PRIVATE | ||
) | ||
|
||
# Post build commands | ||
add_custom_command(TARGET ${EXECUTABLE} POST_BUILD COMMAND ${OBJCOPY} -Oihex ${DEPLOY_DIR}/${EXECUTABLE} ${DEPLOY_DIR}/${EXECUTABLE_NAME}.hex) | ||
add_custom_command(TARGET ${EXECUTABLE} POST_BUILD COMMAND ${OBJCOPY} -Obinary ${DEPLOY_DIR}/${EXECUTABLE} ${DEPLOY_DIR}/${EXECUTABLE_NAME}.bin) | ||
add_custom_command(TARGET ${EXECUTABLE} POST_BUILD COMMAND ${OBJDUMP} -d ${DEPLOY_DIR}/${EXECUTABLE} > ${DEPLOY_DIR}/${EXECUTABLE_NAME}.disa) | ||
add_custom_command(TARGET ${EXECUTABLE} POST_BUILD COMMAND ${SIZE} --format=berkeley ${DEPLOY_DIR}/${EXECUTABLE}) | ||
|
||
# Print build info | ||
message("=====================================") | ||
message("Project: ${CMAKE_PROJECT_NAME}") | ||
message("Build type: ${CMAKE_BUILD_TYPE}") | ||
message("=====================================") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
set(CMAKE_SYSTEM_NAME Generic) | ||
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) | ||
|
||
set(TOOLCHAIN riscv32-unknown-elf) | ||
set(AR ${TOOLCHAIN}-ar) | ||
set(AS ${TOOLCHAIN}-as) | ||
set(CC ${TOOLCHAIN}-gcc) | ||
set(CPP ${TOOLCHAIN}-g++) | ||
set(LD ${TOOLCHAIN}-ld) | ||
set(GDB ${TOOLCHAIN}-gdb) | ||
set(OBJCOPY ${TOOLCHAIN}-objcopy) | ||
set(OBJDUMP ${TOOLCHAIN}-objdump) | ||
set(SIZE ${TOOLCHAIN}-size) | ||
set(READELF ${TOOLCHAIN}-readelf) |