From d7862cf77686e607fcce776df1da6a800315bac8 Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Wed, 12 Feb 2020 15:42:09 +0100 Subject: [PATCH] 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 --- CMakeLists.txt | 2 +- cmake/app/boilerplate.cmake | 12 ++++++++---- cmake/boards.cmake | 6 +++--- cmake/cfb.cmake | 1 + cmake/flash/CMakeLists.txt | 3 +-- cmake/kconfig.cmake | 1 + cmake/kobj.cmake | 4 ++-- cmake/linker/ld/target_configure.cmake | 8 ++++---- doc/CMakeLists.txt | 5 ++++- drivers/wifi/simplelink/CMakeLists.txt | 2 +- scripts/gen_cfb_font_header.py | 13 +++++++++---- scripts/kconfig/kconfig.py | 18 ++++++++++++------ subsys/testsuite/CMakeLists.txt | 2 +- subsys/testsuite/unittest.cmake | 14 ++++++++++---- subsys/testsuite/ztest/CMakeLists.txt | 4 ++-- 15 files changed, 60 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d23e48adb4..603abdfa925 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -637,7 +637,7 @@ add_custom_command( ) 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) # Add a pseudo-target that is up-to-date when all generated headers diff --git a/cmake/app/boilerplate.cmake b/cmake/app/boilerplate.cmake index 5ba526d901d..42229e4589c 100644 --- a/cmake/app/boilerplate.cmake +++ b/cmake/app/boilerplate.cmake @@ -4,7 +4,7 @@ # Zephyr applications, e.g. zephyr/samples/hello_world/CMakeLists.txt # 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 # 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 # 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 -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_BASE ${PROJECT_SOURCE_DIR}) -set(ENV{ZEPHYR_BASE} ${ZEPHYR_BASE}) set(AUTOCONF_H ${__build_dir}/include/generated/autoconf.h) # Re-configure (Re-execute all CMakeLists.txt code) when autoconf.h changes diff --git a/cmake/boards.cmake b/cmake/boards.cmake index ce97e9cc740..e93f4a1e662 100644 --- a/cmake/boards.cmake +++ b/cmake/boards.cmake @@ -3,13 +3,13 @@ # List all architectures, export the list in 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) foreach(f ${arch_contents}) if ("${f}" STREQUAL "common") continue() endif() - if (IS_DIRECTORY "$ENV{ZEPHYR_BASE}/arch/${f}") + if (IS_DIRECTORY "${ZEPHYR_BASE}/arch/${f}") list(APPEND _arch_list "${f}") endif() endforeach() @@ -98,7 +98,7 @@ if(CMAKE_SCRIPT_MODE_FILE AND NOT CMAKE_PARENT_LIST_FILE) # 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 # 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") endif() diff --git a/cmake/cfb.cmake b/cmake/cfb.cmake index b7995823b66..7b5ee61161f 100644 --- a/cmake/cfb.cmake +++ b/cmake/cfb.cmake @@ -13,6 +13,7 @@ function(generate_cfb_font COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/gen_cfb_font_header.py + --zephyr-base ${ZEPHYR_BASE} --input ${input_file} --output ${output_file} --bindir ${CMAKE_BINARY_DIR} diff --git a/cmake/flash/CMakeLists.txt b/cmake/flash/CMakeLists.txt index c49044b3649..bf297139fe7 100644 --- a/cmake/flash/CMakeLists.txt +++ b/cmake/flash/CMakeLists.txt @@ -167,7 +167,7 @@ if(DEFINED ENV{WEST_DIR} AND NOT WEST_DIR) endif(DEFINED ENV{WEST_DIR} AND NOT 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() # Generate the flash, debug, debugserver, attach targets within the build @@ -207,7 +207,6 @@ foreach(target flash debug debugserver attach) ${target} --skip-rebuild DEPENDS ${FLASH_DEPS} - $ WORKING_DIRECTORY ${APPLICATION_BINARY_DIR} ) diff --git a/cmake/kconfig.cmake b/cmake/kconfig.cmake index 9dc8342dc70..4465da520e6 100644 --- a/cmake/kconfig.cmake +++ b/cmake/kconfig.cmake @@ -201,6 +201,7 @@ execute_process( COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/kconfig/kconfig.py + --zephyr-base=${ZEPHYR_BASE} ${input_configs_are_handwritten} ${KCONFIG_ROOT} ${DOTCONFIG} diff --git a/cmake/kobj.cmake b/cmake/kobj.cmake index 66393373276..372f9bb0442 100644 --- a/cmake/kobj.cmake +++ b/cmake/kobj.cmake @@ -17,14 +17,14 @@ function(gen_kobj gen_dir_out) OUTPUT ${KOBJ_TYPES} ${KOBJ_OTYPE} COMMAND ${PYTHON_EXECUTABLE} - $ENV{ZEPHYR_BASE}/scripts/gen_kobject_list.py + ${ZEPHYR_BASE}/scripts/gen_kobject_list.py --kobj-types-output ${KOBJ_TYPES} --kobj-otype-output ${KOBJ_OTYPE} --kobj-size-output ${KOBJ_SIZE} ${gen_kobject_list_include_args} $<$:--verbose> DEPENDS - $ENV{ZEPHYR_BASE}/scripts/gen_kobject_list.py + ${ZEPHYR_BASE}/scripts/gen_kobject_list.py ${PARSE_SYSCALLS_TARGET} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) diff --git a/cmake/linker/ld/target_configure.cmake b/cmake/linker/ld/target_configure.cmake index 7d02fb5552f..e088c1ff24c 100644 --- a/cmake/linker/ld/target_configure.cmake +++ b/cmake/linker/ld/target_configure.cmake @@ -4,18 +4,18 @@ macro(toolchain_ld_configure_files) 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) 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) 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) 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) endmacro() diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 9cd0cff28d2..e9b39140888 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -3,6 +3,9 @@ cmake_minimum_required(VERSION 3.13.1) 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_program( WEST @@ -12,7 +15,7 @@ if(${WEST} STREQUAL WEST-NOTFOUND) unset(WEST) endif() -file(TO_CMAKE_PATH "$ENV{ZEPHYR_BASE}" ZEPHYR_BASE) +file(TO_CMAKE_PATH "${ZEPHYR_BASE}" ZEPHYR_BASE) message(STATUS "Zephyr base: ${ZEPHYR_BASE}") if(DEFINED WEST) diff --git a/drivers/wifi/simplelink/CMakeLists.txt b/drivers/wifi/simplelink/CMakeLists.txt index 59ef94cdd54..9ad0c9db333 100644 --- a/drivers/wifi/simplelink/CMakeLists.txt +++ b/drivers/wifi/simplelink/CMakeLists.txt @@ -3,7 +3,7 @@ if(CONFIG_WIFI_SIMPLELINK) zephyr_include_directories( . - $ENV{ZEPHYR_BASE}/subsys/net/lib/tls_credentials + ${ZEPHYR_BASE}/subsys/net/lib/tls_credentials ) zephyr_sources( simplelink_support.c diff --git a/scripts/gen_cfb_font_header.py b/scripts/gen_cfb_font_header.py index f24185caab1..4e743ec48ef 100755 --- a/scripts/gen_cfb_font_header.py +++ b/scripts/gen_cfb_font_header.py @@ -5,7 +5,6 @@ # SPDX-License-Identifier: Apache-2.0 import argparse -import os import sys from PIL import ImageFont @@ -96,8 +95,6 @@ def extract_image_glyphs(): def generate_header(): """Generate CFB font header file""" - zephyr_base = os.environ.get('ZEPHYR_BASE', "") - clean_cmd = [] for arg in sys.argv: if arg.startswith("--bindir"): @@ -109,7 +106,11 @@ def generate_header(): clean_cmd.append(arg[striplen:]) 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("""/* * 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", formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument( + "-z", "--zephyr-base", + help="Zephyr base directory") + parser.add_argument( "-d", "--dump", action="store_true", help="dump generated CFB font elements as images for preview") diff --git a/scripts/kconfig/kconfig.py b/scripts/kconfig/kconfig.py index e4ac8dcbda4..77aafc91f6f 100755 --- a/scripts/kconfig/kconfig.py +++ b/scripts/kconfig/kconfig.py @@ -23,6 +23,9 @@ from kconfiglib import Kconfig, split_expr, expr_value, expr_str, BOOL, \ def main(): args = parse_args() + if args.zephyr_base: + os.environ['ZEPHYR_BASE'] = args.zephyr_base + print("Parsing " + args.kconfig_file) kconf = Kconfig(args.kconfig_file, warn_to_stderr=False, suppress_traceback=True) @@ -118,8 +121,8 @@ def check_assigned_sym_values(kconf): user_value = TRI_TO_STR[user_value] if user_value != sym.str_value: - msg = f"{sym.name_and_loc} was assigned the value '{user_value}' " \ - f"but got the value '{sym.str_value}'. " + msg = f"{sym.name_and_loc} was assigned the value '{user_value}'" \ + f" but got the value '{sym.str_value}'. " # List any unsatisfied 'depends on' dependencies in the warning mdeps = missing_deps(sym) @@ -132,7 +135,8 @@ def check_assigned_sym_values(kconf): # Gives '(FOO || BAR) (=n)' instead of # 'FOO || BAR (=n)', which might be clearer. 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: " + \ ", ".join(expr_strs) + ". " @@ -171,9 +175,9 @@ def check_assigned_choice_values(kconf): # # 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 - # a choice selection from a board defconfig is overridden in a prj.conf, for - # example. The last choice symbol set to y becomes the selection (and all - # other choice symbols get the value n). + # a choice selection from a board defconfig is overridden in a prj.conf, + # for example. The last choice symbol set to y becomes the selection (and + # all other choice symbols get the value n). # # Without special-casing choices, we'd detect that the first symbol set to # y ended up as n, and print a spurious warning. @@ -226,6 +230,8 @@ def parse_args(): "handwritten fragments and do additional checks " "on them, like no promptless symbols being " "assigned") + parser.add_argument("--zephyr-base", + help="Path to current Zephyr installation") parser.add_argument("kconfig_file", help="Top-level Kconfig file") parser.add_argument("config_out", diff --git a/subsys/testsuite/CMakeLists.txt b/subsys/testsuite/CMakeLists.txt index 93a304c503f..86a04a0d5e3 100644 --- a/subsys/testsuite/CMakeLists.txt +++ b/subsys/testsuite/CMakeLists.txt @@ -3,6 +3,6 @@ add_subdirectory_if_kconfig(ztest) zephyr_include_directories_ifdef(CONFIG_TEST - $ENV{ZEPHYR_BASE}/subsys/testsuite/include + ${ZEPHYR_BASE}/subsys/testsuite/include ) add_subdirectory_ifdef(CONFIG_COVERAGE_GCOV coverage) diff --git a/subsys/testsuite/unittest.cmake b/subsys/testsuite/unittest.cmake index 64196d1654f..89cdd9da62d 100644 --- a/subsys/testsuite/unittest.cmake +++ b/subsys/testsuite/unittest.cmake @@ -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_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) set(SOURCES main.c) endif() @@ -23,7 +29,7 @@ endif() add_executable(testbinary ${SOURCES}) 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}) gen_kobj(KOBJ_GEN_DIR) @@ -72,14 +78,14 @@ if(LIBS) endif() target_sources(testbinary PRIVATE - $ENV{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.c + ${ZEPHYR_BASE}/subsys/testsuite/ztest/src/ztest_mock.c ) target_compile_definitions(testbinary PRIVATE ZTEST_UNITTEST) foreach(inc ${INCLUDE}) - target_include_directories(testbinary PRIVATE $ENV{ZEPHYR_BASE}/${inc}) + target_include_directories(testbinary PRIVATE ${ZEPHYR_BASE}/${inc}) endforeach() find_program(VALGRIND_PROGRAM valgrind) diff --git a/subsys/testsuite/ztest/CMakeLists.txt b/subsys/testsuite/ztest/CMakeLists.txt index 4a5459928dc..7a5cc862c24 100644 --- a/subsys/testsuite/ztest/CMakeLists.txt +++ b/subsys/testsuite/ztest/CMakeLists.txt @@ -1,8 +1,8 @@ # SPDX-License-Identifier: Apache-2.0 zephyr_include_directories( - $ENV{ZEPHYR_BASE}/subsys/testsuite/include - $ENV{ZEPHYR_BASE}/subsys/testsuite/ztest/include + ${ZEPHYR_BASE}/subsys/testsuite/include + ${ZEPHYR_BASE}/subsys/testsuite/ztest/include ) zephyr_library()