|
1 |
| -#=============================================================================# |
2 |
| -# _get_board_id |
3 |
| -# [PRIVATE/INTERNAL] |
4 |
| -# |
5 |
| -# _get_board_id(BOARD_NAME BOARD_CPU TARGET_NAME OUTPUT_VAR) |
6 |
| -# |
7 |
| -# BOARD_NAME - name of the board, eg.: nano, uno, etc... |
8 |
| -# BOARD_CPU - come boards has multiple versions with different cpus, eg.: nano has atmega168 and atmega328 |
9 |
| -# TARGET_NAME - name of the build target, used to show clearer error message |
10 |
| -# OUT_VAR - BOARD_ID constructed from BOARD_NAME and BOARD_CPU |
11 |
| -# |
12 |
| -# returns BOARD_ID constructing from BOARD_NAME and BOARD_CPU, if board doesn't has multiple cpus then BOARD_ID = BOARD_NAME |
13 |
| -# if board has multiple CPUS, and BOARD_CPU is not defined or incorrect, fatal error will be invoked. |
14 |
| -#=============================================================================# |
15 |
| -function(_GET_BOARD_ID BOARD_NAME BOARD_CPU TARGET_NAME OUTPUT_VAR) |
16 |
| - if (${BOARD_NAME}.menu.CPUS) |
17 |
| - if (BOARD_CPU) |
18 |
| - LIST(FIND ${BOARD_NAME}.menu.CPUS ${BOARD_CPU} CPU_INDEX) |
19 |
| - if (CPU_INDEX EQUAL -1) |
20 |
| - message(FATAL_ERROR "Invalid BOARD_CPU (valid cpus: ${${BOARD_NAME}.menu.CPUS}).") |
21 |
| - endif() |
22 |
| - else() |
23 |
| - message(FATAL_ERROR "Board has multiple CPU versions (${${BOARD_NAME}.menu.CPUS}). BOARD_CPU must be defined for target ${TARGET_NAME}.") |
24 |
| - endif() |
25 |
| - set(${OUTPUT_VAR} ${BOARD_NAME}.${BOARD_CPU} PARENT_SCOPE) |
26 |
| - else() |
27 |
| - set(${OUTPUT_VAR} ${BOARD_NAME} PARENT_SCOPE) |
28 |
| - endif() |
29 |
| -endfunction() |
30 |
| - |
31 |
| -#=============================================================================# |
32 |
| -# _get_board_property |
33 |
| -# [PRIVATE/INTERNAL] |
34 |
| -# |
35 |
| -# _get_board_property(BOARD_ID PROPERTY_NAME OUTPUT_VAR) |
36 |
| -# |
37 |
| -# BOARD_ID - return value from function "_get_board_id (BOARD_NAME, BOARD_CPU)". It contains BOARD_NAME and BOARD_CPU |
38 |
| -# PROPERTY_NAME - property name for the board, eg.: bootloader.high_fuses |
39 |
| -# OUT_VAR - variable holding value for the property |
40 |
| -# |
41 |
| -# Gets board property. |
42 |
| -# Reconstructs BOARD_NAME and BOARD_CPU from BOARD_ID and tries to find value at ${BOARD_NAME}.${PROPERTY_NAME}, |
43 |
| -# if not found than try to find value at ${BOARD_NAME}.menu.cpu.${BOARD_CPU}.${PROPERTY_NAME} |
44 |
| -# if not found that show fatal error |
45 |
| -#=============================================================================# |
46 |
| -function(_GET_BOARD_PROPERTY BOARD_ID PROPERTY_NAME OUTPUT_VAR) |
47 |
| - string(REPLACE "." ";" BOARD_INFO ${BOARD_ID}) |
48 |
| - list(GET BOARD_INFO 0 BOARD_NAME) |
49 |
| - set(VALUE ${${BOARD_NAME}.${PROPERTY_NAME}}) |
50 |
| - if(NOT VALUE) |
51 |
| - list(LENGTH BOARD_INFO INFO_PARAMS_COUNT) |
52 |
| - if (${INFO_PARAMS_COUNT} EQUAL 2) |
53 |
| - list(GET BOARD_INFO 1 BOARD_CPU) |
54 |
| - VALIDATE_VARIABLES_NOT_EMPTY(VARS BOARD_CPU MSG "cannot find CPU info, must define BOARD_CPU.") |
55 |
| - set(VALUE ${${BOARD_NAME}.menu.cpu.${BOARD_CPU}.${PROPERTY_NAME}}) |
56 |
| - endif() |
57 |
| - endif() |
58 |
| - if (NOT VALUE) |
59 |
| - message(FATAL_ERROR "Board info not found: BoardName='${BOARD_NAME}' BoardCPU='${BOARD_CPU}' PropertyName='${PROPERTY_NAME}'") |
60 |
| - endif() |
61 |
| - set(${OUTPUT_VAR} ${VALUE} PARENT_SCOPE) |
62 |
| -endfunction() |
63 |
| - |
64 |
| -#=============================================================================# |
65 |
| -# _get_board_property_if_exists |
66 |
| -# [PRIVATE/INTERNAL] |
67 |
| -# |
68 |
| -# _get_board_property_if_exists(BOARD_ID PROPERTY_NAME OUTPUT_VAR) |
69 |
| -# |
70 |
| -# BOARD_ID - return value from function "_get_board_id (BOARD_NAME, BOARD_CPU)". It contains BOARD_NAME and BOARD_CPU |
71 |
| -# PROPERTY_NAME - property name for the board, eg.: bootloader.high_fuses |
72 |
| -# OUT_VAR - variable holding value for the property |
73 |
| -# |
74 |
| -# Similar to _get_board_property, except it returns empty value if value was not found. |
75 |
| -#=============================================================================# |
76 |
| -function(_try_get_board_property BOARD_ID PROPERTY_NAME OUTPUT_VAR) |
77 |
| - string(REPLACE "." ";" BOARD_INFO ${BOARD_ID}) |
78 |
| - list(GET BOARD_INFO 0 BOARD_NAME) |
79 |
| - set(VALUE ${${BOARD_NAME}.${PROPERTY_NAME}}) |
80 |
| - if(NOT VALUE) |
81 |
| - list(LENGTH BOARD_INFO INFO_PARAMS_COUNT) |
82 |
| - if (${INFO_PARAMS_COUNT} EQUAL 2) |
83 |
| - list(GET BOARD_INFO 1 BOARD_CPU) |
84 |
| - VALIDATE_VARIABLES_NOT_EMPTY(VARS BOARD_CPU MSG "cannot find CPU info, must define BOARD_CPU.") |
85 |
| - set(VALUE ${${BOARD_NAME}.menu.cpu.${BOARD_CPU}.${PROPERTY_NAME}}) |
86 |
| - endif() |
87 |
| - endif() |
88 |
| - set(${OUTPUT_VAR} ${VALUE} PARENT_SCOPE) |
89 |
| -endfunction() |
| 1 | +#=============================================================================# |
| 2 | +# _get_board_id |
| 3 | +# [PRIVATE/INTERNAL] |
| 4 | +# |
| 5 | +# _get_board_id(BOARD_NAME BOARD_CPU TARGET_NAME OUTPUT_VAR) |
| 6 | +# |
| 7 | +# BOARD_NAME - name of the board, eg.: nano, uno, etc... |
| 8 | +# BOARD_CPU - come boards has multiple versions with different cpus, eg.: nano has atmega168 and atmega328 |
| 9 | +# TARGET_NAME - name of the build target, used to show clearer error message |
| 10 | +# OUT_VAR - BOARD_ID constructed from BOARD_NAME and BOARD_CPU |
| 11 | +# |
| 12 | +# returns BOARD_ID constructing from BOARD_NAME and BOARD_CPU, if board doesn't has multiple cpus then BOARD_ID = BOARD_NAME |
| 13 | +# if board has multiple CPUS, and BOARD_CPU is not defined or incorrect, fatal error will be invoked. |
| 14 | +#=============================================================================# |
| 15 | +function(_GET_BOARD_ID BOARD_NAME BOARD_CPU TARGET_NAME OUTPUT_VAR) |
| 16 | + if (${BOARD_NAME}.menu.CPUS) |
| 17 | + if (BOARD_CPU) |
| 18 | + LIST(FIND ${BOARD_NAME}.menu.CPUS ${BOARD_CPU} CPU_INDEX) |
| 19 | + if (CPU_INDEX EQUAL -1) |
| 20 | + message(FATAL_ERROR "Invalid BOARD_CPU (valid cpus: ${${BOARD_NAME}.menu.CPUS}).") |
| 21 | + endif() |
| 22 | + else() |
| 23 | + message(FATAL_ERROR "Board has multiple CPU versions (${${BOARD_NAME}.menu.CPUS}). BOARD_CPU must be defined for target ${TARGET_NAME}.") |
| 24 | + endif() |
| 25 | + set(${OUTPUT_VAR} ${BOARD_NAME}.${BOARD_CPU} PARENT_SCOPE) |
| 26 | + else() |
| 27 | + set(${OUTPUT_VAR} ${BOARD_NAME} PARENT_SCOPE) |
| 28 | + endif() |
| 29 | +endfunction() |
| 30 | + |
| 31 | +#=============================================================================# |
| 32 | +# _get_board_property |
| 33 | +# [PRIVATE/INTERNAL] |
| 34 | +# |
| 35 | +# _get_board_property(BOARD_ID PROPERTY_NAME OUTPUT_VAR) |
| 36 | +# |
| 37 | +# BOARD_ID - return value from function "_get_board_id (BOARD_NAME, BOARD_CPU)". It contains BOARD_NAME and BOARD_CPU |
| 38 | +# PROPERTY_NAME - property name for the board, eg.: bootloader.high_fuses |
| 39 | +# OUT_VAR - variable holding value for the property |
| 40 | +# |
| 41 | +# Gets board property. |
| 42 | +# Reconstructs BOARD_NAME and BOARD_CPU from BOARD_ID and tries to find value at ${BOARD_NAME}.${PROPERTY_NAME}, |
| 43 | +# if not found than try to find value at ${BOARD_NAME}.menu.cpu.${BOARD_CPU}.${PROPERTY_NAME} |
| 44 | +# if not found that show fatal error |
| 45 | +#=============================================================================# |
| 46 | +function(_GET_BOARD_PROPERTY BOARD_ID PROPERTY_NAME OUTPUT_VAR) |
| 47 | + string(REPLACE "." ";" BOARD_INFO ${BOARD_ID}) |
| 48 | + list(GET BOARD_INFO 0 BOARD_NAME) |
| 49 | + set(VALUE ${${BOARD_NAME}.${PROPERTY_NAME}}) |
| 50 | + if(NOT VALUE) |
| 51 | + list(LENGTH BOARD_INFO INFO_PARAMS_COUNT) |
| 52 | + if (${INFO_PARAMS_COUNT} EQUAL 2) |
| 53 | + list(GET BOARD_INFO 1 BOARD_CPU) |
| 54 | + VALIDATE_VARIABLES_NOT_EMPTY(VARS BOARD_CPU MSG "cannot find CPU info, must define BOARD_CPU.") |
| 55 | + set(VALUE ${${BOARD_NAME}.menu.cpu.${BOARD_CPU}.${PROPERTY_NAME}}) |
| 56 | + endif() |
| 57 | + endif() |
| 58 | + if (NOT VALUE) |
| 59 | + message(FATAL_ERROR "Board info not found: BoardName='${BOARD_NAME}' BoardCPU='${BOARD_CPU}' PropertyName='${PROPERTY_NAME}'") |
| 60 | + endif() |
| 61 | + set(${OUTPUT_VAR} ${VALUE} PARENT_SCOPE) |
| 62 | +endfunction() |
| 63 | + |
| 64 | +#=============================================================================# |
| 65 | +# _get_board_property_if_exists |
| 66 | +# [PRIVATE/INTERNAL] |
| 67 | +# |
| 68 | +# _get_board_property_if_exists(BOARD_ID PROPERTY_NAME OUTPUT_VAR) |
| 69 | +# |
| 70 | +# BOARD_ID - return value from function "_get_board_id (BOARD_NAME, BOARD_CPU)". It contains BOARD_NAME and BOARD_CPU |
| 71 | +# PROPERTY_NAME - property name for the board, eg.: bootloader.high_fuses |
| 72 | +# OUT_VAR - variable holding value for the property |
| 73 | +# |
| 74 | +# Similar to _get_board_property, except it returns empty value if value was not found. |
| 75 | +#=============================================================================# |
| 76 | +function(_try_get_board_property BOARD_ID PROPERTY_NAME OUTPUT_VAR) |
| 77 | + string(REPLACE "." ";" BOARD_INFO ${BOARD_ID}) |
| 78 | + list(GET BOARD_INFO 0 BOARD_NAME) |
| 79 | + set(VALUE ${${BOARD_NAME}.${PROPERTY_NAME}}) |
| 80 | + if(NOT VALUE) |
| 81 | + list(LENGTH BOARD_INFO INFO_PARAMS_COUNT) |
| 82 | + if (${INFO_PARAMS_COUNT} EQUAL 2) |
| 83 | + list(GET BOARD_INFO 1 BOARD_CPU) |
| 84 | + VALIDATE_VARIABLES_NOT_EMPTY(VARS BOARD_CPU MSG "cannot find CPU info, must define BOARD_CPU.") |
| 85 | + set(VALUE ${${BOARD_NAME}.menu.cpu.${BOARD_CPU}.${PROPERTY_NAME}}) |
| 86 | + endif() |
| 87 | + endif() |
| 88 | + set(${OUTPUT_VAR} ${VALUE} PARENT_SCOPE) |
| 89 | +endfunction() |
0 commit comments