Skip to content

[sw] Apply common CMake conventions #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ to a verilator simulation model to be simulated on a PC.
```
mkdir sw/build
pushd sw/build
cmake ../
cmake ..
make
popd
```
Expand Down
27 changes: 12 additions & 15 deletions sw/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
cmake_minimum_required(VERSION 3.10)
project(demo_system_sw)
cmake_minimum_required(VERSION 3.12)

if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/gcc_toolchain.cmake")
endif()

project(demo_system_sw LANGUAGES C ASM)

if(CMAKE_BUILD_TYPE STREQUAL "")
get_property(helpstring CACHE CMAKE_BUILD_TYPE PROPERTY HELPSTRING)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "${helpstring}" FORCE)
endif()

option(SIM_CTRL_OUTPUT
"Send string output to simulator control rather than UART")
Expand All @@ -8,19 +18,6 @@ if(SIM_CTRL_OUTPUT)
add_compile_definitions(SIM_CTRL_OUTPUT)
endif()

set(COMMON_DIR "${CMAKE_CURRENT_LIST_DIR}/common")
set(LINKER_SCRIPT "${COMMON_DIR}/link.ld")
set(CMAKE_C_COMPILER riscv32-unknown-elf-gcc)
set(CMAKE_EXE_LINKER_FLAGS "-nostartfiles -T${LINKER_SCRIPT}")
set(CMAKE_C_FLAGS "-march=rv32imc -mabi=ilp32 -static -mcmodel=medany -Wall -g \
-fvisibility=hidden -ffreestanding")

add_subdirectory(common)

function(add_prog prog_name srcs)
add_executable(${prog_name} ${srcs} $<TARGET_OBJECTS:common>)
target_include_directories(${prog_name} PRIVATE $<TARGET_PROPERTY:common,INCLUDE_DIRECTORIES>)
endfunction()

add_subdirectory(demo)
add_subdirectory(blank)
3 changes: 1 addition & 2 deletions sw/blank/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
add_executable(blank blank.S)
set_property(SOURCE blank.S PROPERTY LANGUAGE C)

add_custom_command(
TARGET blank POST_BUILD
COMMAND riscv32-unknown-elf-objcopy -O binary "$<TARGET_FILE:blank>" "$<TARGET_FILE:blank>.bin"
COMMAND ${CMAKE_OBJCOPY} -O binary "$<TARGET_FILE:blank>" "$<TARGET_FILE:blank>.bin"
COMMAND srec_cat "$<TARGET_FILE:blank>.bin" -binary -offset 0x0000 -byte-swap 4 -o "$<TARGET_FILE:blank>.vmem" -vmem
VERBATIM)
3 changes: 1 addition & 2 deletions sw/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
add_library(common OBJECT demo_system.c uart.c timer.c gpio.c pwm.c spi.c crt0.S)
set_property(SOURCE crt0.S PROPERTY LANGUAGE C)
target_include_directories(common PUBLIC "${CMAKE_CURRENT_LIST_DIR}")
target_include_directories(common INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}")
4 changes: 2 additions & 2 deletions sw/demo/basic-passwdcheck/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../vendor/newae/simpleseri
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../common)


add_prog(basic-passwdcheck ${CMAKE_CURRENT_SOURCE_DIR}/../../../vendor/newae/basic-passwdcheck/basic-passwdcheck.c)
add_executable(basic-passwdcheck ${CMAKE_CURRENT_SOURCE_DIR}/../../../vendor/newae/basic-passwdcheck/basic-passwdcheck.c)

target_link_libraries(basic-passwdcheck simpleserial)
target_link_libraries(basic-passwdcheck common simpleserial)

3 changes: 2 additions & 1 deletion sw/demo/hello_world/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_prog(demo main.c)
add_executable(demo main.c)
target_link_libraries(demo common)
6 changes: 2 additions & 4 deletions sw/demo/lcd_st7735/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ ${CMAKE_CURRENT_SOURCE_DIR}/../../../vendor/display_drivers/core/lucida_console_
${CMAKE_CURRENT_SOURCE_DIR}/../../../vendor/display_drivers/st7735/lcd_st7735.c
)

string(APPEND CMAKE_C_FLAGS " -O2")

# add_executable(lcd_st7735 main.c)
add_prog(lcd_st7735 "main.c;lcd.c;fractal_fixed.c;fractal_float.c;fractal_palette.c")
add_executable(lcd_st7735 main.c lcd.c fractal_fixed.c fractal_float.c fractal_palette.c)

# pull in core dependencies and additional i2c hardware support
target_link_libraries(lcd_st7735 lcd_st7735_lib)
target_link_libraries(lcd_st7735 common lcd_st7735_lib)

target_include_directories(lcd_st7735 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../../vendor/display_drivers)
4 changes: 2 additions & 2 deletions sw/demo/simpleserial-aes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ${CMAKE_CURRENT_SOURCE_DIR}/../../../vendor/newae/crypto/aes-independant.c
${CMAKE_CURRENT_SOURCE_DIR}/../../../vendor/newae/crypto/tiny-AES128-C/aes.c
)

add_prog(simpleserial-aes ${CMAKE_CURRENT_SOURCE_DIR}/../../../vendor/newae/simpleserial-aes/simpleserial-aes.c)
add_executable(simpleserial-aes ${CMAKE_CURRENT_SOURCE_DIR}/../../../vendor/newae/simpleserial-aes/simpleserial-aes.c)

target_link_libraries(simpleserial-aes simpleserial tiny-AES128)
target_link_libraries(simpleserial-aes common simpleserial tiny-AES128)

7 changes: 7 additions & 0 deletions sw/gcc_toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(LINKER_SCRIPT "${CMAKE_CURRENT_LIST_DIR}/common/link.ld")
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_C_COMPILER riscv32-unknown-elf-gcc)
set(CMAKE_C_FLAGS_INIT
"-march=rv32imc -mabi=ilp32 -mcmodel=medany -Wall -fvisibility=hidden -ffreestanding")
set(CMAKE_ASM_FLAGS_INIT "-march=rv32imc")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-nostartfiles -T \"${LINKER_SCRIPT}\"")