Skip to content
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
18 changes: 9 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ jobs:
- name: Add startup file (if it exists)
if: steps.check_files.outputs.files_exists == 'true'
run: |
sed -i '6 s/# //' ${{github.workspace}}/project/CMakeLists.txt
sed -i '/KLIB_DIR.*startup.cpp/ s/# //' ${{github.workspace}}/project/CMakeLists.txt

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: CC=arm-none-eabi-gcc CXX=arm-none-eabi-g++ cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DTARGET_CPU=${{matrix.cpu}} -Wno-dev
run: CC=arm-none-eabi-gcc CXX=arm-none-eabi-g++ cmake -S ${{github.workspace}}/project -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DTARGET_CPU=${{matrix.cpu}} -Wno-dev

- name: Build
# Build your program with the given configuration
Expand All @@ -88,12 +88,12 @@ jobs:
with:
name: ${{matrix.cpu}}
path: |
${{github.workspace}}/build/project/klib.elf
${{github.workspace}}/build/project/klib.map
${{github.workspace}}/build/project/klib.lss
${{github.workspace}}/build/project/klib.memory
${{github.workspace}}/build/project/klib.hex
${{github.workspace}}/build/project/klib.bin
${{github.workspace}}/build/klib.elf
${{github.workspace}}/build/klib.map
${{github.workspace}}/build/klib.lss
${{github.workspace}}/build/klib.memory
${{github.workspace}}/build/klib.hex
${{github.workspace}}/build/klib.bin
${{github.workspace}}/targets/chip/${{matrix.cpu}}/${{matrix.cpu}}.h

individual-header-build:
Expand Down Expand Up @@ -154,6 +154,6 @@ jobs:
echo "Building for header: $header_file"

# Configure and build
CC=arm-none-eabi-gcc CXX=arm-none-eabi-g++ cmake -B "$BUILD_DIR/$safe_name" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DTARGET_CPU=lpc1756 -Wno-dev
CC=arm-none-eabi-gcc CXX=arm-none-eabi-g++ cmake -S ${{github.workspace}}/project -B "$BUILD_DIR/$safe_name" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DTARGET_CPU=lpc1756 -Wno-dev
cmake --build "$BUILD_DIR/$safe_name" --config ${{env.BUILD_TYPE}}
done
24 changes: 6 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
# set minimum version of CMake.
cmake_minimum_required(VERSION 3.22)

# enable the folder property for the whole project
set_property(GLOBAL PROPERTY USE_FOLDERS TRUE)

# The Generic system name is used for embedded targets (targets without OS) in
# CMake
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR ARM)

# Supress Error when trying to test the compiler
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(BUILD_SHARED_LIBS OFF)

# set project name and version
project(klib VERSION 0.0.1)
# provide the klib directory for the project
set(KLIB_DIR ${CMAKE_CURRENT_LIST_DIR})

# enable assembly
enable_language(ASM)
Expand Down Expand Up @@ -48,7 +36,7 @@ if (DEFINED TARGET_CPU)
message("Building for target: ${TARGET_CPU}")

# add the target directory
add_subdirectory(${CMAKE_SOURCE_DIR}/targets/chip/${TARGET_CPU})
include(${KLIB_DIR}/targets/chip/${TARGET_CPU}/CMakeLists.txt)

# check if the user configured the fpu
if (DEFINED TARGET_FPU_ENABLED)
Expand All @@ -74,7 +62,7 @@ else()
endif()

# add the klib library
add_subdirectory(${CMAKE_SOURCE_DIR}/klib)
include(${KLIB_DIR}/klib/CMakeLists.txt)

# add the project sources
add_subdirectory(${CMAKE_SOURCE_DIR}/project)
# include the linkerscript generator needed to preprocess the linkerscripts
include(${KLIB_DIR}/targets/arm/linkerscript/linkerscript.cmake)
40 changes: 20 additions & 20 deletions klib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
# set the sources
set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/entry/entry.c
${CMAKE_CURRENT_SOURCE_DIR}/entry/secondary.cpp
set(SOURCES
${CMAKE_CURRENT_LIST_DIR}/entry/entry.c
${CMAKE_CURRENT_LIST_DIR}/entry/secondary.cpp
)

set(HEADERS_PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/comm/streams/stream_base.hpp
${CMAKE_CURRENT_SOURCE_DIR}/comm/streams/combined_stream.hpp
${CMAKE_CURRENT_SOURCE_DIR}/comm/streams/istream.hpp
${CMAKE_CURRENT_SOURCE_DIR}/comm/streams/ostream.hpp
${CMAKE_CURRENT_LIST_DIR}/comm/streams/stream_base.hpp
${CMAKE_CURRENT_LIST_DIR}/comm/streams/combined_stream.hpp
${CMAKE_CURRENT_LIST_DIR}/comm/streams/istream.hpp
${CMAKE_CURRENT_LIST_DIR}/comm/streams/ostream.hpp
)

