cmake: Use a variable for 'zephyr_prebuilt'

There is an effort underway to make most of the Zephyr build script's
reentrant. Meaning, the build scripts can be executed multiple times
during the same CMake invocation.

Reentrancy enables several use-cases, the motivating one is the
ability to build several Zephyr executables, or images, for instance a
bootloader and an application.

For build scripts to be reentrant they cannot be directly referencing
global variables, like target names, but must instead reference
variables, which can vary from entry to entry.

Therefore, in this patch, we replace global targets with variables.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
This commit is contained in:
Sebastian Bøe 2019-01-14 16:31:02 +01:00 committed by Anas Nashif
commit 1526070082
4 changed files with 36 additions and 34 deletions

View file

@ -28,6 +28,7 @@ check_c_compiler_flag("" toolchain_is_ok)
assert(toolchain_is_ok "The toolchain is unable to build a dummy C file. See CMakeError.log.") assert(toolchain_is_ok "The toolchain is unable to build a dummy C file. See CMakeError.log.")
set(CMAKE_EXECUTABLE_SUFFIX .elf) set(CMAKE_EXECUTABLE_SUFFIX .elf)
set(ZEPHYR_PREBUILT_EXECUTABLE zephyr_prebuilt)
if(NOT PROPERTY_LINKER_SCRIPT_DEFINES) if(NOT PROPERTY_LINKER_SCRIPT_DEFINES)
set_property(GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES -D__GCC_LINKER_CMD__) set_property(GLOBAL PROPERTY PROPERTY_LINKER_SCRIPT_DEFINES -D__GCC_LINKER_CMD__)
@ -841,7 +842,7 @@ if(CONFIG_GEN_ISR_TABLES)
list(APPEND GEN_ISR_TABLE_EXTRA_ARG --vector-table) list(APPEND GEN_ISR_TABLE_EXTRA_ARG --vector-table)
endif() endif()
# isr_tables.c is generated from zephyr_prebuilt by # isr_tables.c is generated from ${ZEPHYR_PREBUILT_EXECUTABLE} by
# gen_isr_tables.py # gen_isr_tables.py
add_custom_command( add_custom_command(
OUTPUT isr_tables.c OUTPUT isr_tables.c
@ -849,17 +850,17 @@ if(CONFIG_GEN_ISR_TABLES)
-I ${OUTPUT_FORMAT} -I ${OUTPUT_FORMAT}
-O binary -O binary
--only-section=.intList --only-section=.intList
$<TARGET_FILE:zephyr_prebuilt> $<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}>
isrList.bin isrList.bin
COMMAND ${PYTHON_EXECUTABLE} COMMAND ${PYTHON_EXECUTABLE}
${ZEPHYR_BASE}/arch/common/gen_isr_tables.py ${ZEPHYR_BASE}/arch/common/gen_isr_tables.py
--output-source isr_tables.c --output-source isr_tables.c
--kernel $<TARGET_FILE:zephyr_prebuilt> --kernel $<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}>
--intlist isrList.bin --intlist isrList.bin
$<$<BOOL:${CONFIG_BIG_ENDIAN}>:--big-endian> $<$<BOOL:${CONFIG_BIG_ENDIAN}>:--big-endian>
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--debug> $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--debug>
${GEN_ISR_TABLE_EXTRA_ARG} ${GEN_ISR_TABLE_EXTRA_ARG}
DEPENDS zephyr_prebuilt DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE}
) )
set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_SOURCE_FILES isr_tables.c) set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_SOURCE_FILES isr_tables.c)
endif() endif()
@ -921,7 +922,7 @@ if(CONFIG_ARM AND CONFIG_USERSPACE)
# elf file. # elf file.
# Use the script GEN_PRIV_STACKS to scan the kernel binary's # Use the script GEN_PRIV_STACKS to scan the kernel binary's
# (zephyr_prebuilt) DWARF information to produce a table of kernel # (${ZEPHYR_PREBUILT_EXECUTABLE}) DWARF information to produce a table of kernel
# objects (PRIV_STACKS) which we will then pass to gperf # objects (PRIV_STACKS) which we will then pass to gperf
add_custom_command( add_custom_command(
OUTPUT ${PRIV_STACKS} OUTPUT ${PRIV_STACKS}
@ -1040,17 +1041,17 @@ if(CONFIG_USERSPACE)
# elf file. # elf file.
# Use the script GEN_KOBJ_LIST to scan the kernel binary's # Use the script GEN_KOBJ_LIST to scan the kernel binary's
# (zephyr_prebuilt) DWARF information to produce a table of kernel # (${ZEPHYR_PREBUILT_EXECUTABLE}) DWARF information to produce a table of kernel
# objects (OBJ_LIST) which we will then pass to gperf # objects (OBJ_LIST) which we will then pass to gperf
add_custom_command( add_custom_command(
OUTPUT ${OBJ_LIST} OUTPUT ${OBJ_LIST}
COMMAND COMMAND
${PYTHON_EXECUTABLE} ${PYTHON_EXECUTABLE}
${GEN_KOBJ_LIST} ${GEN_KOBJ_LIST}
--kernel $<TARGET_FILE:zephyr_prebuilt> --kernel $<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}>
--gperf-output ${OBJ_LIST} --gperf-output ${OBJ_LIST}
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
DEPENDS zephyr_prebuilt DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
) )
add_custom_target(obj_list DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OBJ_LIST}) add_custom_target(obj_list DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OBJ_LIST})
@ -1262,10 +1263,10 @@ endif()
endif() endif()
# FIXME: Is there any way to get rid of empty_file.c? # FIXME: Is there any way to get rid of empty_file.c?
add_executable( zephyr_prebuilt misc/empty_file.c) add_executable( ${ZEPHYR_PREBUILT_EXECUTABLE} misc/empty_file.c)
target_link_libraries(zephyr_prebuilt ${TOPT} ${PROJECT_BINARY_DIR}/linker.cmd ${PRIV_STACK_LIB} ${zephyr_lnk} ${CODE_RELOCATION_DEP}) target_link_libraries(${ZEPHYR_PREBUILT_EXECUTABLE} ${TOPT} ${PROJECT_BINARY_DIR}/linker.cmd ${PRIV_STACK_LIB} ${zephyr_lnk} ${CODE_RELOCATION_DEP})
set_property(TARGET zephyr_prebuilt PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker.cmd) set_property(TARGET ${ZEPHYR_PREBUILT_EXECUTABLE} PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker.cmd)
add_dependencies( zephyr_prebuilt ${ALIGN_SIZING_DEP} ${PRIV_STACK_DEP} linker_script offsets) add_dependencies( ${ZEPHYR_PREBUILT_EXECUTABLE} ${ALIGN_SIZING_DEP} ${PRIV_STACK_DEP} linker_script offsets)
if(GKOF OR GKSF) if(GKOF OR GKSF)
@ -1284,7 +1285,7 @@ if(GKOF OR GKSF)
DEPENDS DEPENDS
${ALIGN_SIZING_DEP} ${PRIV_STACK_DEP} ${ALIGN_SIZING_DEP} ${PRIV_STACK_DEP}
${CODE_RELOCATION_DEP} ${CODE_RELOCATION_DEP}
zephyr_prebuilt ${ZEPHYR_PREBUILT_EXECUTABLE}
linker_pass_final.cmd linker_pass_final.cmd
offsets_h offsets_h
) )
@ -1299,7 +1300,7 @@ if(GKOF OR GKSF)
set_property(TARGET kernel_elf PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker_pass_final.cmd) set_property(TARGET kernel_elf PROPERTY LINK_DEPENDS ${PROJECT_BINARY_DIR}/linker_pass_final.cmd)
add_dependencies( kernel_elf ${ALIGN_SIZING_DEP} ${PRIV_STACK_DEP} linker_pass_final_script) add_dependencies( kernel_elf ${ALIGN_SIZING_DEP} ${PRIV_STACK_DEP} linker_pass_final_script)
else() else()
set(logical_target_for_zephyr_elf zephyr_prebuilt) set(logical_target_for_zephyr_elf ${ZEPHYR_PREBUILT_EXECUTABLE})
# Use the prebuilt elf as the final elf since we don't have a # Use the prebuilt elf as the final elf since we don't have a
# generation stage. # generation stage.
endif() endif()
@ -1410,7 +1411,7 @@ if(CONFIG_OUTPUT_PRINT_MEMORY_USAGE)
zephyr_check_compiler_flag(C "" ${check}) zephyr_check_compiler_flag(C "" ${check})
set(CMAKE_REQUIRED_FLAGS ${SAVED_CMAKE_REQUIRED_FLAGS}) set(CMAKE_REQUIRED_FLAGS ${SAVED_CMAKE_REQUIRED_FLAGS})
target_link_libraries_ifdef(${check} zephyr_prebuilt ${option}) target_link_libraries_ifdef(${check} ${ZEPHYR_PREBUILT_EXECUTABLE} ${option})
endif() endif()
if(EMU_PLATFORM) if(EMU_PLATFORM)

