cmake: using ${ZEPHYR_BASE} instead of $ENV{ZEPHYR_BASE}

With the introduction of ZephyrConfig.cmake all parts of CMake code
should rely on the CMake ZEPHYR_BASE variable instead of the environment
setting.

This ensures that after the first CMake invocation, then all subsequent
invocation in same build folder will use same zephyr base.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
Torsten Rasmussen 2020-02-12 15:42:09 +01:00 committed by Carles Cufí
commit d7862cf776
15 changed files with 60 additions and 35 deletions

View file

@ -637,7 +637,7 @@ add_custom_command(
) )
add_custom_target(${DRIVER_VALIDATION_H_TARGET} DEPENDS ${DRV_VALIDATION}) add_custom_target(${DRIVER_VALIDATION_H_TARGET} DEPENDS ${DRV_VALIDATION})
include($ENV{ZEPHYR_BASE}/cmake/kobj.cmake) include(${ZEPHYR_BASE}/cmake/kobj.cmake)
gen_kobj(KOBJ_INCLUDE_PATH) gen_kobj(KOBJ_INCLUDE_PATH)
# Add a pseudo-target that is up-to-date when all generated headers # Add a pseudo-target that is up-to-date when all generated headers

View file

@ -4,7 +4,7 @@
# Zephyr applications, e.g. zephyr/samples/hello_world/CMakeLists.txt # Zephyr applications, e.g. zephyr/samples/hello_world/CMakeLists.txt
# must start with the line: # must start with the line:
# #
# include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) # include(${ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
# #
# It exists to reduce boilerplate code that Zephyr expects to be in # It exists to reduce boilerplate code that Zephyr expects to be in
# application CMakeLists.txt code. # application CMakeLists.txt code.
@ -75,12 +75,16 @@ add_custom_target(code_data_relocation_target)
# It is recommended to always use ZEPHYR_BASE instead of PROJECT_SOURCE_DIR # It is recommended to always use ZEPHYR_BASE instead of PROJECT_SOURCE_DIR
# when trying to reference ENV${ZEPHYR_BASE}. # when trying to reference ENV${ZEPHYR_BASE}.
set(ENV_ZEPHYR_BASE $ENV{ZEPHYR_BASE})
# This add support for old style boilerplate include.
if((NOT DEFINED ZEPHYR_BASE) AND (DEFINED ENV_ZEPHYR_BASE))
set(ZEPHYR_BASE ${ENV_ZEPHYR_BASE} CACHE PATH "Zephyr base")
endif()
# Note any later project() resets PROJECT_SOURCE_DIR # Note any later project() resets PROJECT_SOURCE_DIR
file(TO_CMAKE_PATH "$ENV{ZEPHYR_BASE}" PROJECT_SOURCE_DIR) file(TO_CMAKE_PATH "${ZEPHYR_BASE}" PROJECT_SOURCE_DIR)
set(ZEPHYR_BINARY_DIR ${PROJECT_BINARY_DIR}) set(ZEPHYR_BINARY_DIR ${PROJECT_BINARY_DIR})
set(ZEPHYR_BASE ${PROJECT_SOURCE_DIR})
set(ENV{ZEPHYR_BASE} ${ZEPHYR_BASE})
set(AUTOCONF_H ${__build_dir}/include/generated/autoconf.h) set(AUTOCONF_H ${__build_dir}/include/generated/autoconf.h)
# Re-configure (Re-execute all CMakeLists.txt code) when autoconf.h changes # Re-configure (Re-execute all CMakeLists.txt code) when autoconf.h changes

View file

