Skip to content

Commit

Permalink
Introduce cmake-based rewrite of KBuild
Browse files Browse the repository at this point in the history
Introducing CMake is an important step in a larger effort to make
Zephyr easy to use for application developers working on different
platforms with different development environment needs.

Simplified, this change retains Kconfig as-is, and replaces all
Makefiles with CMakeLists.txt. The DSL-like Make language that KBuild
offers is replaced by a set of CMake extentions. These extentions have
either provided simple one-to-one translations of KBuild features or
introduced new concepts that replace KBuild concepts.

This is a breaking change for existing test infrastructure and build
scripts that are maintained out-of-tree. But for FW itself, no porting
should be necessary.

For users that just want to continue their work with minimal
disruption the following should suffice:

Install CMake 3.8.2+

Port any out-of-tree Makefiles to CMake.

Learn the absolute minimum about the new command line interface:

$ cd samples/hello_world
$ mkdir build && cd build
$ cmake -DBOARD=nrf52_pca10040 ..

$ cd build
$ make

PR: zephyrproject-rtos#4692
docs: http://docs.zephyrproject.org/getting_started/getting_started.html

Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
  • Loading branch information
SebastianBoe authored and Anas Nashif committed Nov 9, 2017
1 parent 8bffcda commit 12f8f76
Show file tree
Hide file tree
Showing 644 changed files with 7,815 additions and 0 deletions.
731 changes: 731 additions & 0 deletions CMakeLists.txt

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions arch/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_subdirectory(common)
add_subdirectory(${ARCH})
14 changes: 14 additions & 0 deletions arch/arc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Enable debug support in mdb
# Dwarf version 2 can be recognized by mdb
# The default dwarf version in gdb is not recognized by mdb
zephyr_cc_option(-g3 -gdwarf-2)

# Without this (poorly named) option, compiler may generate undefined
# references to abort().
# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63691
zephyr_cc_option(-fno-delete-null-pointer-checks)

zephyr_cc_option_ifdef (CONFIG_LTO -flto)

add_subdirectory(soc/${SOC_PATH})
add_subdirectory(core)
23 changes: 23 additions & 0 deletions arch/arc/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
zephyr_sources(
thread.c
thread_entry_wrapper.S
cpu_idle.S
fast_irq.S
fatal.c
fault.c
fault_s.S
irq_manage.c
cache.c
timestamp.c
isr_wrapper.S
regular_irq.S
swap.S
sys_fatal_error_handler.c
prep_c.c
reset.S
vector_table.c
)

zephyr_sources_if_kconfig(irq_offload.c)
zephyr_sources_ifdef(CONFIG_ATOMIC_OPERATIONS_CUSTOM atomic.c)
add_subdirectory_ifdef(CONFIG_CPU_HAS_MPU mpu)
2 changes: 2 additions & 0 deletions arch/arc/core/mpu/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
zephyr_sources_if_kconfig(arc_core_mpu.c)
zephyr_sources_if_kconfig(arc_mpu.c)
14 changes: 14 additions & 0 deletions arch/arc/soc/em11d/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
zephyr_library_include_directories(${PROJECT_SOURCE_DIR}/drivers)

zephyr_cc_option(-mcpu=em4_fpuda -mno-sdata -mdiv-rem -mswap -mnorm)
zephyr_cc_option(-mmpy-option=6 -mbarrel-shifter)
zephyr_cc_option(--param l1-cache-size=16384)
zephyr_cc_option(--param l1-cache-line-size=32)
zephyr_cc_option_ifdef(CONFIG_CODE_DENSITY -mcode-density)
zephyr_cc_option_ifdef(CONFIG_FLOAT -mfpu=fpuda_all)


zephyr_sources(
soc.c
soc_config.c
)
21 changes: 21 additions & 0 deletions arch/arc/soc/em7d/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
zephyr_library_include_directories(${PROJECT_SOURCE_DIR}/drivers)

zephyr_cc_option(-mcpu=-mcpu=em4_dmips -mno-sdata)
zephyr_cc_option(-mdiv-rem -mswap -mnorm)
zephyr_cc_option(-mmpy-option=6 -mbarrel-shifter)
zephyr_cc_option(--param l1-cache-size=16384)
zephyr_cc_option(--param l1-cache-line-size=32)

zephyr_cc_option_ifdef(CONFIG_CODE_DENSITY -mcode-density)

