Skip to content

Commit ed5e793

Browse files
Merge pull request #17 from itzandroidtab/working_dir
changed projects so now they are the one you build in
2 parents c0f1ca1 + 2b1ceda commit ed5e793

25 files changed

Lines changed: 174 additions & 179 deletions

File tree

.github/workflows/build.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ jobs:
7171
- name: Add startup file (if it exists)
7272
if: steps.check_files.outputs.files_exists == 'true'
7373
run: |
74-
sed -i '6 s/# //' ${{github.workspace}}/project/CMakeLists.txt
74+
sed -i '/KLIB_DIR.*startup.cpp/ s/# //' ${{github.workspace}}/project/CMakeLists.txt
7575
7676
- name: Configure CMake
7777
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
7878
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
79-
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
79+
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
8080

8181
- name: Build
8282
# Build your program with the given configuration
@@ -88,12 +88,12 @@ jobs:
8888
with:
8989
name: ${{matrix.cpu}}
9090
path: |
91-
${{github.workspace}}/build/project/klib.elf
92-
${{github.workspace}}/build/project/klib.map
93-
${{github.workspace}}/build/project/klib.lss
94-
${{github.workspace}}/build/project/klib.memory
95-
${{github.workspace}}/build/project/klib.hex
96-
${{github.workspace}}/build/project/klib.bin
91+
${{github.workspace}}/build/klib.elf
92+
${{github.workspace}}/build/klib.map
93+
${{github.workspace}}/build/klib.lss
94+
${{github.workspace}}/build/klib.memory
95+
${{github.workspace}}/build/klib.hex
96+
${{github.workspace}}/build/klib.bin
9797
${{github.workspace}}/targets/chip/${{matrix.cpu}}/${{matrix.cpu}}.h
9898
9999
individual-header-build:
@@ -154,6 +154,6 @@ jobs:
154154
echo "Building for header: $header_file"
155155
156156
# Configure and build
157-
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
157+
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
158158
cmake --build "$BUILD_DIR/$safe_name" --config ${{env.BUILD_TYPE}}
159159
done

CMakeLists.txt

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
1-
# set minimum version of CMake.
2-
cmake_minimum_required(VERSION 3.22)
3-
41
# enable the folder property for the whole project
52
set_property(GLOBAL PROPERTY USE_FOLDERS TRUE)
63

7-
# The Generic system name is used for embedded targets (targets without OS) in
8-
# CMake
9-
set(CMAKE_SYSTEM_NAME Generic)
10-
set(CMAKE_SYSTEM_PROCESSOR ARM)
11-
12-
# Supress Error when trying to test the compiler
13-
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
14-
set(BUILD_SHARED_LIBS OFF)
15-
16-
# set project name and version
17-
project(klib VERSION 0.0.1)
4+
# provide the klib directory for the project
5+
set(KLIB_DIR ${CMAKE_CURRENT_LIST_DIR})
186

197
# enable assembly
208
enable_language(ASM)
@@ -48,7 +36,7 @@ if (DEFINED TARGET_CPU)
4836
message("Building for target: ${TARGET_CPU}")
4937

5038
# add the target directory
51-
add_subdirectory(${CMAKE_SOURCE_DIR}/targets/chip/${TARGET_CPU})
39+
include(${KLIB_DIR}/targets/chip/${TARGET_CPU}/CMakeLists.txt)
5240

5341
# check if the user configured the fpu
5442
if (DEFINED TARGET_FPU_ENABLED)
@@ -74,7 +62,7 @@ else()
7462
endif()
7563

7664
# add the klib library
77-
add_subdirectory(${CMAKE_SOURCE_DIR}/klib)
65+
include(${KLIB_DIR}/klib/CMakeLists.txt)
7866

79-
# add the project sources
80-
add_subdirectory(${CMAKE_SOURCE_DIR}/project)
67+
# include the linkerscript generator needed to preprocess the linkerscripts
68+
include(${KLIB_DIR}/targets/arm/linkerscript/linkerscript.cmake)

