• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_system/backend.cmake)
28include($ENV{PW_ROOT}/pw_thread/backend.cmake)
29include($ENV{PW_ROOT}/pw_trace/backend.cmake)
30include($ENV{PW_ROOT}/pw_trace_tokenized/backend.cmake)
31
32set(CMAKE_C_COMPILER clang)
33set(CMAKE_CXX_COMPILER clang++)
34
35pw_add_global_compile_options(-std=c++20 LANGUAGES CXX)
36
37# Configure backend for assert facade.
38pw_set_backend(pw_assert.check pw_assert.print_and_abort_check_backend)
39pw_set_backend(pw_assert.assert pw_assert.print_and_abort_assert_backend)
40
41# Configure backend for async dispatcher facade
42pw_set_backend(pw_async2.dispatcher pw_async2_epoll.dispatcher_backend)
43
44# Configure backend for logging facade.
45pw_set_backend(pw_log pw_log_basic)
46
47# Configure backends for pw_sync's facades.
48pw_set_backend(pw_sync.interrupt_spin_lock pw_sync_stl.interrupt_spin_lock)
49pw_set_backend(pw_sync.binary_semaphore pw_sync_stl.binary_semaphore_backend)
50pw_set_backend(pw_sync.counting_semaphore
51               pw_sync_stl.counting_semaphore_backend)
52pw_set_backend(pw_sync.mutex pw_sync_stl.mutex_backend)
53pw_set_backend(pw_sync.timed_mutex pw_sync_stl.timed_mutex_backend)
54pw_set_backend(pw_sync.thread_notification
55               pw_sync.binary_semaphore_thread_notification_backend)
56pw_set_backend(pw_sync.timed_thread_notification
57               pw_sync.binary_semaphore_timed_thread_notification_backend)
58
59# Configure backend for pw_sys_io facade.
60pw_set_backend(pw_sys_io pw_sys_io_stdio)
61
62# Configure backend for pw_rpc_system_server.
63pw_set_backend(pw_rpc.system_server targets.host.system_rpc_server)
64# TODO(hepler): set config to use global mutex
65
66# Configure backend for pw_chrono's facades.
67pw_set_backend(pw_chrono.system_clock pw_chrono_stl.system_clock)
68pw_set_backend(pw_chrono.system_timer pw_chrono_stl.system_timer)
69
70# Configure backend for pw_perf_test's facade
71pw_set_backend(pw_perf_test.TIMER_INTERFACE_BACKEND pw_perf_test.chrono_timer)
72
73# Configure backends for pw_thread's facades.
74pw_set_backend(pw_thread.id pw_thread_stl.id)
75pw_set_backend(pw_thread.yield pw_thread_stl.yield)
76pw_set_backend(pw_thread.sleep pw_thread_stl.sleep)
77pw_set_backend(pw_thread.thread pw_thread_stl.thread)
78pw_set_backend(pw_thread.thread_creation pw_thread_stl.thread_creation)
79pw_set_backend(pw_thread.test_thread_context pw_thread_stl.test_thread_context)
80pw_set_backend(pw_thread.thread_iteration pw_thread_stl.thread_iteration)
81
82# Configure backends for pw_system
83pw_set_backend(pw_system.target_hooks pw_system.stl_target_hooks)
84pw_set_backend(pw_system.rpc_server pw_system.hdlc_rpc_server)
85pw_set_backend(pw_system.io pw_system.sys_io_target_io)
86
87# Configure backends for pw_trace
88pw_set_backend(pw_trace pw_trace_tokenized)
89# Maybe this should just be a facade?
90set(pw_trace_tokenizer_time pw_trace_tokenized.host_trace_time CACHE STRING "Tokenizer trace time implementation" FORCE)
91
92if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
93    # The CIPD provided Clang/LLVM toolchain must link against the matched
94    # libc++ which is also from CIPD. However, by default, Clang on Mac (but
95    # not on Linux) will fall back to the system libc++, which is
96    # incompatible due to an ABI change.
97    #
98    # Pull the appropriate paths from our Pigweed env setup.
99    set(CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT} -nostdlib++ $ENV{PW_PIGWEED_CIPD_INSTALL_DIR}/lib/libc++.a")
100
101    # macOS uses llvm-libtool-darwin, which has different behavior.
102    set(LIBTOOL_TOOL llvm-libtool-darwin)
103    set(CMAKE_C_ARCHIVE_CREATE "${LIBTOOL_TOOL} -static -no_warning_for_no_symbols -o <TARGET> <LINK_FLAGS> <OBJECTS>")
104    set(CMAKE_CXX_ARCHIVE_CREATE "${LIBTOOL_TOOL} -static -no_warning_for_no_symbols -o <TARGET> <LINK_FLAGS> <OBJECTS>")
105elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
106    # Use the CIPD provided sysroot to make host builds more hermetic.
107    set(CMAKE_SYSROOT "$ENV{PW_PIGWEED_CIPD_INSTALL_DIR}/clang_sysroot")
108endif()
109
110# Explicitly use lld to link.
111foreach(TYPE IN ITEMS EXE SHARED MODULE)
112    set(CMAKE_${TYPE}_LINKER_FLAGS_INIT "${CMAKE_${TYPE}_LINKER_FLAGS_INIT} -fuse-ld=lld")
113endforeach()
114
115set(pw_build_WARNINGS
116    pw_build.strict_warnings
117    pw_build.extra_strict_warnings
118    pw_build.pedantic_warnings
119  CACHE STRING "" FORCE
120)
121