Issue
I am attempting to initialize a uint8_t
array with a preprocessor definition that is overwritten in a CMakeLists.txt file. For example:
#ifndef MY_CHAR_ARRAY
#define MY_CHAR_ARRAY {0x00, 0x01, 0x02}
#endif
uint8_t str[3] = MY_CHAR_ARRAY;
What is the syntax, if it exists, to overwrite MY_CHAR_ARRAY
using add_compile_definitions()
in my CMakeLists.txt file?
I have made various guesses of the syntax:
add_compile_definitions(MY_CHAR_ARRAY={0xAA, 0xBB, 0xCC})
add_compile_definitions(MY_CHAR_ARRAY={0xAA}{0xBB}{0xCC}
add_compile_definitions(MY_CHAR_ARRAY={0xAA},{0xBB},{0xCC}
add_compile_definitions(MY_CHAR_ARRAY={0xAA} {0xBB} {0xCC}
add_compile_definitions(MY_CHAR_ARRAY={0xAA0xBB0xCC}
add_compile_definitions(MY_CHAR_ARRAY={0xAA 0xBB 0xCC}
add_compile_definitions(MY_CHAR_ARRAY={0xAABBCC}
with no luck.
Thank you.
Solution
Enclose the whole string in double quotes.
add_compile_definitions("MY_CHAR_ARRAY={0xAA, 0xBB, 0xCC}")
Prefer target_compile_definitions
.
Answered By - KamilCuk Answer Checked By - David Goodson (WPSolving Volunteer)