Skip to content

Commit 888b9c0

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 8457db5 commit 888b9c0

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
@@ -1085,10 +1085,19 @@ if(CONFIG_CODE_DATA_RELOCATION)
10851085
endif()
10861086

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

10931102
set(GEN_KOBJ_LIST ${ZEPHYR_BASE}/scripts/build/gen_kobject_list.py)
10941103
set(PROCESS_GPERF ${ZEPHYR_BASE}/scripts/build/process_gperf.py)
@@ -1288,11 +1297,13 @@ if(CONFIG_USERSPACE)
12881297
add_library(
12891298
kobj_prebuilt_hash_output_lib
12901299
OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_PREBUILT_HASH_OUTPUT_SRC}
1291-
)
1300+
)
12921301

1293-
set_source_files_properties(${KOBJECT_PREBUILT_HASH_OUTPUT_SRC}
1294-
PROPERTIES COMPILE_FLAGS
1295-
"${NO_COVERAGE_FLAGS} -fno-function-sections -fno-data-sections")
1302+
# set_target_properties sets ALL properties, target_compile_options() adds
1303+
# and KOBJECT_HASH_COMPILE_OPTIONS contains all the options.
1304+
set_target_properties(kobj_prebuilt_hash_output_lib PROPERTIES
1305+
COMPILE_OPTIONS "${KOBJECT_HASH_COMPILE_OPTIONS}"
1306+
)
12961307

12971308
target_compile_definitions(kobj_prebuilt_hash_output_lib
12981309
PRIVATE $<TARGET_PROPERTY:zephyr_interface,INTERFACE_COMPILE_DEFINITIONS>
@@ -1500,9 +1511,9 @@ if(CONFIG_USERSPACE)
15001511
OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_HASH_OUTPUT_SRC}
15011512
)
15021513

1503-
set_source_files_properties(${KOBJECT_HASH_OUTPUT_SRC}
1504-
PROPERTIES COMPILE_FLAGS
1505-
"${NO_COVERAGE_FLAGS} -fno-function-sections -fno-data-sections")
1514+
set_target_properties(kobj_hash_output_lib PROPERTIES
1515+
COMPILE_OPTIONS "${KOBJECT_HASH_COMPILE_OPTIONS}"
1516+
)
15061517

15071518
target_compile_definitions(kobj_hash_output_lib
15081519
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
@@ -210,3 +210,9 @@ set_compiler_property(PROPERTY warning_shadow_variables)
210210

211211
set_compiler_property(PROPERTY no_builtin -fno-builtin)
212212
set_compiler_property(PROPERTY no_builtin_malloc -fno-builtin-malloc)
213+
214+
# Compiler flag for placing functions in their own sections:
215+
set_compiler_property(PROPERTY no_function_sections "-fno-function-sections")
216+
217+
# Compiler flag for placing variables in their own sections:
218+
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
@@ -149,3 +149,9 @@ set_compiler_property(PROPERTY specs)
149149

150150
# Compiler flag for defining preinclude files.
151151
set_compiler_property(PROPERTY include_file)
152+
153+
# Compiler flag for placing functions in their own sections:
154+
set_compiler_property(PROPERTY no_function_sections)
155+
156+
# Compiler flag for placing variables in their own sections:
157+
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
@@ -253,3 +253,9 @@ set_compiler_property(PROPERTY no_builtin_malloc -fno-builtin-malloc)
253253
set_compiler_property(PROPERTY specs -specs=)
254254

255255
set_compiler_property(PROPERTY include_file -include)
256+
257+
# Compiler flag for placing functions in their own sections:
258+
set_compiler_property(PROPERTY no_function_sections "-fno-function-sections")
259+
260+
# Compiler flag for placing variables in their own sections:
261+
set_compiler_property(PROPERTY no_data_sections "-fno-data-sections")

0 commit comments

Comments
 (0)