set(HEADERS_PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/irq.hpp
${CMAKE_CURRENT_SOURCE_DIR}/klib.hpp
${CMAKE_CURRENT_SOURCE_DIR}/stream.hpp
${CMAKE_CURRENT_LIST_DIR}/irq.hpp
${CMAKE_CURRENT_LIST_DIR}/klib.hpp
${CMAKE_CURRENT_LIST_DIR}/stream.hpp
)

# check if we need to add the segger rtt library
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/comm/segger/src/)
if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/comm/segger/src/)
message("Segger RTT support enabled")

# append the header implementation to the public headers
set(HEADERS_PUBLIC ${HEADERS_PUBLIC} ${CMAKE_CURRENT_SOURCE_DIR}/comm/segger/rtt.hpp)
set(HEADERS_PRIVATE ${HEADERS_PUBLIC} ${CMAKE_CURRENT_SOURCE_DIR}/comm/streams/rtt_stream.hpp)
set(HEADERS_PUBLIC ${HEADERS_PUBLIC} ${CMAKE_CURRENT_LIST_DIR}/comm/segger/rtt.hpp)
set(HEADERS_PRIVATE ${HEADERS_PUBLIC} ${CMAKE_CURRENT_LIST_DIR}/comm/streams/rtt_stream.hpp)

# add the segger library source files
set(SOURCES ${SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/comm/segger/src/RTT/SEGGER_RTT.c)
set(SOURCES ${SOURCES} ${CMAKE_CURRENT_LIST_DIR}/comm/segger/src/RTT/SEGGER_RTT.c)

# check if we need to include the systemview sources
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/comm/segger/src/SYSVIEW/)
if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/comm/segger/src/SYSVIEW/)
# append the systemview sources
set(SOURCES ${SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/comm/segger/src/SYSVIEW/SEGGER_SYSVIEW.c)
set(SOURCES ${SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/comm/segger/src/SYSVIEW/SEGGER_SYSVIEW_Config_NoOS.c)
set(SOURCES ${SOURCES} ${CMAKE_CURRENT_LIST_DIR}/comm/segger/src/SYSVIEW/SEGGER_SYSVIEW.c)
set(SOURCES ${SOURCES} ${CMAKE_CURRENT_LIST_DIR}/comm/segger/src/SYSVIEW/SEGGER_SYSVIEW_Config_NoOS.c)
endif()
else()
message("Segger RTT support disabled")
Expand Down Expand Up @@ -99,7 +99,7 @@ endif()

# enabled segger support in the defines to prevent a
# include of the segger files
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/comm/segger/src/)
if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/comm/segger/src/)
target_compile_definitions(klib PUBLIC "KLIB_SEGGER_SUPPORT=1")
else()
target_compile_definitions(klib PUBLIC "KLIB_SEGGER_SUPPORT=0")
Expand All @@ -111,7 +111,7 @@ endif()
# - header location in project: ${CMAKE_CURRENT_BINARY_DIR}/generated_headers
target_include_directories(
klib PUBLIC
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/../>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/../>"
"$<BUILD_INTERFACE:${GENERATED_HEADERS_DIR}>"
)
31 changes: 28 additions & 3 deletions project/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
# include the linkerscript generator needed to preprocess the linkerscripts
include (${CMAKE_SOURCE_DIR}/targets/arm/linkerscript/linkerscript.cmake)
# The Generic system name is used for embedded targets (targets without OS) in
# CMake
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR ARM)

# Supress Error when trying to test the compiler
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(BUILD_SHARED_LIBS OFF)

# set minimum version of CMake.
cmake_minimum_required(VERSION 3.22)

# set project name and version
project(klib VERSION 0.0.1)

# provide the klib directory for the project (repo root, one level up)
set(KLIB_DIR ${CMAKE_CURRENT_LIST_DIR}/..)

# include klib and all common toolchain + target setup from the klib repo root.
# This configures the build-type flags, includes the target cpu (creating the
# target_cpu / target_cpu_options targets), defines the add_linkerscript()
# helper and builds the klib library target.
# Note: KLIB_DIR needs to point to your klib installation folder.
include(${KLIB_DIR}/CMakeLists.txt)

# set the sources
set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp

