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  )
27
28  zephyr_include_directories(
29    src/HW_models/
30    src/nrfx/nrfx_replacements
31  )
32
33  if(CONFIG_SOC_SERIES_BSIM_NRF52X)
34    file(STRINGS make_inc/52833_hw_files HW_MODEL_SRCS)
35    file(STRINGS make_inc/52833_hal_files HAL_SRCS)
36    set(VARIANT_FLAGS
37        -DNRF52833_XXAA
38        -DNRF52833
39    )
40  elseif(CONFIG_SOC_SERIES_BSIM_NRF53X)
41    file(STRINGS make_inc/5340_hw_files HW_MODEL_SRCS)
42
43    if(CONFIG_BOARD_NRF5340BSIM_NRF5340_CPUNET)
44      file(STRINGS make_inc/5340_net_hal_files HAL_SRCS)
45      set(VARIANT_FLAGS
46        -DNRF5340_XXAA_NETWORK
47        -DNRF5340
48      )
49    elseif(CONFIG_BOARD_NRF5340BSIM_NRF5340_CPUAPP)
50      file(STRINGS make_inc/5340_app_hal_files HAL_SRCS)
51      set(VARIANT_FLAGS
52        -DNRF5340_XXAA_APPLICATION
53        -DNRF5340
54      )
55    endif()
56  endif()
57
58  # The nrfx HAL is built in the context of the embedded software
59  zephyr_library()
60  zephyr_library_sources(${HAL_SRCS})
61
62  zephyr_library_include_directories(
63    $ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/
64    src/HW_models/
65  )
66
67  # The HW models are built in the runner context, so they have access to the host OS
68  target_sources(native_simulator INTERFACE ${HW_MODEL_SRCS})
69
70  target_compile_options(native_simulator BEFORE INTERFACE
71    -I${NSI_DIR}/common/src/include
72    -I${NSI_DIR}/common/src/
73    -I$ENV{BSIM_COMPONENTS_PATH}/libUtilv1/src/
74    -I$ENV{BSIM_COMPONENTS_PATH}/libPhyComv1/src/
75    -I$ENV{BSIM_COMPONENTS_PATH}/ext_2G4_libPhyComv1/src/
76    -I$ENV{BSIM_COMPONENTS_PATH}/libRandv2/src/
77    -I${CMAKE_CURRENT_SOURCE_DIR}/src/HW_models/
78    -I${CMAKE_CURRENT_SOURCE_DIR}/src/nrfx_config
79    -I${CMAKE_CURRENT_SOURCE_DIR}/src/nrfx/mdk_replacements
80    -I${CMAKE_CURRENT_SOURCE_DIR}/src/nrfx/nrfx_replacements
81    -I${NRFX_DIR}
82    -I${NRFX_DIR}/mdk
83    ${VARIANT_FLAGS}
84    -std=gnu11 #The nrfx hal uses non standard features which will cause warnings otherwise
85  )
86
87endif()
88