Skip to content

Commit bb797ab

Browse files
bjorniuppsalanashif
authored andcommitted
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 <bjorn.bergman@iar.com>
1 parent e87e054 commit bb797ab

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
@@ -1104,10 +1104,19 @@ if(CONFIG_CODE_DATA_RELOCATION)
11041104
endif()
11051105

11061106
if(CONFIG_USERSPACE)
1107-
zephyr_get_compile_options_for_lang_as_string(C compiler_flags_priv)
1107+
# Go for raw properties here since zephyr_get_compile_options_for_lang()
1108+
# processes the list of options, and wraps it in a $<JOIN thing. When
1109+
# generating the build systems this leads to some interesting command lines,
1110+
# with SHELL: not being present and other "random" list-join related issues
1111+
# (e.g. for IAR toolchains the lists were joined with "gnu" postfixed on a
1112+
# bunch of entries).
1113+
get_property(compiler_flags_priv TARGET zephyr_interface PROPERTY INTERFACE_COMPILE_OPTIONS)
11081114
string(REPLACE "$<TARGET_PROPERTY:compiler,coverage>" ""
1109-
NO_COVERAGE_FLAGS "${compiler_flags_priv}"
1110-
)
1115+
KOBJECT_HASH_COMPILE_OPTIONS "${compiler_flags_priv}")
1116+
1117+
list(APPEND KOBJECT_HASH_COMPILE_OPTIONS
1118+
$<TARGET_PROPERTY:compiler,no_function_sections>
1119+
$<TARGET_PROPERTY:compiler,no_data_sections>)
11111120

11121121
set(PROCESS_GPERF ${ZEPHYR_BASE}/scripts/build/process_gperf.py)
11131122
endif()
@@ -1305,11 +1314,13 @@ if(CONFIG_USERSPACE)
13051314
add_library(
13061315
kobj_prebuilt_hash_output_lib
13071316
OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_PREBUILT_HASH_OUTPUT_SRC}
1308-
)
1317+
)
13091318

1310-
set_source_files_properties(${KOBJECT_PREBUILT_HASH_OUTPUT_SRC}
1311-
PROPERTIES COMPILE_FLAGS
1312-
"${NO_COVERAGE_FLAGS} -fno-function-sections -fno-data-sections")
1319+
# set_target_properties sets ALL properties, target_compile_options() adds
1320+
# and KOBJECT_HASH_COMPILE_OPTIONS contains all the options.
1321+
set_target_properties(kobj_prebuilt_hash_output_lib PROPERTIES
1322+
COMPILE_OPTIONS "${KOBJECT_HASH_COMPILE_OPTIONS}"
1323+
)
13131324

13141325
target_compile_definitions(kobj_prebuilt_hash_output_lib
13151326
PRIVATE $<TARGET_PROPERTY:zephyr_interface,INTERFACE_COMPILE_DEFINITIONS>
@@ -1514,9 +1525,9 @@ if(CONFIG_USERSPACE)
15141525
OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_HASH_OUTPUT_SRC}
15151526
)
15161527

1517-
set_source_files_properties(${KOBJECT_HASH_OUTPUT_SRC}
1518-
PROPERTIES COMPILE_FLAGS
1519-
"${NO_COVERAGE_FLAGS} -fno-function-sections -fno-data-sections")
1528+
set_target_properties(kobj_hash_output_lib PROPERTIES
1529+
COMPILE_OPTIONS "${KOBJECT_HASH_COMPILE_OPTIONS}"
1530+
)
15201531

15211532
target_compile_definitions(kobj_hash_output_lib
15221533
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
@@ -215,3 +215,9 @@ set_compiler_property(PROPERTY warning_no_array_bounds)
215215

216216
set_compiler_property(PROPERTY no_builtin -fno-builtin)
217217
set_compiler_property(PROPERTY no_builtin_malloc -fno-builtin-malloc)
218+
219+
# Compiler flag for not placing functions in their own sections:
220+
set_compiler_property(PROPERTY no_function_sections "-fno-function-sections")
221+
222+
# Compiler flag for not placing variables in their own sections:
223+
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
@@ -161,3 +161,9 @@ set_compiler_property(PROPERTY include_file)
161161
set_compiler_property(PROPERTY cmse)
162162

163163
set_property(TARGET asm PROPERTY cmse)
164+
165+
# Compiler flag for not placing functions in their own sections:
166+
set_compiler_property(PROPERTY no_function_sections)
167+
168+
# Compiler flag for not placing variables in their own sections:
169+
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
@@ -266,3 +266,9 @@ set_compiler_property(PROPERTY include_file -include)
266266
set_compiler_property(PROPERTY cmse -mcmse)
267267

268268
set_property(TARGET asm PROPERTY cmse -mcmse)
269+
270+
# Compiler flag for not placing functions in their own sections:
271+
set_compiler_property(PROPERTY no_function_sections "-fno-function-sections")
272+
273+
# Compiler flag for not placing variables in their own sections:
274+
set_compiler_property(PROPERTY no_data_sections "-fno-data-sections")

0 commit comments

Comments
 (0)