# example for including the startup.cpp
# ${CMAKE_SOURCE_DIR}/targets/chip/${TARGET_CPU}/startup.cpp
# ${KLIB_DIR}/targets/chip/${TARGET_CPU}/startup.cpp
)

set(HEADERS)
Expand Down Expand Up @@ -42,6 +64,9 @@ target_link_libraries(klib_project PUBLIC target_cpu)
# Libraries to link for all targets
target_link_libraries(klib_project PUBLIC m)

# get the linkerscript we should link against
get_property(TARGET_LINKERSCRIPT GLOBAL PROPERTY TARGET_LINKERSCRIPT)

# link to the linkerscript of the target cpu
add_linkerscript(klib_project ${TARGET_LINKERSCRIPT} "")

Expand Down
2 changes: 1 addition & 1 deletion targets/arm/linkerscript/linkerscript.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# macroes, conditionals, etc)
function(add_linkerscript target linkerscript options)
set(output "${CMAKE_BINARY_DIR}/linkerscript.ld")
set(CURRENT_DIR "${CMAKE_SOURCE_DIR}/targets/arm/linkerscript")
set(CURRENT_DIR "${KLIB_DIR}/targets/arm/linkerscript")

# run the preprocessor on the linkerscript
add_custom_command(
Expand Down
13 changes: 6 additions & 7 deletions targets/chip/atsam3x8e/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# export our linkerscript
set(TARGET_LINKERSCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/linkerscript.ld" PARENT_SCOPE)
set_property(GLOBAL PROPERTY TARGET_LINKERSCRIPT "${CMAKE_CURRENT_LIST_DIR}/linkerscript.ld")

# set the atsam3x8e cpu options as a seperate target so the driver layer can link agains klib
add_library(target_cpu_options INTERFACE)
Expand All @@ -9,7 +9,7 @@ set_target_properties(target_cpu_options PROPERTIES FOLDER "klib")
add_library(${PROJECT_NAME}::target_cpu_options ALIAS target_cpu_options)

# include the arm directory for all the cmsis files
target_include_directories(target_cpu_options INTERFACE ${CMAKE_SOURCE_DIR}/targets/arm/)
target_include_directories(target_cpu_options INTERFACE ${CMAKE_CURRENT_LIST_DIR}/../../arm/)

if (DEFINED TARGET_FPU_ENABLED)
message(FATAL_ERROR "Target does not have a FPU")
Expand Down Expand Up @@ -37,7 +37,7 @@ target_compile_options(target_cpu_options INTERFACE "-fno-asynchronous-unwind-ta

# cpu atsam3x8e target drivers
set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/../../arm/vector_table/cortex-m3.cpp
${CMAKE_CURRENT_LIST_DIR}/../../arm/vector_table/cortex-m3.cpp
)

set(HEADERS_PRIVATE
Expand All @@ -63,8 +63,8 @@ add_library(${PROJECT_NAME}::target_cpu ALIAS target_cpu)
target_compile_features(target_cpu PUBLIC cxx_std_20)

# set the target_cpu for klib
get_filename_component(TARGET_CPU_FOLDER ${CMAKE_CURRENT_SOURCE_DIR} NAME)
set(TARGET_CPU ${TARGET_CPU_FOLDER} PARENT_SCOPE)
get_filename_component(TARGET_CPU_FOLDER ${CMAKE_CURRENT_LIST_DIR} NAME)
set_property(GLOBAL PROPERTY TARGET_CPU ${TARGET_CPU_FOLDER})
target_compile_definitions(target_cpu PUBLIC "TARGET_CPU=${TARGET_CPU}")

# add target specific compile options
Expand All @@ -80,7 +80,6 @@ target_link_libraries(target_cpu PUBLIC klib)
# - header location in project: ${CMAKE_CURRENT_BINARY_DIR}/generated_headers
target_include_directories(
target_cpu PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>"
"$<BUILD_INTERFACE:${GENERATED_HEADERS_DIR}>"
)
13 changes: 6 additions & 7 deletions targets/chip/atsam4s2b/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# export our linkerscript
set(TARGET_LINKERSCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/linkerscript.ld" PARENT_SCOPE)
set_property(GLOBAL PROPERTY TARGET_LINKERSCRIPT "${CMAKE_CURRENT_LIST_DIR}/linkerscript.ld")

# set the atsam4s2b cpu options as a seperate target so the driver layer can link agains klib
add_library(target_cpu_options INTERFACE)
Expand All @@ -9,7 +9,7 @@ set_target_properties(target_cpu_options PROPERTIES FOLDER "klib")
add_library(${PROJECT_NAME}::target_cpu_options ALIAS target_cpu_options)

# include the arm directory for all the cmsis files
target_include_directories(target_cpu_options INTERFACE ${CMAKE_SOURCE_DIR}/targets/arm/)
target_include_directories(target_cpu_options INTERFACE ${CMAKE_CURRENT_LIST_DIR}/../../arm/)

# set the cpu options for the compiler
target_compile_options(target_cpu_options INTERFACE "-march=armv7e-m")
Expand All @@ -33,7 +33,7 @@ target_compile_options(target_cpu_options INTERFACE "-fno-asynchronous-unwind-ta

# cpu atsam4s2b target drivers
set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/../../arm/vector_table/cortex-m4.cpp
${CMAKE_CURRENT_LIST_DIR}/../../arm/vector_table/cortex-m4.cpp
)

set(HEADERS_PRIVATE
Expand All @@ -59,8 +59,8 @@ add_library(${PROJECT_NAME}::target_cpu ALIAS target_cpu)
target_compile_features(target_cpu PUBLIC cxx_std_20)

# set the target_cpu for klib
get_filename_component(TARGET_CPU_FOLDER ${CMAKE_CURRENT_SOURCE_DIR} NAME)
set(TARGET_CPU ${TARGET_CPU_FOLDER} PARENT_SCOPE)
get_filename_component(TARGET_CPU_FOLDER ${CMAKE_CURRENT_LIST_DIR} NAME)
set_property(GLOBAL PROPERTY TARGET_CPU ${TARGET_CPU_FOLDER})
target_compile_definitions(target_cpu PUBLIC "TARGET_CPU=${TARGET_CPU}")

# add target specific compile options
Expand All @@ -76,7 +76,6 @@ target_link_libraries(target_cpu PUBLIC klib)
# - header location in project: ${CMAKE_CURRENT_BINARY_DIR}/generated_headers
target_include_directories(
target_cpu PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>"
"$<BUILD_INTERFACE:${GENERATED_HEADERS_DIR}>"
)
13 changes: 6 additions & 7 deletions targets/chip/lpc1752/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# export our linkerscript
set(TARGET_LINKERSCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/linkerscript.ld" PARENT_SCOPE)
set_property(GLOBAL PROPERTY TARGET_LINKERSCRIPT "${CMAKE_CURRENT_LIST_DIR}/linkerscript.ld")

# set the lpc1752 cpu options as a seperate target so the driver layer can link agains klib
add_library(target_cpu_options INTERFACE)
Expand All @@ -9,7 +9,7 @@ set_target_properties(target_cpu_options PROPERTIES FOLDER "klib")
add_library(${PROJECT_NAME}::target_cpu_options ALIAS target_cpu_options)

# include the arm directory for all the cmsis files
target_include_directories(target_cpu_options INTERFACE ${CMAKE_SOURCE_DIR}/targets/arm/)
target_include_directories(target_cpu_options INTERFACE ${CMAKE_CURRENT_LIST_DIR}/../../arm/)

# set the cpu options for the compiler
target_compile_options(target_cpu_options INTERFACE "-march=armv7-m")
Expand All @@ -33,7 +33,7 @@ target_compile_options(target_cpu_options INTERFACE "-fno-asynchronous-unwind-ta

# cpu lpc1752 target drivers
set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/../../arm/vector_table/cortex-m3.cpp
${CMAKE_CURRENT_LIST_DIR}/../../arm/vector_table/cortex-m3.cpp
)

set(HEADERS_PRIVATE
Expand All @@ -59,8 +59,8 @@ add_library(${PROJECT_NAME}::target_cpu ALIAS target_cpu)
target_compile_features(target_cpu PUBLIC cxx_std_20)

# set the target_cpu for klib
get_filename_component(TARGET_CPU_FOLDER ${CMAKE_CURRENT_SOURCE_DIR} NAME)
set(TARGET_CPU ${TARGET_CPU_FOLDER} PARENT_SCOPE)
get_filename_component(TARGET_CPU_FOLDER ${CMAKE_CURRENT_LIST_DIR} NAME)
set_property(GLOBAL PROPERTY TARGET_CPU ${TARGET_CPU_FOLDER})
target_compile_definitions(target_cpu PUBLIC "TARGET_CPU=${TARGET_CPU}")

# add target specific compile options
Expand All @@ -76,7 +76,6 @@ target_link_libraries(target_cpu PUBLIC klib)
# - header location in project: ${CMAKE_CURRENT_BINARY_DIR}/generated_headers
target_include_directories(
target_cpu PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>"
"$<BUILD_INTERFACE:${GENERATED_HEADERS_DIR}>"
)
Loading
Loading