From b05d681621e4df7d1d7f8c8781512edda6bb1465 Mon Sep 17 00:00:00 2001 From: Kent McLeod Date: Sat, 19 Jun 2021 17:29:36 +1000 Subject: [PATCH] cmake: Add seL4Config.cmake include CMakeLists.txt seL4Config.cmake is responsible for generating a valid CMAKE_TOOLCHAIN_FILE and setting up platform config options at the start of the build. The CMAKE_TOOLCHAIN_FILE variable has to be set before the first cmake `project()` function is processed to take effect. Previously this file was required to be imported in a CMake script before the kernel's CMakeLists.txt could be processed. This prevented the main CMakeLists.txt file from being used without an additional configuration file: cmake -G Ninja -C ../configs/ARM_verified.cmake ../ Now it is possible to do: cmake -G Ninja -DKernelPlatform=imx6 -DKernelARMPlatform=sabre ../ This should make it easier to invoke CMake for building kernel configurations from other build environments. Because this file is now imported in the Kernel's CMakeLists.txt context, there is no longer a requirement to save all the intermediate settings into the cache and then read them out again. Signed-off-by: Kent McLeod --- CMakeLists.txt | 16 +----- config.cmake | 4 +- configs/ARM_HYP_verified.cmake | 1 - configs/ARM_MCS_verified.cmake | 1 - configs/ARM_verified.cmake | 1 - configs/RISCV64_MCS_verified.cmake | 1 - configs/RISCV64_verified.cmake | 1 - configs/X64_verified.cmake | 1 - configs/seL4Config.cmake | 85 ++++-------------------------- gcc.cmake | 6 +-- 10 files changed, 15 insertions(+), 102 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d377bec0c..574939609 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,8 @@ cmake_minimum_required(VERSION 3.8.2) include(CheckCCompilerFlag) + +include(${CMAKE_CURRENT_LIST_DIR}/configs/seL4Config.cmake) project(seL4 C ASM) # First find our helpers @@ -36,20 +38,6 @@ RequireTool(INVOCATION_ID_GEN_PATH invocation_header_gen.py) RequireTool(SYSCALL_ID_GEN_PATH syscall_header_gen.py) RequireTool(XMLLINT_PATH xmllint.sh) -set(c_sources "") -set(asm_sources "") -set(bf_declarations "") -foreach(file IN LISTS config_c_sources) - list(APPEND c_sources "${CMAKE_CURRENT_SOURCE_DIR}/${file}") -endforeach() -foreach(file IN LISTS config_asm_sources) - list(APPEND asm_sources "${CMAKE_CURRENT_SOURCE_DIR}/${file}") -endforeach() -foreach(file IN LISTS config_bf_declarations) - list(APPEND bf_declarations "${CMAKE_CURRENT_SOURCE_DIR}/${file}") -endforeach() -set(KernelDTSList "${config_KernelDTSList}") - # Process the configuration scripts include(config.cmake) diff --git a/config.cmake b/config.cmake index 82703076c..383698329 100644 --- a/config.cmake +++ b/config.cmake @@ -6,8 +6,6 @@ cmake_minimum_required(VERSION 3.7.2) -set(configure_string "${config_configure_string}") - config_option( KernelIsMCS KERNEL_MCS "Use the MCS kernel configuration, which is not verified." DEFAULT OFF @@ -49,7 +47,7 @@ set_property( ) # These options are now set in seL4Config.cmake -if(DEFINED CONFIGURE_MAX_IRQ) +if(DEFINED CALLED_declare_default_headers) # calculate the irq cnode size based on MAX_IRQ if("${KernelArch}" STREQUAL "riscv") set(MAX_IRQ "${CONFIGURE_PLIC_MAX_NUM_INT}") diff --git a/configs/ARM_HYP_verified.cmake b/configs/ARM_HYP_verified.cmake index 9538d3a40..19a8ea584 100755 --- a/configs/ARM_HYP_verified.cmake +++ b/configs/ARM_HYP_verified.cmake @@ -24,4 +24,3 @@ set(KernelNumDomains 16 CACHE STRING "") set(KernelMaxNumBootinfoUntypedCap 166 CACHE STRING "") set(KernelRootCNodeSizeBits 19 CACHE STRING "") set(KernelMaxNumBootinfoUntypedCaps 50 CACHE STRING "") -include(${CMAKE_CURRENT_LIST_DIR}/seL4Config.cmake) diff --git a/configs/ARM_MCS_verified.cmake b/configs/ARM_MCS_verified.cmake index 89ac01840..c0a62b524 100644 --- a/configs/ARM_MCS_verified.cmake +++ b/configs/ARM_MCS_verified.cmake @@ -23,4 +23,3 @@ set(KernelNumDomains 16 CACHE STRING "") set(KernelMaxNumBootinfoUntypedCap 166 CACHE STRING "") set(KernelIsMCS ON CACHE BOOL "") set(KernelStaticMaxPeriodUs "(60 * 60 * MS_IN_S * US_IN_MS)" CACHE STRING "") -include(${CMAKE_CURRENT_LIST_DIR}/seL4Config.cmake) diff --git a/configs/ARM_verified.cmake b/configs/ARM_verified.cmake index 574f38044..05103a5e3 100755 --- a/configs/ARM_verified.cmake +++ b/configs/ARM_verified.cmake @@ -21,4 +21,3 @@ set(KernelFastpath ON CACHE BOOL "") set(KernelPrinting OFF CACHE BOOL "") set(KernelNumDomains 16 CACHE STRING "") set(KernelMaxNumBootinfoUntypedCap 166 CACHE STRING "") -include(${CMAKE_CURRENT_LIST_DIR}/seL4Config.cmake) diff --git a/configs/RISCV64_MCS_verified.cmake b/configs/RISCV64_MCS_verified.cmake index 9889a45a6..cd06b12ab 100644 --- a/configs/RISCV64_MCS_verified.cmake +++ b/configs/RISCV64_MCS_verified.cmake @@ -28,4 +28,3 @@ set(KernelIsMCS ON CACHE BOOL "") set(KernelStaticMaxPeriodUs "(60 * 60 * MS_IN_S * US_IN_MS)" CACHE STRING "") set(KernelClzNoBuiltin ON CACHE BOOL "") set(KernelCtzNoBuiltin ON CACHE BOOL "") -include(${CMAKE_CURRENT_LIST_DIR}/seL4Config.cmake) diff --git a/configs/RISCV64_verified.cmake b/configs/RISCV64_verified.cmake index a1778b79e..ab0d21c51 100644 --- a/configs/RISCV64_verified.cmake +++ b/configs/RISCV64_verified.cmake @@ -26,4 +26,3 @@ set(KernelRootCNodeSizeBits 19 CACHE STRING "") set(KernelMaxNumBootinfoUntypedCaps 50 CACHE STRING "") set(KernelClzNoBuiltin ON CACHE BOOL "") set(KernelCtzNoBuiltin ON CACHE BOOL "") -include(${CMAKE_CURRENT_LIST_DIR}/seL4Config.cmake) diff --git a/configs/X64_verified.cmake b/configs/X64_verified.cmake index 195d40eba..c468a2356 100755 --- a/configs/X64_verified.cmake +++ b/configs/X64_verified.cmake @@ -24,4 +24,3 @@ set(KernelMaxNumBootinfoUntypedCap 166 CACHE STRING "") set(KernelRootCNodeSizeBits 19 CACHE STRING "") set(KernelMaxNumBootinfoUntypedCaps 50 CACHE STRING "") set(KernelFSGSBase "inst" CACHE STRING "") -include(${CMAKE_CURRENT_LIST_DIR}/seL4Config.cmake) diff --git a/configs/seL4Config.cmake b/configs/seL4Config.cmake index 2a4bae840..07b69ad97 100644 --- a/configs/seL4Config.cmake +++ b/configs/seL4Config.cmake @@ -11,6 +11,7 @@ set(configure_string "") set(c_sources "") set(asm_sources "") set(bf_declarations "") +set(KernelDTSList "") include(${CMAKE_CURRENT_LIST_DIR}/../tools/internal.cmake) include(${CMAKE_CURRENT_LIST_DIR}/../tools/helpers.cmake) @@ -108,51 +109,21 @@ macro(fallback_declare_seL4_arch_default default_arch) declare_seL4_arch(${default_arch}) endmacro() -unset(CONFIGURE_PLIC_MAX_NUM_INT CACHE) -unset(CONFIGURE_TIMER_FREQUENCY CACHE) -unset(CONFIGURE_MAX_IRQ CACHE) -unset(CONFIGURE_NUM_PPI CACHE) -unset(CONFIGURE_INTERRUPT_CONTROLLER CACHE) -unset(CONFIGURE_TIMER CACHE) -unset(CONFIGURE_SMMU CACHE) -unset(CONFIGURE_CLK_SHIFT CACHE) -unset(CONFIGURE_CLK_MAGIC CACHE) -unset(CONFIGURE_KERNEL_WCET CACHE) -unset(CONFIGURE_TIMER_PRECISION CACHE) -# CONFIGURE_MAX_CB and CONFIGURE_MAX_SID are related to the kernel SMMU on Arm. -unset(CONFIGURE_MAX_SID CACHE) -unset(CONFIGURE_MAX_CB CACHE) - # CLK_SHIFT and CLK_MAGIC are generated from tools/reciprocal.py # based on the TIMER_CLK_HZ to simulate division. # This could be moved to a cmake function # in future to build the values on the first build. Note the calculation # can take a long time though. -function(declare_default_headers) +macro(declare_default_headers) cmake_parse_arguments( - PARSE_ARGV - 0 CONFIGURE "" "TIMER_FREQUENCY;MAX_IRQ;NUM_PPI;PLIC_MAX_NUM_INT;INTERRUPT_CONTROLLER;TIMER;SMMU;CLK_SHIFT;CLK_MAGIC;KERNEL_WCET;TIMER_PRECISION;MAX_SID;MAX_CB" "" + ${ARGN} ) - set(CONFIGURE_TIMER_FREQUENCY "${CONFIGURE_TIMER_FREQUENCY}" CACHE INTERNAL "") - set(CONFIGURE_MAX_IRQ "${CONFIGURE_MAX_IRQ}" CACHE INTERNAL "") - set(CONFIGURE_NUM_PPI "${CONFIGURE_NUM_PPI}" CACHE INTERNAL "") - set(CONFIGURE_PLIC_MAX_NUM_INT "${CONFIGURE_PLIC_MAX_NUM_INT}" CACHE INTERNAL "") - set(CONFIGURE_INTERRUPT_CONTROLLER "${CONFIGURE_INTERRUPT_CONTROLLER}" CACHE INTERNAL "") - set(CONFIGURE_TIMER "${CONFIGURE_TIMER}" CACHE INTERNAL "") - set(CONFIGURE_SMMU "${CONFIGURE_SMMU}" CACHE INTERNAL "") - set(CONFIGURE_CLK_SHIFT "${CONFIGURE_CLK_SHIFT}" CACHE INTERNAL "") - set(CONFIGURE_CLK_MAGIC "${CONFIGURE_CLK_MAGIC}" CACHE INTERNAL "") - set(CONFIGURE_KERNEL_WCET "${CONFIGURE_KERNEL_WCET}" CACHE INTERNAL "") - if(DEFINED CONFIGURE_TIMER_PRECISION) - set(CONFIGURE_TIMER_PRECISION "${CONFIGURE_TIMER_PRECISION}" CACHE INTERNAL "") - endif() - set(CONFIGURE_MAX_SID "${CONFIGURE_MAX_SID}" CACHE INTERNAL "") - set(CONFIGURE_MAX_CB "${CONFIGURE_MAX_CB}" CACHE INTERNAL "") -endfunction() + set(CALLED_declare_default_headers 1) +endmacro() # For all of the common variables we set a default value here if they haven't # been set by a platform. @@ -186,7 +157,6 @@ unset(KernelArmCPU CACHE) unset(KernelArmArmV CACHE) # Blacklist platforms without MCS support -unset(KernelPlatformSupportsMCS CACHE) set(KernelPlatformSupportsMCS ON) file(GLOB result ${CMAKE_CURRENT_LIST_DIR}/../src/plat/*/config.cmake) @@ -215,7 +185,6 @@ config_set(KernelArchArmV7ve ARCH_ARM_V7VE "${KernelArchArmV7ve}") config_set(KernelArchArmV8a ARCH_ARM_V8A "${KernelArchArmV8a}") config_set(KernelArmSMMU ARM_SMMU "${KernelArmSMMU}") config_set(KernelAArch64SErrorIgnore AARCH64_SERROR_IGNORE "${KernelAArch64SErrorIgnore}") -set(KernelPlatformSupportsMCS "${KernelPlatformSupportsMCS}" CACHE INTERNAL "" FORCE) # Check for v7ve before v7a as v7ve is a superset and we want to set the # actual armv to that, but leave armv7a config enabled for anything that @@ -254,46 +223,6 @@ if(KernelArchARM) config_set(KernelArmMach ARM_MACH "${KernelArmMach}") endif() -set(config_configure_string ${configure_string} CACHE INTERNAL "") -set(config_c_sources "") -set(config_asm_sources "") -set(config_bf_declarations "") -foreach(file IN LISTS c_sources) - string( - REPLACE - "${CMAKE_CURRENT_SOURCE_DIR}/" - "" - file - "${file}" - ) - list(APPEND config_c_sources "${file}") -endforeach() -foreach(file IN LISTS asm_sources) - string( - REPLACE - "${CMAKE_CURRENT_SOURCE_DIR}/" - "" - file - "${file}" - ) - list(APPEND config_asm_sources "${file}") -endforeach() -foreach(file IN LISTS bf_declarations) - string( - REPLACE - "${CMAKE_CURRENT_SOURCE_DIR}/" - "" - file - "${file}" - ) - list(APPEND config_bf_declarations "${file}") -endforeach() - -set(config_c_sources ${config_c_sources} CACHE INTERNAL "") -set(config_asm_sources ${config_asm_sources} CACHE INTERNAL "") -set(config_bf_declarations ${config_bf_declarations} CACHE INTERNAL "") -set(config_KernelDTSList ${KernelDTSList} CACHE INTERNAL "") - if("${TRIPLE}" STREQUAL "") set(toolchain_file gcc.cmake) else() @@ -304,6 +233,10 @@ if( ("${CMAKE_TOOLCHAIN_FILE}" STREQUAL "") OR ("${CMAKE_TOOLCHAIN_FILE}" STREQUAL "${toolchain_outputfile}") ) + if(DEFINED CACHE{CROSS_COMPILER_PREFIX}) + set(cross_prefix $CACHE{CROSS_COMPILER_PREFIX}) + endif() + configure_file( "${CMAKE_CURRENT_LIST_DIR}/../${toolchain_file}" "${toolchain_outputfile}.temp" @ONLY ) diff --git a/gcc.cmake b/gcc.cmake index bc3d33a0f..606dad86d 100644 --- a/gcc.cmake +++ b/gcc.cmake @@ -19,16 +19,16 @@ set(CMAKE_STAGING_PREFIX "${CMAKE_BINARY_DIR}/staging") set(sel4_arch @KernelSel4Arch@) set(arch @KernelArch@) set(mode @KernelWordSize@) -set(cross_prefix @CROSS_COMPILER_PREFIX@) +set(cross_prefix @cross_prefix@) # If this file is used without templating, then cross_prefix will # have an invalid value and should only be assigned to CROSS_COMPILER_PREFIX # if it has been set to something different. # We need to build the test string dynamically otherwise the templating would # overwrite it. -set(cross_prefix_test @CROSS_COMPILER_PREFIX) +set(cross_prefix_test @cross_prefix) string(APPEND cross_prefix_test @) -if(NOT "${cross_prefix}" STREQUAL "${cross_prefix_test}") +if((NOT "${cross_prefix}" STREQUAL "${cross_prefix_test}") AND (NOT "${cross_prefix}" STREQUAL "")) set(CROSS_COMPILER_PREFIX ${cross_prefix}) endif()