Skip to content

Commit

Permalink
Add SystemConfig to GN build
Browse files Browse the repository at this point in the history
Not all options are configurable through GN args yet, just a few
examples.
  • Loading branch information
mspang committed Jun 23, 2020
1 parent f792578 commit 2680625
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 0 deletions.
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions build/tests.gni
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@
declare_args() {
# Enable building tests.
chip_build_tests = true

# Enable use of nlfaultinjection.
chip_with_nlfaultinjection = true
}
17 changes: 17 additions & 0 deletions src/BUILD.gn
Original file line number Diff line number Diff line change
@@ -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 = [ "." ]
}
106 changes: 106 additions & 0 deletions src/system/BUILD.gn
Original file line number Diff line number Diff line change
@@ -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" ]
}
51 changes: 51 additions & 0 deletions src/system/system.gni
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 2680625

Please sign in to comment.