Skip to content

Commit fb4955a

Browse files
committed
cmake: Fix compilation options for kobject_hash*.c
Rework how the compilation-options for the gperf generated kobject_hash*.c files are put together to fix problems with SHELL: and cmake-list separators handling. zephyr_get_compile_options_for_lang_as_string() returns the set of options as a cmake generator expression string which is cumbersome to edit. This caused the command line for the IAR toolchain to have broken SHELL: entries, and other some command line entries being postfixed by "gnu". This also adds CMake compiler properties for no_function_sections and no_data_sections options Signed-off-by: Björn Bergman <[email protected]>
1 parent f527494 commit fb4955a

File tree

4 files changed

+39
-10
lines changed

4 files changed

+39
-10
lines changed

CMakeLists.txt

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,10 +1094,19 @@ if(CONFIG_CODE_DATA_RELOCATION)
10941094
endif()
10951095

10961096
if(CONFIG_USERSPACE)
1097-
zephyr_get_compile_options_for_lang_as_string(C compiler_flags_priv)
1097+
# Go for raw properties here since zephyr_get_compile_options_for_lang()
1098+
# processes the list of options, and wraps it in a $<JOIN thing. When
1099+
# generating the build systems this leads to some interesting command lines,
1100+
# with SHELL: not being present and other "random" list-join related issues
1101+
# (e.g. for IAR toolchains the lists were joined with "gnu" postfixed on a
1102+
# bunch of entries).
1103+
get_property(compiler_flags_priv TARGET zephyr_interface PROPERTY INTERFACE_COMPILE_OPTIONS)
10981104
string(REPLACE "$<TARGET_PROPERTY:compiler,coverage>" ""
1099-
NO_COVERAGE_FLAGS "${compiler_flags_priv}"
1100-
)
1105+
KOBJECT_HASH_COMPILE_OPTIONS "${compiler_flags_priv}")
1106+
1107+
list(APPEND KOBJECT_HASH_COMPILE_OPTIONS
1108+
$<TARGET_PROPERTY:compiler,no_function_sections>
1109+
$<TARGET_PROPERTY:compiler,no_data_sections>)
11011110

11021111
set(GEN_KOBJ_LIST ${ZEPHYR_BASE}/scripts/build/gen_kobject_list.py)
11031112
set(PROCESS_GPERF ${ZEPHYR_BASE}/scripts/build/process_gperf.py)
@@ -1297,11 +1306,13 @@ if(CONFIG_USERSPACE)
12971306
add_library(
12981307
kobj_prebuilt_hash_output_lib
12991308
OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_PREBUILT_HASH_OUTPUT_SRC}
1300-
)
1309+
)
13011310

1302-
set_source_files_properties(${KOBJECT_PREBUILT_HASH_OUTPUT_SRC}
1303-
PROPERTIES COMPILE_FLAGS
1304-
"${NO_COVERAGE_FLAGS} -fno-function-sections -fno-data-sections")
1311+
# set_target_properties sets ALL properties, target_compile_options() adds
1312+
# and KOBJECT_HASH_COMPILE_OPTIONS contains all the options.
1313+
set_target_properties(kobj_prebuilt_hash_output_lib PROPERTIES
1314+
COMPILE_OPTIONS "${KOBJECT_HASH_COMPILE_OPTIONS}"
1315+
)
13051316

13061317
target_compile_definitions(kobj_prebuilt_hash_output_lib
13071318
PRIVATE $<TARGET_PROPERTY:zephyr_interface,INTERFACE_COMPILE_DEFINITIONS>
@@ -1509,9 +1520,9 @@ if(CONFIG_USERSPACE)
15091520
OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_HASH_OUTPUT_SRC}
15101521
)
15111522

1512-
set_source_files_properties(${KOBJECT_HASH_OUTPUT_SRC}
1513-
PROPERTIES COMPILE_FLAGS
1514-
"${NO_COVERAGE_FLAGS} -fno-function-sections -fno-data-sections")
1523+
set_target_properties(kobj_hash_output_lib PROPERTIES
1524+
COMPILE_OPTIONS "${KOBJECT_HASH_COMPILE_OPTIONS}"
1525+
)
15151526

15161527
target_compile_definitions(kobj_hash_output_lib
15171528
PRIVATE $<TARGET_PROPERTY:zephyr_interface,INTERFACE_COMPILE_DEFINITIONS>

cmake/compiler/arcmwdt/compiler_flags.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,9 @@ set_compiler_property(PROPERTY warning_shadow_variables)
213213

214214
set_compiler_property(PROPERTY no_builtin -fno-builtin)
215215
set_compiler_property(PROPERTY no_builtin_malloc -fno-builtin-malloc)
216+
217+
# Compiler flag for not placing functions in their own sections:
218+
set_compiler_property(PROPERTY no_function_sections "-fno-function-sections")
219+
220+
# Compiler flag for not placing variables in their own sections:
221+
set_compiler_property(PROPERTY no_data_sections "-fno-data-sections")

cmake/compiler/compiler_flags_template.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,9 @@ set_compiler_property(PROPERTY include_file)
157157
set_compiler_property(PROPERTY cmse)
158158

159159
set_property(TARGET asm PROPERTY cmse)
160+
161+
# Compiler flag for not placing functions in their own sections:
162+
set_compiler_property(PROPERTY no_function_sections)
163+
164+
# Compiler flag for not placing variables in their own sections:
165+
set_compiler_property(PROPERTY no_data_sections)

cmake/compiler/gcc/compiler_flags.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,9 @@ set_compiler_property(PROPERTY include_file -include)
260260
set_compiler_property(PROPERTY cmse -mcmse)
261261

262262
set_property(TARGET asm PROPERTY cmse -mcmse)
263+
264+
# Compiler flag for not placing functions in their own sections:
265+
set_compiler_property(PROPERTY no_function_sections "-fno-function-sections")
266+
267+
# Compiler flag for not placing variables in their own sections:
268+
set_compiler_property(PROPERTY no_data_sections "-fno-data-sections")

0 commit comments

Comments
 (0)