View file

@ -44,7 +44,7 @@ set(GENIDT ${ZEPHYR_BASE}/scripts/gen_idt.py)
define_property(GLOBAL PROPERTY PROPERTY_OUTPUT_ARCH BRIEF_DOCS " " FULL_DOCS " ") define_property(GLOBAL PROPERTY PROPERTY_OUTPUT_ARCH BRIEF_DOCS " " FULL_DOCS " ")
# Use gen_idt.py and objcopy to generate irq_int_vector_map.o, # Use gen_idt.py and objcopy to generate irq_int_vector_map.o,
# irq_vectors_alloc.o, and staticIdt.o from the elf file zephyr_prebuilt # irq_vectors_alloc.o, and staticIdt.o from the elf file ${ZEPHYR_PREBUILT_EXECUTABLE}
set(gen_idt_output_files set(gen_idt_output_files
${CMAKE_CURRENT_BINARY_DIR}/irq_int_vector_map.bin ${CMAKE_CURRENT_BINARY_DIR}/irq_int_vector_map.bin
${CMAKE_CURRENT_BINARY_DIR}/staticIdt.bin ${CMAKE_CURRENT_BINARY_DIR}/staticIdt.bin
@ -60,12 +60,12 @@ add_custom_command(
COMMAND COMMAND
${PYTHON_EXECUTABLE} ${PYTHON_EXECUTABLE}
${GENIDT} ${GENIDT}
--kernel $<TARGET_FILE:zephyr_prebuilt> --kernel $<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}>
--output-idt staticIdt.bin --output-idt staticIdt.bin
--vector-map irq_int_vector_map.bin --vector-map irq_int_vector_map.bin
--output-vectors-alloc irq_vectors_alloc.bin --output-vectors-alloc irq_vectors_alloc.bin
${GENIDT_EXTRA_ARGS} ${GENIDT_EXTRA_ARGS}
DEPENDS zephyr_prebuilt DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
) )
@ -137,10 +137,10 @@ set_property(GLOBAL APPEND PROPERTY GENERATED_KERNEL_OBJECT_FILES irq_vectors_al
if(CONFIG_X86_MMU) if(CONFIG_X86_MMU)
# Use gen_mmu.py and objcopy to generate mmu_tables.o from from the # Use gen_mmu.py and objcopy to generate mmu_tables.o from from the
# elf file zephyr_prebuilt, creating the temp files mmu_tables.bin # elf file ${ZEPHYR_PREBUILT_EXECUTABLE}, creating the temp files mmu_tables.bin
# and mmulist.bin along the way. # and mmulist.bin along the way.
# #
# zephyr_prebuilt.elf -> mmulist.bin -> mmu_tables.bin -> mmu_tables.o # ${ZEPHYR_PREBUILT_EXECUTABLE}.elf -> mmulist.bin -> mmu_tables.bin -> mmu_tables.o
add_custom_command( add_custom_command(
OUTPUT mmulist.bin OUTPUT mmulist.bin
COMMAND COMMAND
@ -148,9 +148,9 @@ if(CONFIG_X86_MMU)
-I ${OUTPUT_FORMAT} -I ${OUTPUT_FORMAT}
-O binary -O binary
-j mmulist -j mmulist
$<TARGET_FILE:zephyr_prebuilt> $<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}>
mmulist.bin mmulist.bin
DEPENDS zephyr_prebuilt DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
) )
add_custom_command( add_custom_command(
@ -159,12 +159,12 @@ if(CONFIG_X86_MMU)
${PYTHON_EXECUTABLE} ${PYTHON_EXECUTABLE}
${ZEPHYR_BASE}/scripts/gen_mmu_x86.py ${ZEPHYR_BASE}/scripts/gen_mmu_x86.py
-i mmulist.bin -i mmulist.bin
-k $<TARGET_FILE:zephyr_prebuilt> -k $<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}>
-o mmu_tables.bin -o mmu_tables.bin
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:-v> $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:-v>
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS mmulist.bin DEPENDS mmulist.bin
DEPENDS zephyr_prebuilt DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE}
) )
add_custom_command( add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/mmu_tables.o OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/mmu_tables.o
@ -189,19 +189,19 @@ endif()
if(CONFIG_GDT_DYNAMIC) if(CONFIG_GDT_DYNAMIC)
# Use gen_gdt.py and objcopy to generate gdt.o from from the elf # Use gen_gdt.py and objcopy to generate gdt.o from from the elf
# file zephyr_prebuilt, creating the temp file gdt.bin along the # file ${ZEPHYR_PREBUILT_EXECUTABLE}, creating the temp file gdt.bin along the
# way. # way.
# #
# zephyr_prebuilt.elf -> gdt.bin -> gdt.o # ${ZEPHYR_PREBUILT_EXECUTABLE}.elf -> gdt.bin -> gdt.o
add_custom_command( add_custom_command(
OUTPUT gdt.bin OUTPUT gdt.bin
COMMAND COMMAND
${PYTHON_EXECUTABLE} ${PYTHON_EXECUTABLE}
${ZEPHYR_BASE}/scripts/gen_gdt.py ${ZEPHYR_BASE}/scripts/gen_gdt.py
--kernel $<TARGET_FILE:zephyr_prebuilt> --kernel $<TARGET_FILE:${ZEPHYR_PREBUILT_EXECUTABLE}>
--output-gdt gdt.bin --output-gdt gdt.bin
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
DEPENDS zephyr_prebuilt DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
) )
add_custom_command( add_custom_command(

View file

@ -61,7 +61,7 @@ set(qkernel_file ${CMAKE_BINARY_DIR}/zephyr-qemu.elf)
add_custom_target(qemu_kernel_target DEPENDS ${qkernel_file}) add_custom_target(qemu_kernel_target DEPENDS ${qkernel_file})
add_custom_command( add_custom_command(
OUTPUT ${qkernel_file} OUTPUT ${qkernel_file}
DEPENDS zephyr_prebuilt DEPENDS ${ZEPHYR_PREBUILT_EXECUTABLE}
COMMAND ${CMAKE_OBJCOPY} -O binary ${CMAKE_BINARY_DIR}/zephyr/zephyr.elf ${CMAKE_CURRENT_BINARY_DIR}/zephyr-qemu.bin COMMAND ${CMAKE_OBJCOPY} -O binary ${CMAKE_BINARY_DIR}/zephyr/zephyr.elf ${CMAKE_CURRENT_BINARY_DIR}/zephyr-qemu.bin
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/qemuinc.c ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/qemuinc.c ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${CMAKE_C_COMPILER} -m32 -c ${CMAKE_CURRENT_BINARY_DIR}/qemuinc.c -o ${CMAKE_CURRENT_BINARY_DIR}/zephyr-qemu.o COMMAND ${CMAKE_C_COMPILER} -m32 -c ${CMAKE_CURRENT_BINARY_DIR}/qemuinc.c -o ${CMAKE_CURRENT_BINARY_DIR}/zephyr-qemu.o

View file

@ -308,8 +308,8 @@ struct _isr_list which is placed in a special .intList section:
}; };
Zephyr is built in two phases; the first phase of the build produces Zephyr is built in two phases; the first phase of the build produces
zephyr_prebuilt.elf which contains all the entries in the .intList section ``${ZEPHYR_PREBUILT_EXECUTABLE}``.elf which contains all the entries in
preceded by a header: the .intList section preceded by a header:
.. code-block:: c .. code-block:: c
@ -322,9 +322,10 @@ preceded by a header:
}; };
This data consisting of the header and instances of struct _isr_list inside This data consisting of the header and instances of struct _isr_list inside
zephyr_prebuilt.elf is then used by the gen_isr_tables.py script to generate a ``${ZEPHYR_PREBUILT_EXECUTABLE}``.elf is then used by the
C file defining a vector table and software ISR table that are then compiled gen_isr_tables.py script to generate a C file defining a vector table and
and linked into the final application. software ISR table that are then compiled and linked into the final
application.
The priority level of any interrupt is not encoded in these tables, instead The priority level of any interrupt is not encoded in these tables, instead
:c:macro:`IRQ_CONNECT` also has a runtime component which programs the desired :c:macro:`IRQ_CONNECT` also has a runtime component which programs the desired