if(CONFIG_BOARD_EM_STARTERKIT_R23)
message(FATAL "em7d from em starterkit 2.3 is not supported")
endif()


zephyr_sources(
soc.c
soc_config.c
)

zephyr_source_ifdef(CONFIG_ARC_MPU_ENABLE arc_mpu_regions.c)
14 changes: 14 additions & 0 deletions arch/arc/soc/em9d/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
zephyr_library_include_directories(${PROJECT_SOURCE_DIR}/drivers)

zephyr_cc_option(-mcpu=em4_fpus -mno-sdata -mdiv-rem -mswap -mnorm)
zephyr_cc_option(-mdiv-rem -mswap -mnorm)
zephyr_cc_option(-mmpy-option=6 -mbarrel-shifter)

zephyr_cc_option_ifdef(CONFIG_CODE_DENSITY -mcode-density)
zephyr_cc_option_ifdef(CONFIG_FLOAT -mfpu=fpuda_all)


zephyr_sources(
soc.c
soc_config.c
)
17 changes: 17 additions & 0 deletions arch/arc/soc/quark_se_c1000_ss/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
zephyr_library_include_directories(${PROJECT_SOURCE_DIR}/drivers)
zephyr_include_directories(${PROJECT_SOURCE_DIR}/arch/x86/soc/intel_quark)

zephyr_cc_option(-mcpu=quarkse_em -mno-sdata)

zephyr_compile_definitions_ifdef(
CONFIG_SOC_QUARK_SE_C1000_SS
QM_SENSOR=1
SOC_SERIES=quark_se
)

zephyr_sources(
soc.c
soc_config.c
power.c
soc_power.S
)
21 changes: 21 additions & 0 deletions arch/arm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
zephyr_cc_option_ifdef(CONFIG_LTO -flto)

set(ARCH_FOR_cortex-m0 armv6-m )
set(ARCH_FOR_cortex-m0plus armv6-m )
set(ARCH_FOR_cortex-m3 armv7-m )
set(ARCH_FOR_cortex-m4 armv7e-m )
set(ARCH_FOR_cortex-m23 armv8-m.base)
set(ARCH_FOR_cortex-m33 armv8-m.main)

if(${ARCH_FOR_${GCC_M_CPU}})
set(ARCH_FLAG -march=${ARCH_FOR_${GCC_M_CPU}})
endif()

zephyr_compile_options(
-mabi=aapcs
${TOOLCHAIN_C_FLAGS}
${ARCH_FLAG}
)

add_subdirectory(soc)
add_subdirectory(core)
20 changes: 20 additions & 0 deletions arch/arm/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
zephyr_sources(
exc_exit.S
irq_init.c
swap.S
fault.c
irq_manage.c
thread.c
cpu_idle.S
fault_s.S
fatal.c
sys_fatal_error_handler.c
thread_abort.c
)

zephyr_sources_ifdef(CONFIG_GEN_SW_ISR_TABLE isr_wrapper.S)
zephyr_sources_ifdef(CONFIG_CPLUSPLUS __aeabi_atexit.c)
zephyr_sources_ifdef(CONFIG_IRQ_OFFLOAD irq_offload.c)

add_subdirectory_ifdef(CONFIG_CPU_CORTEX_M cortex_m)
add_subdirectory_ifdef(CONFIG_CPU_HAS_MPU cortex_m/mpu)
9 changes: 9 additions & 0 deletions arch/arm/core/cortex_m/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
zephyr_sources(
vector_table.S
reset.S
nmi_on_reset.S
prep_c.c
scb.c
nmi.c
exc_manage.c
)
3 changes: 3 additions & 0 deletions arch/arm/core/cortex_m/mpu/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
zephyr_sources_ifdef(CONFIG_ARM_CORE_MPU arm_core_mpu.c)
zephyr_sources_if_kconfig( arm_mpu.c)
zephyr_sources_if_kconfig( nxp_mpu.c)
6 changes: 6 additions & 0 deletions arch/arm/soc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if(SOC_FAMILY)
add_subdirectory(${SOC_FAMILY})
else()
add_subdirectory(${SOC_NAME})
endif()