klib/CMakeLists.txt

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
# set the sources
2-
set(SOURCES
3-
${CMAKE_CURRENT_SOURCE_DIR}/entry/entry.c
4-
${CMAKE_CURRENT_SOURCE_DIR}/entry/secondary.cpp
2+
set(SOURCES
3+
${CMAKE_CURRENT_LIST_DIR}/entry/entry.c
4+
${CMAKE_CURRENT_LIST_DIR}/entry/secondary.cpp
55
)
66

77
set(HEADERS_PRIVATE
8-
${CMAKE_CURRENT_SOURCE_DIR}/comm/streams/stream_base.hpp
9-
${CMAKE_CURRENT_SOURCE_DIR}/comm/streams/combined_stream.hpp
10-
${CMAKE_CURRENT_SOURCE_DIR}/comm/streams/istream.hpp
11-
${CMAKE_CURRENT_SOURCE_DIR}/comm/streams/ostream.hpp
8+
${CMAKE_CURRENT_LIST_DIR}/comm/streams/stream_base.hpp
9+
${CMAKE_CURRENT_LIST_DIR}/comm/streams/combined_stream.hpp
10+
${CMAKE_CURRENT_LIST_DIR}/comm/streams/istream.hpp
11+
${CMAKE_CURRENT_LIST_DIR}/comm/streams/ostream.hpp
1212
)
1313

1414
set(HEADERS_PUBLIC
15-
${CMAKE_CURRENT_SOURCE_DIR}/irq.hpp
16-
${CMAKE_CURRENT_SOURCE_DIR}/klib.hpp
17-
${CMAKE_CURRENT_SOURCE_DIR}/stream.hpp
15+
${CMAKE_CURRENT_LIST_DIR}/irq.hpp
16+
${CMAKE_CURRENT_LIST_DIR}/klib.hpp
17+
${CMAKE_CURRENT_LIST_DIR}/stream.hpp
1818
)
1919

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

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

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

3131
# check if we need to include the systemview sources
32-
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/comm/segger/src/SYSVIEW/)
32+
if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/comm/segger/src/SYSVIEW/)
3333
# append the systemview sources
34-
set(SOURCES ${SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/comm/segger/src/SYSVIEW/SEGGER_SYSVIEW.c)
35-
set(SOURCES ${SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/comm/segger/src/SYSVIEW/SEGGER_SYSVIEW_Config_NoOS.c)
34+
set(SOURCES ${SOURCES} ${CMAKE_CURRENT_LIST_DIR}/comm/segger/src/SYSVIEW/SEGGER_SYSVIEW.c)
35+
set(SOURCES ${SOURCES} ${CMAKE_CURRENT_LIST_DIR}/comm/segger/src/SYSVIEW/SEGGER_SYSVIEW_Config_NoOS.c)
3636
endif()
3737
else()
3838
message("Segger RTT support disabled")
@@ -99,7 +99,7 @@ endif()
9999

100100
# enabled segger support in the defines to prevent a
101101
# include of the segger files
102-
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/comm/segger/src/)
102+
if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/comm/segger/src/)
103103
target_compile_definitions(klib PUBLIC "KLIB_SEGGER_SUPPORT=1")
104104
else()
105105
target_compile_definitions(klib PUBLIC "KLIB_SEGGER_SUPPORT=0")
@@ -111,7 +111,7 @@ endif()
111111
# - header location in project: ${CMAKE_CURRENT_BINARY_DIR}/generated_headers
112112
target_include_directories(
113113
klib PUBLIC
114-
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>"
115-
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>"
114+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/../>"
115+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/../>"
116116
"$<BUILD_INTERFACE:${GENERATED_HEADERS_DIR}>"
117117
)

