1# Copyright 2020 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://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, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14 15# Do not rely on the PW_ROOT environment variable being set through bootstrap. 16# Regardless of whether it's set or not the following include will ensure it is. 17include(${CMAKE_CURRENT_LIST_DIR}/../../pw_build/pigweed.cmake) 18 19include($ENV{PW_ROOT}/pw_assert/backend.cmake) 20include($ENV{PW_ROOT}/pw_async2/backend.cmake) 21include($ENV{PW_ROOT}/pw_chrono/backend.cmake) 22include($ENV{PW_ROOT}/pw_log/backend.cmake) 23include($ENV{PW_ROOT}/pw_perf_test/backend.cmake) 24include($ENV{PW_ROOT}/pw_rpc/system_server/backend.cmake) 25include($ENV{PW_ROOT}/pw_sync/backend.cmake) 26include($ENV{PW_ROOT}/pw_sys_io/backend.cmake) 27include($ENV{PW_ROOT}/pw_thread/backend.cmake) 28include($ENV{PW_ROOT}/pw_trace/backend.cmake) 29 30set(CMAKE_C_COMPILER clang) 31set(CMAKE_CXX_COMPILER clang++) 32 33pw_add_global_compile_options(-std=c++20 LANGUAGES CXX) 34 35# Configure backend for assert facade. 36pw_set_backend(pw_assert.check pw_assert.print_and_abort_check_backend) 37pw_set_backend(pw_assert.assert pw_assert.print_and_abort_assert_backend) 38 39# Configure backend for async dispatcher facade 40pw_set_backend(pw_async2.dispatcher pw_async2_basic.dispatcher_backend) 41 42# Configure backend for logging facade. 43pw_set_backend(pw_log pw_log_basic) 44 45# Configure backends for pw_sync's facades. 46pw_set_backend(pw_sync.interrupt_spin_lock pw_sync_stl.interrupt_spin_lock) 47pw_set_backend(pw_sync.binary_semaphore pw_sync_stl.binary_semaphore_backend) 48pw_set_backend(pw_sync.counting_semaphore 49 pw_sync_stl.counting_semaphore_backend) 50pw_set_backend(pw_sync.mutex pw_sync_stl.mutex_backend) 51pw_set_backend(pw_sync.timed_mutex pw_sync_stl.timed_mutex_backend) 52pw_set_backend(pw_sync.thread_notification 53 pw_sync.binary_semaphore_thread_notification_backend) 54pw_set_backend(pw_sync.timed_thread_notification 55 pw_sync.binary_semaphore_timed_thread_notification_backend) 56 57# Configure backend for pw_sys_io facade. 58pw_set_backend(pw_sys_io pw_sys_io_stdio) 59 60# Configure backend for pw_rpc_system_server. 61pw_set_backend(pw_rpc.system_server targets.host.system_rpc_server) 62# TODO(hepler): set config to use global mutex 63 64# Configure backend for pw_chrono's facades. 65pw_set_backend(pw_chrono.system_clock pw_chrono_stl.system_clock) 66pw_set_backend(pw_chrono.system_timer pw_chrono_stl.system_timer) 67 68# Configure backend for pw_perf_test's facade 69pw_set_backend(pw_perf_test.TIMER_INTERFACE_BACKEND pw_perf_test.chrono_timer) 70 71# Configure backends for pw_thread's facades. 72pw_set_backend(pw_thread.id pw_thread_stl.id) 73pw_set_backend(pw_thread.yield pw_thread_stl.yield) 74pw_set_backend(pw_thread.sleep pw_thread_stl.sleep) 75pw_set_backend(pw_thread.thread pw_thread_stl.thread) 76pw_set_backend(pw_thread.test_thread_context pw_thread_stl.test_thread_context) 77 78# TODO(ewout): Migrate this to match GN's tokenized trace setup. 79pw_set_backend(pw_trace pw_trace.null) 80 81if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") 82 # The CIPD provided Clang/LLVM toolchain must link against the matched 83 # libc++ which is also from CIPD. However, by default, Clang on Mac (but 84 # not on Linux) will fall back to the system libc++, which is 85 # incompatible due to an ABI change. 86 # 87 # Pull the appropriate paths from our Pigweed env setup. 88 set(CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT} -nostdlib++ $ENV{PW_PIGWEED_CIPD_INSTALL_DIR}/lib/libc++.a") 89 90 # macOS uses llvm-libtool-darwin, which has different behavior. 91 set(LIBTOOL_TOOL llvm-libtool-darwin) 92 set(CMAKE_C_ARCHIVE_CREATE "${LIBTOOL_TOOL} -static -no_warning_for_no_symbols -o <TARGET> <LINK_FLAGS> <OBJECTS>") 93 set(CMAKE_CXX_ARCHIVE_CREATE "${LIBTOOL_TOOL} -static -no_warning_for_no_symbols -o <TARGET> <LINK_FLAGS> <OBJECTS>") 94elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") 95 # Use the CIPD provided sysroot to make host builds more hermetic. 96 set(CMAKE_SYSROOT "$ENV{PW_PIGWEED_CIPD_INSTALL_DIR}/clang_sysroot") 97endif() 98 99set(pw_build_WARNINGS 100 pw_build.strict_warnings 101 pw_build.extra_strict_warnings 102 pw_build.pedantic_warnings 103 CACHE STRING "" FORCE 104) 105