1 change: 1 addition & 0 deletions arch/arm/soc/arm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(${SOC_SERIES})
5 changes: 5 additions & 0 deletions arch/arm/soc/arm/beetle/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
zephyr_sources(
soc.c
power.c
)
zephyr_sources_ifdef(CONFIG_ARM_MPU_ENABLE arm_mpu_regions.c)
3 changes: 3 additions & 0 deletions arch/arm/soc/arm/mps2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
zephyr_sources(
soc.c
)
8 changes: 8 additions & 0 deletions arch/arm/soc/atmel_sam/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Makefile - Atmel SAM MCU family
#
# Copyright (c) 2016 Piotr Mienkowski
# SPDX-License-Identifier: Apache-2.0
#

add_subdirectory(${SOC_SERIES})
add_subdirectory_ifdef(CONFIG_ASF common)
5 changes: 5 additions & 0 deletions arch/arm/soc/atmel_sam/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
zephyr_include_directories(.)
zephyr_sources(
soc_pmc.c
soc_gpio.c
)
3 changes: 3 additions & 0 deletions arch/arm/soc/atmel_sam/sam3x/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
zephyr_sources(
soc.c
)
3 changes: 3 additions & 0 deletions arch/arm/soc/atmel_sam/sam4s/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
zephyr_sources(
soc.c
)
4 changes: 4 additions & 0 deletions arch/arm/soc/atmel_sam/same70/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
zephyr_sources(
soc.c
soc_config.c
)
5 changes: 5 additions & 0 deletions arch/arm/soc/nordic_nrf5/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
zephyr_include_directories(
include
)

add_subdirectory(${SOC_SERIES})
9 changes: 9 additions & 0 deletions arch/arm/soc/nordic_nrf5/nrf51/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
zephyr_compile_definitions_ifdef(
CONFIG_SOC_SERIES_NRF51X
NRF51
NRF51822
)

zephyr_sources(
soc.c
)
8 changes: 8 additions & 0 deletions arch/arm/soc/nordic_nrf5/nrf52/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF52832 NRF52832_XXAA)
zephyr_compile_definitions_ifdef(CONFIG_SOC_NRF52840 NRF52840_XXAA)

zephyr_sources(
mpu_regions.c
power.c
soc.c
)
1 change: 1 addition & 0 deletions arch/arm/soc/nxp_kinetis/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(${SOC_SERIES})
8 changes: 8 additions & 0 deletions arch/arm/soc/nxp_kinetis/k6x/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
zephyr_sources(
soc.c
wdog.S
)
zephyr_sources_ifdef(
CONFIG_HAS_SYSMPU
nxp_mpu_regions.c
)
1 change: 1 addition & 0 deletions arch/arm/soc/nxp_kinetis/kl2x/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
zephyr_sources(soc.c)
4 changes: 4 additions & 0 deletions arch/arm/soc/nxp_kinetis/kwx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
zephyr_sources_ifdef(CONFIG_SOC_MKW24D5 wdog.S soc_kw2xd.c)
zephyr_sources_ifdef(CONFIG_SOC_MKW22D5 wdog.S soc_kw2xd.c)
zephyr_sources_ifdef(CONFIG_SOC_MKW41Z4 soc_kw4xz.c)
zephyr_sources_ifdef(CONFIG_SOC_MKW40Z4 soc_kw4xz.c)
2 changes: 2 additions & 0 deletions arch/arm/soc/silabs_exx32/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_subdirectory(${SOC_SERIES})
add_subdirectory(common)
1 change: 1 addition & 0 deletions arch/arm/soc/silabs_exx32/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
zephyr_sources(soc_gpio.c)
1 change: 1 addition & 0 deletions arch/arm/soc/silabs_exx32/efm32wg/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
zephyr_sources(soc.c)
2 changes: 2 additions & 0 deletions arch/arm/soc/st_stm32/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_subdirectory(${SOC_SERIES})
add_subdirectory(common)
1 change: 1 addition & 0 deletions arch/arm/soc/st_stm32/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
zephyr_sources_ifdef(CONFIG_STM32_ARM_MPU_ENABLE arm_mpu_regions.c)
3 changes: 3 additions & 0 deletions arch/arm/soc/st_stm32/stm32f0/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
zephyr_include_directories($ENV{ZEPHYR_BASE}/drivers)
zephyr_sources(soc.c)
zephyr_sources_ifdef(CONFIG_GPIO soc_gpio.c)
5 changes: 5 additions & 0 deletions arch/arm/soc/st_stm32/stm32f1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
zephyr_include_directories($ENV{ZEPHYR_BASE}/drivers)
zephyr_sources(
soc.c
)
zephyr_sources_ifdef(CONFIG_GPIO soc_gpio.c)
5 changes: 5 additions & 0 deletions arch/arm/soc/st_stm32/stm32f3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
zephyr_include_directories($ENV{ZEPHYR_BASE}/drivers)
zephyr_sources(
soc.c
)
zephyr_sources_ifdef(CONFIG_GPIO soc_gpio.c)
5 changes: 5 additions & 0 deletions arch/arm/soc/st_stm32/stm32f4/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
zephyr_include_directories($ENV{ZEPHYR_BASE}/drivers)
zephyr_sources(
soc.c
)
zephyr_sources_ifdef(CONFIG_GPIO soc_gpio.c)
5 changes: 5 additions & 0 deletions arch/arm/soc/st_stm32/stm32l4/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
zephyr_include_directories($ENV{ZEPHYR_BASE}/drivers)
zephyr_sources(
soc.c
)
zephyr_sources_ifdef(CONFIG_GPIO soc_gpio.c)
4 changes: 4 additions & 0 deletions arch/arm/soc/ti_lm3s6965/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
zephyr_sources(
soc.c
soc_config.c
)
1 change: 1 addition & 0 deletions arch/arm/soc/ti_simplelink/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(${SOC_SERIES})
1 change: 1 addition & 0 deletions arch/arm/soc/ti_simplelink/cc2650/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
zephyr_sources(soc.c)
1 change: 1 addition & 0 deletions arch/arm/soc/ti_simplelink/cc32xx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
zephyr_sources(soc.c)
2 changes: 2 additions & 0 deletions arch/arm/soc/ti_simplelink/msp432p4xx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
zephyr_compile_definitions(-D__MSP432P401R__)
zephyr_sources(soc.c)
13 changes: 13 additions & 0 deletions arch/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Put functions and data in their own binary sections so that ld can
# garbage collect them
zephyr_cc_option(-ffunction-sections -fdata-sections)

