1# Copyright (C) 2022 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15if(CONFIG_CHRE)
16  get_filename_component(CHRE_DIR "${ZEPHYR_CURRENT_MODULE_DIR}" ABSOLUTE)
17
18  zephyr_library()
19
20  set(CHRE_INCLUDE_DIRS
21      "${CHRE_DIR}/chpp/include"
22      "${CHRE_DIR}/chre_api/include"
23      "${CHRE_DIR}/chre_api/include/chre_api"
24      "${CHRE_DIR}/core/include"
25      "${CHRE_DIR}/pal/include"
26      "${CHRE_DIR}/platform/include"
27      "${CHRE_DIR}/platform/shared/include"
28      "${CHRE_DIR}/util/include"
29      "${CMAKE_CURRENT_SOURCE_DIR}/include")
30  zephyr_include_directories("${CHRE_INCLUDE_DIRS}")
31  zephyr_library_include_directories("${CHRE_INCLUDE_DIRS}")
32
33  zephyr_library_sources(
34      "context.cc"
35      "host_link.cc"
36      "init.cc"
37      "log_module.c"
38      "memory.cc"
39      "platform_nanoapp.cc"
40      "power_control_manager.cc"
41      "system_time.cc"
42      "system_timer.cc"
43      "${CHRE_DIR}/core/debug_dump_manager.cc"
44      "${CHRE_DIR}/core/event.cc"
45      "${CHRE_DIR}/core/event_loop.cc"
46      "${CHRE_DIR}/core/event_loop_manager.cc"
47      "${CHRE_DIR}/core/event_ref_queue.cc"
48      "${CHRE_DIR}/core/host_comms_manager.cc"
49      "${CHRE_DIR}/core/init.cc"
50      "${CHRE_DIR}/core/nanoapp.cc"
51      "${CHRE_DIR}/core/settings.cc"
52      "${CHRE_DIR}/core/static_nanoapps.cc"
53      "${CHRE_DIR}/core/timer_pool.cc"
54      "${CHRE_DIR}/platform/shared/version.cc"
55      "${CHRE_DIR}/platform/shared/system_time.cc"
56      "${CHRE_DIR}/util/buffer_base.cc"
57      "${CHRE_DIR}/util/dynamic_vector_base.cc"
58  )
59  zephyr_linker_sources(SECTIONS linker_chre.ld)
60
61  # Optional audio support
62  if(CONFIG_CHRE_AUDIO_SUPPORT_ENABLED)
63    zephyr_compile_definitions(CHRE_AUDIO_SUPPORT_ENABLED)
64    zephyr_library_sources("${CHRE_DIR}/core/audio_request_manager.cc")
65  endif()
66
67  # Optional GNSS support
68  if(CONFIG_CHRE_GNSS_SUPPORT_ENABLED)
69    zephyr_compile_definitions(CHRE_GNSS_SUPPORT_ENABLED)
70    zephyr_library_sources("${CHRE_DIR}/core/gnss_manager.cc")
71  endif()
72
73  # Optional sensor support
74  if(CONFIG_CHRE_SENSORS_SUPPORT_ENABLED)
75    zephyr_compile_definitions(CHRE_SENSORS_SUPPORT_ENABLED)
76    zephyr_library_sources(
77        "${CHRE_DIR}/core/sensor.cc"
78        "${CHRE_DIR}/core/sensor_request.cc"
79        "${CHRE_DIR}/core/sensor_request_manager.cc"
80        "${CHRE_DIR}/core/sensor_request_multiplexer.cc"
81        "${CHRE_DIR}/core/sensor_type.cc"
82        "${CHRE_DIR}/core/sensor_type_helpers.cc"
83    )
84  endif()
85
86  # Optional WiFi support
87  if(CONFIG_CHRE_WIFI_SUPPORT_ENABLED)
88    zephyr_compile_definitions(CHRE_WIFI_SUPPORT_ENABLED)
89    zephyr_library_sources(
90        "${CHRE_DIR}/core/wifi_request_manager.cc"
91        "${CHRE_DIR}/core/wifi_scan_request.cc"
92    )
93  endif()
94
95  # Optional WWAN support
96  if(CONFIG_CHRE_WWAN_SUPPORT_ENABLED)
97    zephyr_compile_definitions(CHRE_WWAN_SUPPORT_ENABLED)
98    zephyr_library_sources("${CHRE_DIR}/core/wwan_request_manager.cc")
99  endif()
100
101  zephyr_compile_definitions(
102      CHRE_MESSAGE_TO_HOST_MAX_SIZE=${CONFIG_CHRE_MESSAGE_TO_HOST_MAX_SIZE})
103
104  zephyr_compile_definitions(CHRE_FILENAME=__FILE__)
105
106  # Add logging definitions
107  if((NOT DEFINED CONFIG_CHRE_LOG_LEVEL) OR
108     "${CONFIG_CHRE_LOG_LEVEL}" EQUAL "0")
109    zephyr_compile_definitions(CHRE_MINIMUM_LOG_LEVEL=CHRE_LOG_LEVEL_MUTE)
110  elseif("${CONFIG_CHRE_LOG_LEVEL}" EQUAL "1")
111    zephyr_compile_definitions(CHRE_MINIMUM_LOG_LEVEL=CHRE_LOG_LEVEL_ERROR)
112  elseif("${CONFIG_CHRE_LOG_LEVEL}" EQUAL "2")
113    zephyr_compile_definitions(CHRE_MINIMUM_LOG_LEVEL=CHRE_LOG_LEVEL_WARN)
114  elseif("${CONFIG_CHRE_LOG_LEVEL}" EQUAL "3")
115    zephyr_compile_definitions(CHRE_MINIMUM_LOG_LEVEL=CHRE_LOG_LEVEL_INFO)
116  elseif(("${CONFIG_CHRE_LOG_LEVEL}" EQUAL "4") OR
117         ("${CONFIG_CHRE_LOG_LEVEL}" EQUAL "5"))
118    # Debug and verbose are collapsed into one since Zephyr doesn't
119    # differentiate the two levels
120    zephyr_compile_definitions(CHRE_MINIMUM_LOG_LEVEL=CHRE_LOG_LEVEL_VERBOSE)
121  endif()
122
123  if(DEFINED CONFIG_CHRE_ASSERTIONS)
124    zephyr_compile_definitions(CHRE_ASSERTIONS_ENABLED)
125  else()
126    zephyr_compile_definitions(CHRE_ASSERTIONS_DISABLED)
127  endif()
128
129  zephyr_compile_definitions(CHRE_FIRST_SUPPORTED_API_VERSION=CHRE_API_VERSION_1_5)
130endif()
131