@ -3,13 +3,13 @@
# List all architectures, export the list in list_var # List all architectures, export the list in list_var
function(list_archs list_var) function(list_archs list_var)
FILE(GLOB arch_contents RELATIVE $ENV{ZEPHYR_BASE}/arch $ENV{ZEPHYR_BASE}/arch/*) FILE(GLOB arch_contents RELATIVE ${ZEPHYR_BASE}/arch ${ZEPHYR_BASE}/arch/*)
set(_arch_list) set(_arch_list)
foreach(f ${arch_contents}) foreach(f ${arch_contents})
if ("${f}" STREQUAL "common") if ("${f}" STREQUAL "common")
continue() continue()
endif() endif()
if (IS_DIRECTORY "$ENV{ZEPHYR_BASE}/arch/${f}") if (IS_DIRECTORY "${ZEPHYR_BASE}/arch/${f}")
list(APPEND _arch_list "${f}") list(APPEND _arch_list "${f}")
endif() endif()
endforeach() endforeach()
@ -98,7 +98,7 @@ if(CMAKE_SCRIPT_MODE_FILE AND NOT CMAKE_PARENT_LIST_FILE)
# BOARD_ROOT_SPACE_SEPARATED: Space-separated board roots # BOARD_ROOT_SPACE_SEPARATED: Space-separated board roots
# FILE_OUT: Set to a file path to save the boards to a file. If not defined the # FILE_OUT: Set to a file path to save the boards to a file. If not defined the
# the contents will be printed to stdout # the contents will be printed to stdout
if(NOT DEFINED ENV{ZEPHYR_BASE}) if(NOT DEFINED ZEPHYR_BASE)
message(FATAL_ERROR "ZEPHYR_BASE not set") message(FATAL_ERROR "ZEPHYR_BASE not set")
endif() endif()

View file

@ -13,6 +13,7 @@ function(generate_cfb_font
COMMAND COMMAND
${PYTHON_EXECUTABLE} ${PYTHON_EXECUTABLE}
${ZEPHYR_BASE}/scripts/gen_cfb_font_header.py ${ZEPHYR_BASE}/scripts/gen_cfb_font_header.py
--zephyr-base ${ZEPHYR_BASE}
--input ${input_file} --input ${input_file}
--output ${output_file} --output ${output_file}
--bindir ${CMAKE_BINARY_DIR} --bindir ${CMAKE_BINARY_DIR}

View file

@ -167,7 +167,7 @@ if(DEFINED ENV{WEST_DIR} AND NOT WEST_DIR)
endif(DEFINED ENV{WEST_DIR} AND NOT WEST_DIR) endif(DEFINED ENV{WEST_DIR} AND NOT WEST_DIR)
if(WEST_DIR) if(WEST_DIR)
set(WEST "PYTHONPATH=${WEST_DIR}/src" "${PYTHON_EXECUTABLE};${WEST_DIR}/src/west/app/main.py;--zephyr-base=$ENV{ZEPHYR_BASE} ") set(WEST "PYTHONPATH=${WEST_DIR}/src" "${PYTHON_EXECUTABLE};${WEST_DIR}/src/west/app/main.py;--zephyr-base=${ZEPHYR_BASE} ")
endif() endif()
# Generate the flash, debug, debugserver, attach targets within the build # Generate the flash, debug, debugserver, attach targets within the build
@ -207,7 +207,6 @@ foreach(target flash debug debugserver attach)
${target} ${target}
--skip-rebuild --skip-rebuild
DEPENDS ${FLASH_DEPS} DEPENDS ${FLASH_DEPS}
$<TARGET_PROPERTY:zephyr_property_target,FLASH_DEPENDENCIES>
WORKING_DIRECTORY ${APPLICATION_BINARY_DIR} WORKING_DIRECTORY ${APPLICATION_BINARY_DIR}
) )

View file

@ -201,6 +201,7 @@ execute_process(
COMMAND COMMAND
${PYTHON_EXECUTABLE} ${PYTHON_EXECUTABLE}
${ZEPHYR_BASE}/scripts/kconfig/kconfig.py ${ZEPHYR_BASE}/scripts/kconfig/kconfig.py
--zephyr-base=${ZEPHYR_BASE}
${input_configs_are_handwritten} ${input_configs_are_handwritten}
${KCONFIG_ROOT} ${KCONFIG_ROOT}
${DOTCONFIG} ${DOTCONFIG}

View file

@ -17,14 +17,14 @@ function(gen_kobj gen_dir_out)
OUTPUT ${KOBJ_TYPES} ${KOBJ_OTYPE} OUTPUT ${KOBJ_TYPES} ${KOBJ_OTYPE}
COMMAND COMMAND
${PYTHON_EXECUTABLE} ${PYTHON_EXECUTABLE}
$ENV{ZEPHYR_BASE}/scripts/gen_kobject_list.py ${ZEPHYR_BASE}/scripts/gen_kobject_list.py
--kobj-types-output ${KOBJ_TYPES} --kobj-types-output ${KOBJ_TYPES}
--kobj-otype-output ${KOBJ_OTYPE} --kobj-otype-output ${KOBJ_OTYPE}
--kobj-size-output ${KOBJ_SIZE} --kobj-size-output ${KOBJ_SIZE}
${gen_kobject_list_include_args} ${gen_kobject_list_include_args}
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose> $<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
DEPENDS DEPENDS
$ENV{ZEPHYR_BASE}/scripts/gen_kobject_list.py ${ZEPHYR_BASE}/scripts/gen_kobject_list.py
${PARSE_SYSCALLS_TARGET} ${PARSE_SYSCALLS_TARGET}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
) )

View file

@ -4,18 +4,18 @@
macro(toolchain_ld_configure_files) macro(toolchain_ld_configure_files)
configure_file( configure_file(
$ENV{ZEPHYR_BASE}/include/arch/common/app_data_alignment.ld ${ZEPHYR_BASE}/include/arch/common/app_data_alignment.ld
${PROJECT_BINARY_DIR}/include/generated/app_data_alignment.ld) ${PROJECT_BINARY_DIR}/include/generated/app_data_alignment.ld)
configure_file( configure_file(
$ENV{ZEPHYR_BASE}/include/linker/app_smem.ld ${ZEPHYR_BASE}/include/linker/app_smem.ld
${PROJECT_BINARY_DIR}/include/generated/app_smem.ld) ${PROJECT_BINARY_DIR}/include/generated/app_smem.ld)
configure_file( configure_file(
$ENV{ZEPHYR_BASE}/include/linker/app_smem_aligned.ld ${ZEPHYR_BASE}/include/linker/app_smem_aligned.ld
${PROJECT_BINARY_DIR}/include/generated/app_smem_aligned.ld) ${PROJECT_BINARY_DIR}/include/generated/app_smem_aligned.ld)
configure_file( configure_file(
$ENV{ZEPHYR_BASE}/include/linker/app_smem_unaligned.ld ${ZEPHYR_BASE}/include/linker/app_smem_unaligned.ld
${PROJECT_BINARY_DIR}/include/generated/app_smem_unaligned.ld) ${PROJECT_BINARY_DIR}/include/generated/app_smem_unaligned.ld)
endmacro() endmacro()

View file

@ -3,6 +3,9 @@
cmake_minimum_required(VERSION 3.13.1) cmake_minimum_required(VERSION 3.13.1)
project(Zephyr-Kernel-Doc LANGUAGES) project(Zephyr-Kernel-Doc LANGUAGES)
set(NO_BOILERPLATE TRUE)
find_package(Zephyr HINTS $ENV{ZEPHYR_BASE} ..)
# Find west to (optionally) process modules for Kconfig # Find west to (optionally) process modules for Kconfig
find_program( find_program(
WEST WEST
@ -12,7 +15,7 @@ if(${WEST} STREQUAL WEST-NOTFOUND)
unset(WEST) unset(WEST)
endif() endif()
file(TO_CMAKE_PATH "$ENV{ZEPHYR_BASE}" ZEPHYR_BASE) file(TO_CMAKE_PATH "${ZEPHYR_BASE}" ZEPHYR_BASE)
message(STATUS "Zephyr base: ${ZEPHYR_BASE}") message(STATUS "Zephyr base: ${ZEPHYR_BASE}")
if(DEFINED WEST) if(DEFINED WEST)

View file

@ -3,7 +3,7 @@
if(CONFIG_WIFI_SIMPLELINK) if(CONFIG_WIFI_SIMPLELINK)
zephyr_include_directories( zephyr_include_directories(
. .
$ENV{ZEPHYR_BASE}/subsys/net/lib/tls_credentials ${ZEPHYR_BASE}/subsys/net/lib/tls_credentials
) )
zephyr_sources( zephyr_sources(
simplelink_support.c simplelink_support.c

View file

@ -5,7 +5,6 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import argparse import argparse
import os
import sys import sys
from PIL import ImageFont from PIL import ImageFont
@ -96,8 +95,6 @@ def extract_image_glyphs():
def generate_header(): def generate_header():
"""Generate CFB font header file""" """Generate CFB font header file"""
zephyr_base = os.environ.get('ZEPHYR_BASE', "")
clean_cmd = [] clean_cmd = []
for arg in sys.argv: for arg in sys.argv:
if arg.startswith("--bindir"): if arg.startswith("--bindir"):
@ -109,7 +106,11 @@ def generate_header():
clean_cmd.append(arg[striplen:]) clean_cmd.append(arg[striplen:])
continue continue
clean_cmd.append(arg.replace(zephyr_base, '"${ZEPHYR_BASE}"')) if args.zephyr_base is not None:
clean_cmd.append(arg.replace(args.zephyr_base, '"${ZEPHYR_BASE}"'))
else:
clean_cmd.append(arg)
args.output.write("""/* args.output.write("""/*
* This file was automatically generated using the following command: * This file was automatically generated using the following command:
@ -158,6 +159,10 @@ def parse_args():
description="Character Frame Buffer (CFB) font header file generator", description="Character Frame Buffer (CFB) font header file generator",
formatter_class=argparse.RawDescriptionHelpFormatter) formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument(
"-z", "--zephyr-base",
help="Zephyr base directory")
parser.add_argument( parser.add_argument(
"-d", "--dump", action="store_true", "-d", "--dump", action="store_true",
help="dump generated CFB font elements as images for preview") help="dump generated CFB font elements as images for preview")

View file

@ -23,6 +23,9 @@ from kconfiglib import Kconfig, split_expr, expr_value, expr_str, BOOL, \
def main(): def main():
args = parse_args() args = parse_args()
if args.zephyr_base:
os.environ['ZEPHYR_BASE'] = args.zephyr_base
print("Parsing " + args.kconfig_file) print("Parsing " + args.kconfig_file)
kconf = Kconfig(args.kconfig_file, warn_to_stderr=False, kconf = Kconfig(args.kconfig_file, warn_to_stderr=False,
suppress_traceback=True) suppress_traceback=True)
@ -118,8 +121,8 @@ def check_assigned_sym_values(kconf):
user_value = TRI_TO_STR[user_value] user_value = TRI_TO_STR[user_value]
if user_value != sym.str_value: if user_value != sym.str_value:
msg = f"{sym.name_and_loc} was assigned the value '{user_value}' " \ msg = f"{sym.name_and_loc} was assigned the value '{user_value}'" \
f"but got the value '{sym.str_value}'. " f" but got the value '{sym.str_value}'. "
# List any unsatisfied 'depends on' dependencies in the warning # List any unsatisfied 'depends on' dependencies in the warning
mdeps = missing_deps(sym) mdeps = missing_deps(sym)
@ -132,7 +135,8 @@ def check_assigned_sym_values(kconf):
# Gives '(FOO || BAR) (=n)' instead of # Gives '(FOO || BAR) (=n)' instead of
# 'FOO || BAR (=n)', which might be clearer. # 'FOO || BAR (=n)', which might be clearer.
estr = f"({estr})" estr = f"({estr})"
expr_strs.append(f"{estr} (={TRI_TO_STR[expr_value(expr)]})") expr_strs.append(f"{estr} "
f"(={TRI_TO_STR[expr_value(expr)]})")
msg += "Check these unsatisfied dependencies: " + \ msg += "Check these unsatisfied dependencies: " + \
", ".join(expr_strs) + ". " ", ".join(expr_strs) + ". "
@ -171,9 +175,9 @@ def check_assigned_choice_values(kconf):
# #
# We check choice symbols separately to avoid warnings when two different # We check choice symbols separately to avoid warnings when two different
# choice symbols within the same choice are set to y. This might happen if # choice symbols within the same choice are set to y. This might happen if
# a choice selection from a board defconfig is overridden in a prj.conf, for # a choice selection from a board defconfig is overridden in a prj.conf,
# example. The last choice symbol set to y becomes the selection (and all # for example. The last choice symbol set to y becomes the selection (and
# other choice symbols get the value n). # all other choice symbols get the value n).
# #
# Without special-casing choices, we'd detect that the first symbol set to # Without special-casing choices, we'd detect that the first symbol set to
# y ended up as n, and print a spurious warning. # y ended up as n, and print a spurious warning.
@ -226,6 +230,8 @@ def parse_args():
"handwritten fragments and do additional checks " "handwritten fragments and do additional checks "
"on them, like no promptless symbols being " "on them, like no promptless symbols being "
"assigned") "assigned")
parser.add_argument("--zephyr-base",
help="Path to current Zephyr installation")
parser.add_argument("kconfig_file", parser.add_argument("kconfig_file",
help="Top-level Kconfig file") help="Top-level Kconfig file")
parser.add_argument("config_out", parser.add_argument("config_out",

View file

@ -3,6 +3,6 @@
add_subdirectory_if_kconfig(ztest) add_subdirectory_if_kconfig(ztest)
zephyr_include_directories_ifdef(CONFIG_TEST zephyr_include_directories_ifdef(CONFIG_TEST
$ENV{ZEPHYR_BASE}/subsys/testsuite/include ${ZEPHYR_BASE}/subsys/testsuite/include
) )
add_subdirectory_ifdef(CONFIG_COVERAGE_GCOV coverage) add_subdirectory_ifdef(CONFIG_COVERAGE_GCOV coverage)

View file

@ -16,6 +16,12 @@ separate_arguments(EXTRA_CPPFLAGS_AS_LIST UNIX_COMMAND ${EXTRA_CPPFLAGS})
separate_arguments(EXTRA_CXXFLAGS_AS_LIST UNIX_COMMAND ${EXTRA_CXXFLAGS}) separate_arguments(EXTRA_CXXFLAGS_AS_LIST UNIX_COMMAND ${EXTRA_CXXFLAGS})
separate_arguments(EXTRA_LDFLAGS_AS_LIST UNIX_COMMAND ${EXTRA_LDFLAGS}) separate_arguments(EXTRA_LDFLAGS_AS_LIST UNIX_COMMAND ${EXTRA_LDFLAGS})
set(ENV_ZEPHYR_BASE $ENV{ZEPHYR_BASE})
# This add support for old style boilerplate include.
if((NOT DEFINED ZEPHYR_BASE) AND (DEFINED ENV_ZEPHYR_BASE))
set(ZEPHYR_BASE ${ENV_ZEPHYR_BASE} CACHE PATH "Zephyr base")
endif()
if(NOT SOURCES) if(NOT SOURCES)
set(SOURCES main.c) set(SOURCES main.c)
endif() endif()
@ -23,7 +29,7 @@ endif()
add_executable(testbinary ${SOURCES}) add_executable(testbinary ${SOURCES})
set(KOBJ_TYPES_H_TARGET kobj_types_h_target) set(KOBJ_TYPES_H_TARGET kobj_types_h_target)
include($ENV{ZEPHYR_BASE}/cmake/kobj.cmake) include(${ZEPHYR_BASE}/cmake/kobj.cmake)
add_dependencies(testbinary ${KOBJ_TYPES_H_TARGET}) add_dependencies(testbinary ${KOBJ_TYPES_H_TARGET})
gen_kobj(KOBJ_GEN_DIR) gen_kobj(KOBJ_GEN_DIR)
@ -72,14 +78,14 @@ if(LIBS)
endif() endif()
target_sources(testbinary PRIVATE target_sources(testbinary PRIVATE
$ENV{ZEPHYR_BASE}/subsys/testsuite/ztest/src/ztest.c ${ZEPHYR_BASE}/subsys/testsuite/ztest/src/ztest.c
$ENV{ZEPHYR_BASE}/subsys/testsuite/ztest/src/ztest_mock.c ${ZEPHYR_BASE}/subsys/testsuite/ztest/src/ztest_mock.c
) )
target_compile_definitions(testbinary PRIVATE ZTEST_UNITTEST) target_compile_definitions(testbinary PRIVATE ZTEST_UNITTEST)
foreach(inc ${INCLUDE}) foreach(inc ${INCLUDE})
target_include_directories(testbinary PRIVATE $ENV{ZEPHYR_BASE}/${inc}) target_include_directories(testbinary PRIVATE ${ZEPHYR_BASE}/${inc})
endforeach() endforeach()
find_program(VALGRIND_PROGRAM valgrind) find_program(VALGRIND_PROGRAM valgrind)

View file

@ -1,8 +1,8 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
zephyr_include_directories( zephyr_include_directories(
$ENV{ZEPHYR_BASE}/subsys/testsuite/include ${ZEPHYR_BASE}/subsys/testsuite/include
$ENV{ZEPHYR_BASE}/subsys/testsuite/ztest/include ${ZEPHYR_BASE}/subsys/testsuite/ztest/include
) )
zephyr_library() zephyr_library()