2 # Copyright (c) 2020 Project CHIP Authors
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
19 # CMake module for incorporating CHIP into an nRF Connect SDK
20 # application for Nordic platforms.
24 # The top-level CMakeLists.txt of an application should define CHIP_ROOT variable,
25 # include this module and configure `app` build target properly. E.g.:
27 # cmake_minimum_required(VERSION 3.13.1)
29 # set(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/third_party/connectedhomeip)
30 # get_filename_component(CHIP_ROOT ${CHIP_ROOT} REALPATH)
31 # set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CHIP_ROOT}/config/nrfconnect/)
33 # include(nrfconnect-app)
35 # project(chip-nrf52840-lock-example)
36 # target_sources(app PRIVATE main/main.cpp ...)
39 # Set DTC overlay before finding the Zephyr package.
40 if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/dts.overlay")
41 set(DTC_OVERLAY_FILE "${CMAKE_CURRENT_SOURCE_DIR}/dts.overlay")
45 if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Kconfig)
46 set(KCONFIG_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/Kconfig)
48 set(KCONFIG_ROOT ${CHIP_ROOT}/config/nrfconnect/Kconfig)
51 # ==================================================
52 # Load NCS/Zephyr build system
53 # ==================================================
54 find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})
56 # TODO: temporary fix forcing time_t size to be equal long size - remove it after merging fix from Zephyr project.
57 zephyr_compile_definitions(_USE_LONG_TIME_T)
59 # ==================================================
61 # ==================================================
66 -D_SYS__PTHREADTYPES_H_
67 -DMBEDTLS_CONFIG_FILE=<nrf-config.h>
69 -DMBEDTLS_X509_CREATE_C
70 -DMBEDTLS_X509_CSR_WRITE_C
71 -isystem${ZEPHYR_BASE}/include/posix
72 -isystem${ZEPHYR_BASE}/../mbedtls/include
73 -I${CMAKE_CURRENT_SOURCE_DIR}
74 -I${CMAKE_CURRENT_SOURCE_DIR}/main/include
77 set(CHIP_LIBRARIES ${CHIP_OUTPUT_DIR}/lib/libCHIP.a)
78 if (CONFIG_CHIP_LIB_SHELL)
79 list(APPEND CHIP_LIBRARIES ${CHIP_OUTPUT_DIR}/obj/third_party/connectedhomeip/src/lib/shell/lib/libCHIPShell.a)
81 if (CONFIG_CHIP_PW_RPC)
82 list(APPEND CHIP_LIBRARIES ${CHIP_OUTPUT_DIR}/lib/libPwRpc.a)
85 find_file(CHIP_PROJECT_CONFIG
87 PATHS ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/main/include
91 # ==================================================
93 # ==================================================
95 function(set_openthread_config OT_DIR CONFIG_FILE)
96 get_property(DEFINES DIRECTORY ${OT_DIR} PROPERTY COMPILE_DEFINITIONS)
97 get_property(SUBDIRS DIRECTORY ${OT_DIR} PROPERTY SUBDIRECTORIES)
99 list(TRANSFORM DEFINES REPLACE
100 OPENTHREAD_PROJECT_CORE_CONFIG_FILE=.*
101 OPENTHREAD_PROJECT_CORE_CONFIG_FILE="${CONFIG_FILE}")
103 set_property(DIRECTORY ${OT_DIR} PROPERTY COMPILE_DEFINITIONS ${DEFINES})
105 foreach(SUBDIR ${SUBDIRS})
106 set_openthread_config(${SUBDIR} ${CONFIG_FILE})
110 # Add dependency on nRF crypto library.
111 # This is temporary solution and should be removed after fixing it in nRF Connect SDK.
112 zephyr_include_directories(${ZEPHYR_BASE}/../nrfxlib/crypto/nrf_cc310_platform/include)
114 # Override Zephyr-supplied OpenThread configuration
115 if (CHIP_OPENTHREAD_CONFIG)
116 get_filename_component(CONFIG_DIR ${CHIP_OPENTHREAD_CONFIG} DIRECTORY)
117 get_filename_component(CONFIG_FILE ${CHIP_OPENTHREAD_CONFIG} NAME)
118 target_include_directories(ot-config INTERFACE ${CONFIG_DIR})
119 set_openthread_config(${ZEPHYR_BASE}/../modules/lib/openthread ${CONFIG_FILE})
122 # ==================================================
124 # ==================================================
126 chip_configure(ChipConfig
128 CFLAGS ${CHIP_COMMON_FLAGS} --specs=nosys.specs
129 CXXFLAGS ${CHIP_COMMON_FLAGS}
130 PROJECT_CONFIG ${CHIP_PROJECT_CONFIG}
133 chip_build(ChipLib ChipConfig
135 BUILD_ARTIFACTS ${CHIP_LIBRARIES}
138 # ==================================================
139 # Configure application
140 # ==================================================
142 target_link_libraries(app PUBLIC ChipLib)
143 target_compile_definitions(app PRIVATE CHIP_HAVE_CONFIG_H)