zephyr_sources_ifdef(
CONFIG_GEN_ISR_TABLES
isr_tables.c
)

zephyr_sources_ifdef(
CONFIG_EXECUTION_BENCHMARKING
timing_info_bench.c
)
37 changes: 37 additions & 0 deletions arch/nios2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
if(CONFIG_GP_NONE)
set(gpopt none)
elseif(CONFIG_GP_LOCAL)
set(gpopt local)
elseif(CONFIG_GP_GLOBAL)
set(gpopt global)
elseif(CONFIG_GP_ALL_DATA)
set(gpopt data)
endif()

# Set Global Pointer option based on Kconfig.
zephyr_cc_option(-mgpopt=${gpopt})

# TODO Find a way to pull this out of system.h somehow
# instead of having Kconfig for it

if(CONFIG_HAS_MUL_INSTRUCTION)
zephyr_cc_option(-mhw-mul)
else()
zephyr_cc_option(-mno-hw-mul)
endif()

if(CONFIG_HAS_MULX_INSTRUCTION)
zephyr_cc_option(-mhw-mulx)
else()
zephyr_cc_option(-mno-hw-mulx)
endif()

if(CONFIG_HAS_DIV_INSTRUCTION)
zephyr_cc_option(-mhw-div)
else()
zephyr_cc_option(-mno-hw-div)
endif()


add_subdirectory(soc/${SOC_PATH})
add_subdirectory(core)
14 changes: 14 additions & 0 deletions arch/nios2/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
zephyr_sources(
thread.c
cpu_idle.c
fatal.c
irq_manage.c
swap.S
prep_c.c
reset.S
cache.c
exception.S
crt0.S
)

zephyr_sources_if_kconfig(irq_offload.c)
Empty file.
2 changes: 2 additions & 0 deletions arch/nios2/soc/nios2f-zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

set($ENV{NIOS2_CPU_SOF} $ENV{ZEPHYR_BASE}/arch/nios2/soc/nios2f-zephyr/cpu/ghrd_10m50da.sof)
4 changes: 4 additions & 0 deletions arch/riscv32/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_subdirectory(soc)
add_subdirectory(core)

set_property(GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT elf32-littleriscv)
Loading

0 comments on commit 12f8f76

Please sign in to comment.