From 2680625945535e11d52deaeed3117ddb720483bb Mon Sep 17 00:00:00 2001 From: Michael Spang Date: Tue, 19 May 2020 06:10:36 -0400 Subject: [PATCH] Add SystemConfig to GN build Not all options are configurable through GN args yet, just a few examples. --- BUILD.gn | 1 + build/tests.gni | 3 ++ src/BUILD.gn | 17 +++++++ src/system/BUILD.gn | 106 ++++++++++++++++++++++++++++++++++++++++++ src/system/system.gni | 51 ++++++++++++++++++++ 5 files changed, 178 insertions(+) create mode 100644 src/BUILD.gn create mode 100644 src/system/BUILD.gn create mode 100644 src/system/system.gni diff --git a/BUILD.gn b/BUILD.gn index 69bd3f03baf63e..d182aa5b42d9da 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -17,6 +17,7 @@ import("build/tests.gni") group("all") { deps = [ "src/lwip:all", + "src/system:system_config_header", "third_party/mbedtls", "third_party/nlassert", "third_party/nlfaultinjection", diff --git a/build/tests.gni b/build/tests.gni index b81105dc1d4927..2f3d4ce0f78b22 100644 --- a/build/tests.gni +++ b/build/tests.gni @@ -15,4 +15,7 @@ declare_args() { # Enable building tests. chip_build_tests = true + + # Enable use of nlfaultinjection. + chip_with_nlfaultinjection = true } diff --git a/src/BUILD.gn b/src/BUILD.gn new file mode 100644 index 00000000000000..5f4d446904d611 --- /dev/null +++ b/src/BUILD.gn @@ -0,0 +1,17 @@ +# Copyright (c) 2020 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +config("includes") { + include_dirs = [ "." ] +} diff --git a/src/system/BUILD.gn b/src/system/BUILD.gn new file mode 100644 index 00000000000000..e2c9ad60bcf356 --- /dev/null +++ b/src/system/BUILD.gn @@ -0,0 +1,106 @@ +# Copyright (c) 2020 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/tests.gni") +import("system.gni") + +declare_args() { + # Extra header to include in CHIPConfig.h for project. + # TODO - This should probably be in src/core but src/system also uses it. + chip_project_config_include = "" + + # Extra header to include in CHIPConfig.h for platform. + # TODO - This should probably be in src/core but src/system also uses it. + chip_platform_config_include = "" + + # Extra header to include in SystemConfig.h for project. + system_project_config_include = "" + + # Extra header to include in SystemConfig.h for platform. + system_platform_config_include = "" +} + +config("system_config") { + configs = [ "//src:includes" ] + + defines = [] + if (chip_project_config_include != "") { + defines += [ "CHIP_PROJECT_CONFIG_INCLUDE=${chip_project_config_include}" ] + } + if (chip_platform_config_include != "") { + defines += + [ "CHIP_PLATFORM_CONFIG_INCLUDE=${chip_platform_config_include}" ] + } + if (system_project_config_include != "") { + defines += + [ "SYSTEM_PROJECT_CONFIG_INCLUDE=${system_project_config_include}" ] + } + if (system_platform_config_include != "") { + defines += + [ "SYSTEM_PLATFORM_CONFIG_INCLUDE=${system_platform_config_include}" ] + } + if (chip_build_tests) { + defines += [ "CHIP_SYSTEM_CONFIG_TEST=1" ] + } else { + defines += [ "CHIP_SYSTEM_CONFIG_TEST=0" ] + } + if (chip_with_nlfaultinjection) { + defines += [ "CHIP_WITH_NLFAULTINJECTION=1" ] + } else { + defines += [ "CHIP_WITH_NLFAULTINJECTION=0" ] + } + if (chip_system_config_use_lwip) { + defines += [ "CHIP_SYSTEM_CONFIG_USE_LWIP=1" ] + } else { + defines += [ "CHIP_SYSTEM_CONFIG_USE_LWIP=0" ] + } + if (chip_system_config_use_sockets) { + defines += [ "CHIP_SYSTEM_CONFIG_USE_SOCKETS=1" ] + } else { + defines += [ "CHIP_SYSTEM_CONFIG_USE_SOCKETS=0" ] + } + if (chip_system_config_locking == "posix") { + defines += [ "CHIP_SYSTEM_CONFIG_POSIX_LOCKING=1" ] + } else { + defines += [ "CHIP_SYSTEM_CONFIG_POSIX_LOCKING=0" ] + } + if (chip_system_config_locking == "freertos") { + defines += [ "CHIP_SYSTEM_CONFIG_FREERTOS_LOCKING=1" ] + } else { + defines += [ "CHIP_SYSTEM_CONFIG_FREERTOS_LOCKING=0" ] + } + if (chip_system_config_locking == "none") { + defines += [ "CHIP_SYSTEM_CONFIG_NO_LOCKING=1" ] + } else { + defines += [ "CHIP_SYSTEM_CONFIG_NO_LOCKING=0" ] + } + if (chip_system_config_provide_statistics) { + defines += [ "CHIP_SYSTEM_CONFIG_PROVIDE_STATISTICS=1" ] + } else { + defines += [ "CHIP_SYSTEM_CONFIG_PROVIDE_STATISTICS=0" ] + } + if (chip_system_config_clock == "clock_gettime") { + defines += [ "HAVE_CLOCK_GETTIME=1" ] + defines += [ "HAVE_CLOCK_SETTIME=1" ] + } + if (chip_system_config_clock == "gettimeofday") { + defines += [ "HAVE_GETTIMEOFDAY=1" ] + } +} + +source_set("system_config_header") { + sources = [ "SystemConfig.h" ] + + public_configs = [ ":system_config" ] +} diff --git a/src/system/system.gni b/src/system/system.gni new file mode 100644 index 00000000000000..6f6d0b52efac28 --- /dev/null +++ b/src/system/system.gni @@ -0,0 +1,51 @@ +# Copyright (c) 2020 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +declare_args() { + # Build tests. + chip_system_config_test = true + + # Use the lwIP library. + chip_system_config_use_lwip = current_os == "freertos" + + # Use BSD/POSIX socket API. + chip_system_config_use_sockets = current_os != "freertos" + + # Mutex implementation: posix, freertos, none. + chip_system_config_locking = "" + + # Clock implementation: clock_gettime, gettimeofday + chip_system_config_clock = "clock_gettime" + + # Enable metrics collection. + chip_system_config_provide_statistics = true +} + +if (chip_system_config_locking == "") { + if (current_os != "freertos") { + chip_system_config_locking = "posix" + } else { + chip_system_config_locking = "none" + } +} + +assert(chip_system_config_locking == "posix" || + chip_system_config_locking == "freertos" || + chip_system_config_locking == "none", + "Please select a valid mutex implementation: posix, freertos, none") + +assert( + chip_system_config_clock == "clock_gettime" || + chip_system_config_clock == "gettimeofday", + "Please select a valid clock implementation: clock_gettime, gettimeofday")