1# SPDX-License-Identifier: Apache-2.0
2# Copyright (c) 2019 Oticon A/S
3
4# CMake file to compile this BabbleSim component as a west module in Zephyr
5
6if(CONFIG_SOC_SERIES_BSIM_NRFXX)
7
8  if (NOT DEFINED ENV{BSIM_COMPONENTS_PATH})
9    message(FATAL_ERROR "This Zephyr module requires the BabbleSim simulator.\
10 Please set the  environment variable BSIM_COMPONENTS_PATH to point to its\
11 components folder. More information can be found in\
12 https://babblesim.github.io/folder_structure_and_env.html")
13  endif()
14  if (NOT DEFINED ENV{BSIM_OUT_PATH})
15    message(FATAL_ERROR "This Zephyr module requires the BabbleSim simulator.\
16 Please set the  environment variable BSIM_OUT_PATH to point to the folder\
17 where the simulator is compiled to. More information can be found in\
18 https://babblesim.github.io/folder_structure_and_env.html")
19  endif()
20
21  # These include directories must be added before those from the hal_nordic
22  # module, so that the local modified versions of nrfx files are used instead
23  # of those from the original nrfx.
24  target_include_directories(zephyr_interface BEFORE INTERFACE
25    ${CMAKE_CURRENT_SOURCE_DIR}/src/nrfx/mdk_replacements
26    ${CMAKE_CURRENT_SOURCE_DIR}/src/nrfx/hal_replacements
27  )
28
29  zephyr_include_directories(
30    src/HW_models/
31    src/nrfx/nrfx_replacements
32  )
33
34  if(CONFIG_SOC_SERIES_BSIM_NRF52X)
35    file(STRINGS make_inc/52833_hw_files HW_MODEL_SRCS)
36    file(STRINGS make_inc/52833_hal_files HAL_SRCS)
37    set(VARIANT_FLAGS
38        -DNRF52833_XXAA
39        -DNRF52833
40    )
41  elseif(CONFIG_SOC_SERIES_BSIM_NRF53X)
42    file(STRINGS make_inc/5340_hw_files HW_MODEL_SRCS)
43
44    if(CONFIG_BOARD_NRF5340BSIM_NRF5340_CPUNET)
45      file(STRINGS make_inc/5340_net_hal_files HAL_SRCS)
46      set(VARIANT_FLAGS
47        -DNRF5340_XXAA_NETWORK
48        -DNRF5340
49      )
50    elseif(CONFIG_BOARD_NRF5340BSIM_NRF5340_CPUAPP)
51      file(STRINGS make_inc/5340_app_hal_files HAL_SRCS)
52      set(VARIANT_FLAGS
53        -DNRF5340_XXAA_APPLICATION
54        -DNRF5340
55      )
56    endif()
57  endif()
58
59  # The nrfx HAL is built in the context of the embedded software
60  zephyr_library()
61  zephyr_library_sources(${HAL_SRCS})
62
63  zephyr_library_include_directories(
64    $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/
65    src/HW_models/
66  )
67
68  # The HW models are built in the runner context, so they have access to the host OS
69  target_sources(native_simulator INTERFACE ${HW_MODEL_SRCS})
70
71  target_compile_options(native_simulator BEFORE INTERFACE
72    -I${NSI_DIR}/common/src/include
73    -I${NSI_DIR}/common/src/
74    -I$ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/
75    -I$ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/
76    -I$ENV{BSIM_COMPONENTS_PATH}/ext_2G4_libPhyComv1/src/
77    -I$ENV{BSIM_COMPONENTS_PATH}/libRandv2/src/
78    -I${CMAKE_CURRENT_SOURCE_DIR}/src/HW_models/
79    -I${CMAKE_CURRENT_SOURCE_DIR}/src/nrfx_config
80    -I${CMAKE_CURRENT_SOURCE_DIR}/src/nrfx/mdk_replacements
81    -I${CMAKE_CURRENT_SOURCE_DIR}/src/nrfx/nrfx_replacements
82    -I${NRFX_DIR}
83    -I${NRFX_DIR}/mdk
84    ${VARIANT_FLAGS}
85    -std=gnu11 #The nrfx hal uses non standard features which will cause warnings otherwise
86  )
87
88endif()
89