project/CMakeLists.txt

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
1-
# include the linkerscript generator needed to preprocess the linkerscripts
2-
include (${CMAKE_SOURCE_DIR}/targets/arm/linkerscript/linkerscript.cmake)
1+
# The Generic system name is used for embedded targets (targets without OS) in
2+
# CMake
3+
set(CMAKE_SYSTEM_NAME Generic)
4+
set(CMAKE_SYSTEM_PROCESSOR ARM)
5+
6+
# Supress Error when trying to test the compiler
7+
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
8+
set(BUILD_SHARED_LIBS OFF)
9+
10+
# set minimum version of CMake.
11+
cmake_minimum_required(VERSION 3.22)
12+
13+
# set project name and version
14+
project(klib VERSION 0.0.1)
15+
16+
# provide the klib directory for the project (repo root, one level up)
17+
set(KLIB_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
18+
19+
# include klib and all common toolchain + target setup from the klib repo root.
20+
# This configures the build-type flags, includes the target cpu (creating the
21+
# target_cpu / target_cpu_options targets), defines the add_linkerscript()
22+
# helper and builds the klib library target.
23+
# Note: KLIB_DIR needs to point to your klib installation folder.
24+
include(${KLIB_DIR}/CMakeLists.txt)
325

426
# set the sources
527
set(SOURCES
628
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
729

830
# example for including the startup.cpp
9-
# ${CMAKE_SOURCE_DIR}/targets/chip/${TARGET_CPU}/startup.cpp
31+
# ${KLIB_DIR}/targets/chip/${TARGET_CPU}/startup.cpp
1032
)
1133

1234
set(HEADERS)
@@ -42,6 +64,9 @@ target_link_libraries(klib_project PUBLIC target_cpu)
4264
# Libraries to link for all targets
4365
target_link_libraries(klib_project PUBLIC m)
4466

67+
# get the linkerscript we should link against
68+
get_property(TARGET_LINKERSCRIPT GLOBAL PROPERTY TARGET_LINKERSCRIPT)
69+
4570
# link to the linkerscript of the target cpu
4671
add_linkerscript(klib_project ${TARGET_LINKERSCRIPT} "")
4772

targets/arm/linkerscript/linkerscript.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# macroes, conditionals, etc)
44
function(add_linkerscript target linkerscript options)
55
set(output "${CMAKE_BINARY_DIR}/linkerscript.ld")
6-
set(CURRENT_DIR "${CMAKE_SOURCE_DIR}/targets/arm/linkerscript")
6+
set(CURRENT_DIR "${KLIB_DIR}/targets/arm/linkerscript")
77

88
# run the preprocessor on the linkerscript
99
add_custom_command(

targets/chip/atsam3x8e/CMakeLists.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# export our linkerscript
2-
set(TARGET_LINKERSCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/linkerscript.ld" PARENT_SCOPE)
2+
set_property(GLOBAL PROPERTY TARGET_LINKERSCRIPT "${CMAKE_CURRENT_LIST_DIR}/linkerscript.ld")
33

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

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

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

3838
# cpu atsam3x8e target drivers
3939
set(SOURCES
40-
${CMAKE_CURRENT_SOURCE_DIR}/../../arm/vector_table/cortex-m3.cpp
40+
${CMAKE_CURRENT_LIST_DIR}/../../arm/vector_table/cortex-m3.cpp
4141
)
4242

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

6565
# set the target_cpu for klib
66-
get_filename_component(TARGET_CPU_FOLDER ${CMAKE_CURRENT_SOURCE_DIR} NAME)
67-
set(TARGET_CPU ${TARGET_CPU_FOLDER} PARENT_SCOPE)
66+
get_filename_component(TARGET_CPU_FOLDER ${CMAKE_CURRENT_LIST_DIR} NAME)
67+
set_property(GLOBAL PROPERTY TARGET_CPU ${TARGET_CPU_FOLDER})
6868
target_compile_definitions(target_cpu PUBLIC "TARGET_CPU=${TARGET_CPU}")
6969

7070
# add target specific compile options
@@ -80,7 +80,6 @@ target_link_libraries(target_cpu PUBLIC klib)
8080
# - header location in project: ${CMAKE_CURRENT_BINARY_DIR}/generated_headers
8181
target_include_directories(
8282
target_cpu PUBLIC
83-
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
84-
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
83+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>"
8584
"$<BUILD_INTERFACE:${GENERATED_HEADERS_DIR}>"
8685
)

targets/chip/atsam4s2b/CMakeLists.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# export our linkerscript
2-
set(TARGET_LINKERSCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/linkerscript.ld" PARENT_SCOPE)
2+
set_property(GLOBAL PROPERTY TARGET_LINKERSCRIPT "${CMAKE_CURRENT_LIST_DIR}/linkerscript.ld")
33

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

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

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

3434
# cpu atsam4s2b target drivers
3535
set(SOURCES
36-
${CMAKE_CURRENT_SOURCE_DIR}/../../arm/vector_table/cortex-m4.cpp
36+
${CMAKE_CURRENT_LIST_DIR}/../../arm/vector_table/cortex-m4.cpp
3737
)
3838

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

6161
# set the target_cpu for klib
62-
get_filename_component(TARGET_CPU_FOLDER ${CMAKE_CURRENT_SOURCE_DIR} NAME)
63-
set(TARGET_CPU ${TARGET_CPU_FOLDER} PARENT_SCOPE)
62+
get_filename_component(TARGET_CPU_FOLDER ${CMAKE_CURRENT_LIST_DIR} NAME)
63+
set_property(GLOBAL PROPERTY TARGET_CPU ${TARGET_CPU_FOLDER})
6464
target_compile_definitions(target_cpu PUBLIC "TARGET_CPU=${TARGET_CPU}")
6565

6666
# add target specific compile options
@@ -76,7 +76,6 @@ target_link_libraries(target_cpu PUBLIC klib)
7676
# - header location in project: ${CMAKE_CURRENT_BINARY_DIR}/generated_headers
7777
target_include_directories(
7878
target_cpu PUBLIC
79-
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
80-
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
79+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>"
8180
"$<BUILD_INTERFACE:${GENERATED_HEADERS_DIR}>"
8281
)

targets/chip/lpc1752/CMakeLists.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# export our linkerscript
2-
set(TARGET_LINKERSCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/linkerscript.ld" PARENT_SCOPE)
2+
set_property(GLOBAL PROPERTY TARGET_LINKERSCRIPT "${CMAKE_CURRENT_LIST_DIR}/linkerscript.ld")
33

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

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

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

3434
# cpu lpc1752 target drivers
3535
set(SOURCES
36-
${CMAKE_CURRENT_SOURCE_DIR}/../../arm/vector_table/cortex-m3.cpp
36+
${CMAKE_CURRENT_LIST_DIR}/../../arm/vector_table/cortex-m3.cpp
3737
)
3838

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

6161
# set the target_cpu for klib
62-
get_filename_component(TARGET_CPU_FOLDER ${CMAKE_CURRENT_SOURCE_DIR} NAME)
63-
set(TARGET_CPU ${TARGET_CPU_FOLDER} PARENT_SCOPE)
62+
get_filename_component(TARGET_CPU_FOLDER ${CMAKE_CURRENT_LIST_DIR} NAME)
63+
set_property(GLOBAL PROPERTY TARGET_CPU ${TARGET_CPU_FOLDER})
6464
target_compile_definitions(target_cpu PUBLIC "TARGET_CPU=${TARGET_CPU}")
6565

6666
# add target specific compile options
@@ -76,7 +76,6 @@ target_link_libraries(target_cpu PUBLIC klib)
7676
# - header location in project: ${CMAKE_CURRENT_BINARY_DIR}/generated_headers
7777
target_include_directories(
7878
target_cpu PUBLIC
79-
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
80-
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
79+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>"
8180
"$<BUILD_INTERFACE:${GENERATED_HEADERS_DIR}>"
8281
)

0 commit comments

Comments
 (0)