Skip to content

Commit 16bed53

Browse files
authored
Updated cmake-tutorial (#14)
1 parent daa1820 commit 16bed53

File tree

179 files changed

+1998
-2226
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

179 files changed

+1998
-2226
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
_builds
2+
hello-world
23
Testing
34

README.md

Lines changed: 160 additions & 232 deletions
Large diffs are not rendered by default.

examples/430/iar-cspy-430.cmake

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Example for creating a test for CTest
2+
# to execute the `IAR C-SPY Command-line Utility (cspybat.exe)`
3+
4+
function(iar_cspy_add_test TARGET TEST_NAME EXPECTED_OUTPUT)
5+
# Add a test for CTest
6+
add_test(NAME ${TEST_NAME}
7+
COMMAND ${TOOLKIT_DIR}/../common/bin/cspybat --silent
8+
# C-SPY drivers
9+
"${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}proc.dll"
10+
"${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}sim.dll"
11+
"--plugin=${TOOLKIT_DIR}/bin/${CMAKE_SYSTEM_PROCESSOR}bat.dll"
12+
--debug_file=$<TARGET_FILE:${TARGET}>
13+
# C-SPY macros settings
14+
"--macro=${CMAKE_CURRENT_SOURCE_DIR}/${TARGET}.mac"
15+
"--macro_param=testName=\"${TEST_NAME}\""
16+
"--macro_param=testExpected=${EXPECTED_OUTPUT}"
17+
# C-SPY backend setup
18+
--backend
19+
-p $<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET},DDF>>,$<TARGET_PROPERTY:${TARGET},DDF>,${TOOLKIT_DIR}/config/debugger/msp430f149.ddf>
20+
--hwmul_base=0x130
21+
--hardware_multiplier=16
22+
--hwmult_type=1
23+
--iv_base=0xFFE0
24+
--odd_word_check
25+
--derivativeSim=MSP430F149
26+
-d sim )
27+
28+
# Set the test to interpret a C-SPY's message containing `PASS`
29+
set_tests_properties(${TEST_NAME} PROPERTIES PASS_REGULAR_EXPRESSION "PASS")
30+
endfunction()

examples/430/mix-c-asm/CMakeLists.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
cmake_minimum_required(VERSION 3.22)
2+
3+
# Set the project name, [description] and [version],
4+
# while enabling its required languages
5+
project(Example1
6+
DESCRIPTION "Mixing C and Assembly"
7+
VERSION 1.0.0
8+
LANGUAGES C ASM )
9+
10+
# Fallback option for generators other than `Ninja Multi-Config`
11+
if (NOT DEFINED CMAKE_BUILD_TYPE)
12+
set(CMAKE_BUILD_TYPE Debug)
13+
endif()
14+
15+
# Enable CTest
16+
enable_testing()
17+
18+
# Add the executable for the "mixLanguages" target
19+
add_executable(mixLanguages
20+
# Source files
21+
main.c
22+
mynum.asm )
23+
24+
# Set a preprocessor symbol, usable from "mixLanguages" target
25+
target_compile_definitions(mixLanguages PUBLIC USE_ASM=1)
26+
27+
# Set the compiler flags for the "mixLanguages" target
28+
target_compile_options(mixLanguages PRIVATE
29+
$<$<COMPILE_LANGUAGE:C>:--multiplier=16 --dlib_config ${TOOLKIT_DIR}/lib/dlib/dl430fn.h>
30+
-D__MSP430F149__ )
31+
32+
# Set the linker options for the "mixLanguages" target
33+
target_link_options(mixLanguages PRIVATE
34+
-f ${TOOLKIT_DIR}/config/linker/lnk430f149.xcl
35+
${TOOLKIT_DIR}/lib/dlib/dl430fn.r43
36+
# The `SHELL:` prefix prevents option de-duplication
37+
"SHELL:-D_DATA16_HEAP_SIZE=50"
38+
"SHELL:-D_STACK_SIZE=50"
39+
"SHELL:-D_DATA20_HEAP_SIZE=50" )
40+
41+
# Optional: test the project with C-SPY
42+
include(../iar-cspy-430.cmake)
43+
iar_cspy_add_test(mixLanguages test_mynum 42)
File renamed without changes.
File renamed without changes.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Add the executable for the "myProgram" target,
2+
# specifying its source files
3+
add_executable (myProgram
4+
# Source files
5+
main.c )
6+
7+
# Set the properties for the "myProgram" target
8+
set_target_properties(myProgram PROPERTIES
9+
XCL "${TOOLKIT_DIR}/config/linker/lnk430f149.xcl"
10+
# C-SPY-related properties
11+
DDF "${TOOLKIT_DIR}/config/debugger/msp430f149.ddf" )
12+
13+
# Set the compiler flags for the target
14+
target_compile_options(myProgram PRIVATE
15+
$<$<COMPILE_LANGUAGE:C>:--multiplier=16 --double=32 --dlib_config ${TOOLKIT_DIR}/lib/dlib/dl430fn.h>
16+
-D__MSP430F149__ )
17+
18+
# Set the linker flags for the target
19+
target_link_options(myProgram PRIVATE
20+
-s __program_start
21+
# Create a map file from the target's UBROF
22+
-l $<TARGET_PROPERTY:NAME>.map
23+
# The `SHELL:` prefix prevents option de-duplication
24+
"SHELL:-D_DATA16_HEAP_SIZE=50"
25+
"SHELL:-D_STACK_SIZE=50"
26+
"SHELL:-D_DATA20_HEAP_SIZE=50"
27+
# Set the linker script
28+
-f $<TARGET_PROPERTY:XCL>
29+
# The `SHELL:` prefix prevents option de-duplication
30+
"SHELL:-f ${TOOLKIT_DIR}/config/linker/multiplier.xcl"
31+
-rt ${TOOLKIT_DIR}/lib/dlib/dl430fn.r43 )
32+
33+
# Link "myProgram" against the "myMath" library
34+
target_link_libraries(myProgram LINK_PUBLIC myMath)
35+
36+
# Optional: test the project with C-SPY
37+
include(../../iar-cspy-430.cmake)
38+
iar_cspy_add_test(myProgram test_add 42)
39+
iar_cspy_add_test(myProgram test_sub 38)
40+
iar_cspy_add_test(myProgram test_mul 80)

0 commit comments

Comments
 (0)