xref: /aosp_15_r20/external/pigweed/pw_toolchain/host_clang/toolchain.cmake (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1*61c4878aSAndroid Build Coastguard Worker# Copyright 2020 The Pigweed Authors
2*61c4878aSAndroid Build Coastguard Worker#
3*61c4878aSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4*61c4878aSAndroid Build Coastguard Worker# use this file except in compliance with the License. You may obtain a copy of
5*61c4878aSAndroid Build Coastguard Worker# the License at
6*61c4878aSAndroid Build Coastguard Worker#
7*61c4878aSAndroid Build Coastguard Worker#     https://www.apache.org/licenses/LICENSE-2.0
8*61c4878aSAndroid Build Coastguard Worker#
9*61c4878aSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
10*61c4878aSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11*61c4878aSAndroid Build Coastguard Worker# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12*61c4878aSAndroid Build Coastguard Worker# License for the specific language governing permissions and limitations under
13*61c4878aSAndroid Build Coastguard Worker# the License.
14*61c4878aSAndroid Build Coastguard Worker
15*61c4878aSAndroid Build Coastguard Worker# Do not rely on the PW_ROOT environment variable being set through bootstrap.
16*61c4878aSAndroid Build Coastguard Worker# Regardless of whether it's set or not the following include will ensure it is.
17*61c4878aSAndroid Build Coastguard Workerinclude(${CMAKE_CURRENT_LIST_DIR}/../../pw_build/pigweed.cmake)
18*61c4878aSAndroid Build Coastguard Worker
19*61c4878aSAndroid Build Coastguard Workerinclude($ENV{PW_ROOT}/pw_assert/backend.cmake)
20*61c4878aSAndroid Build Coastguard Workerinclude($ENV{PW_ROOT}/pw_async2/backend.cmake)
21*61c4878aSAndroid Build Coastguard Workerinclude($ENV{PW_ROOT}/pw_chrono/backend.cmake)
22*61c4878aSAndroid Build Coastguard Workerinclude($ENV{PW_ROOT}/pw_log/backend.cmake)
23*61c4878aSAndroid Build Coastguard Workerinclude($ENV{PW_ROOT}/pw_perf_test/backend.cmake)
24*61c4878aSAndroid Build Coastguard Workerinclude($ENV{PW_ROOT}/pw_rpc/system_server/backend.cmake)
25*61c4878aSAndroid Build Coastguard Workerinclude($ENV{PW_ROOT}/pw_sync/backend.cmake)
26*61c4878aSAndroid Build Coastguard Workerinclude($ENV{PW_ROOT}/pw_sys_io/backend.cmake)
27*61c4878aSAndroid Build Coastguard Workerinclude($ENV{PW_ROOT}/pw_system/backend.cmake)
28*61c4878aSAndroid Build Coastguard Workerinclude($ENV{PW_ROOT}/pw_thread/backend.cmake)
29*61c4878aSAndroid Build Coastguard Workerinclude($ENV{PW_ROOT}/pw_trace/backend.cmake)
30*61c4878aSAndroid Build Coastguard Workerinclude($ENV{PW_ROOT}/pw_trace_tokenized/backend.cmake)
31*61c4878aSAndroid Build Coastguard Worker
32*61c4878aSAndroid Build Coastguard Workerset(CMAKE_C_COMPILER clang)
33*61c4878aSAndroid Build Coastguard Workerset(CMAKE_CXX_COMPILER clang++)
34*61c4878aSAndroid Build Coastguard Worker
35*61c4878aSAndroid Build Coastguard Workerpw_add_global_compile_options(-std=c++20 LANGUAGES CXX)
36*61c4878aSAndroid Build Coastguard Worker
37*61c4878aSAndroid Build Coastguard Worker# Configure backend for assert facade.
38*61c4878aSAndroid Build Coastguard Workerpw_set_backend(pw_assert.check pw_assert.print_and_abort_check_backend)
39*61c4878aSAndroid Build Coastguard Workerpw_set_backend(pw_assert.assert pw_assert.print_and_abort_assert_backend)
40*61c4878aSAndroid Build Coastguard Worker
41*61c4878aSAndroid Build Coastguard Worker# Configure backend for async dispatcher facade
42*61c4878aSAndroid Build Coastguard Workerpw_set_backend(pw_async2.dispatcher pw_async2_epoll.dispatcher_backend)
43*61c4878aSAndroid Build Coastguard Worker
44*61c4878aSAndroid Build Coastguard Worker# Configure backend for logging facade.
45*61c4878aSAndroid Build Coastguard Workerpw_set_backend(pw_log pw_log_basic)
46*61c4878aSAndroid Build Coastguard Worker
47*61c4878aSAndroid Build Coastguard Worker# Configure backends for pw_sync's facades.
48*61c4878aSAndroid Build Coastguard Workerpw_set_backend(pw_sync.interrupt_spin_lock pw_sync_stl.interrupt_spin_lock)
49*61c4878aSAndroid Build Coastguard Workerpw_set_backend(pw_sync.binary_semaphore pw_sync_stl.binary_semaphore_backend)
50*61c4878aSAndroid Build Coastguard Workerpw_set_backend(pw_sync.counting_semaphore
51*61c4878aSAndroid Build Coastguard Worker               pw_sync_stl.counting_semaphore_backend)
52*61c4878aSAndroid Build Coastguard Workerpw_set_backend(pw_sync.mutex pw_sync_stl.mutex_backend)
53*61c4878aSAndroid Build Coastguard Workerpw_set_backend(pw_sync.timed_mutex pw_sync_stl.timed_mutex_backend)
54*61c4878aSAndroid Build Coastguard Workerpw_set_backend(pw_sync.thread_notification
55*61c4878aSAndroid Build Coastguard Worker               pw_sync.binary_semaphore_thread_notification_backend)
56*61c4878aSAndroid Build Coastguard Workerpw_set_backend(pw_sync.timed_thread_notification
57*61c4878aSAndroid Build Coastguard Worker               pw_sync.binary_semaphore_timed_thread_notification_backend)
58*61c4878aSAndroid Build Coastguard Worker
59*61c4878aSAndroid Build Coastguard Worker# Configure backend for pw_sys_io facade.
60*61c4878aSAndroid Build Coastguard Workerpw_set_backend(pw_sys_io pw_sys_io_stdio)
61*61c4878aSAndroid Build Coastguard Worker
62*61c4878aSAndroid Build Coastguard Worker# Configure backend for pw_rpc_system_server.
63*61c4878aSAndroid Build Coastguard Workerpw_set_backend(pw_rpc.system_server targets.host.system_rpc_server)
64*61c4878aSAndroid Build Coastguard Worker# TODO(hepler): set config to use global mutex
65*61c4878aSAndroid Build Coastguard Worker
66*61c4878aSAndroid Build Coastguard Worker# Configure backend for pw_chrono's facades.
67*61c4878aSAndroid Build Coastguard Workerpw_set_backend(pw_chrono.system_clock pw_chrono_stl.system_clock)
68*61c4878aSAndroid Build Coastguard Workerpw_set_backend(pw_chrono.system_timer pw_chrono_stl.system_timer)
69*61c4878aSAndroid Build Coastguard Worker
70*61c4878aSAndroid Build Coastguard Worker# Configure backend for pw_perf_test's facade
71*61c4878aSAndroid Build Coastguard Workerpw_set_backend(pw_perf_test.TIMER_INTERFACE_BACKEND pw_perf_test.chrono_timer)
72*61c4878aSAndroid Build Coastguard Worker
73*61c4878aSAndroid Build Coastguard Worker# Configure backends for pw_thread's facades.
74*61c4878aSAndroid Build Coastguard Workerpw_set_backend(pw_thread.id pw_thread_stl.id)
75*61c4878aSAndroid Build Coastguard Workerpw_set_backend(pw_thread.yield pw_thread_stl.yield)
76*61c4878aSAndroid Build Coastguard Workerpw_set_backend(pw_thread.sleep pw_thread_stl.sleep)
77*61c4878aSAndroid Build Coastguard Workerpw_set_backend(pw_thread.thread pw_thread_stl.thread)
78*61c4878aSAndroid Build Coastguard Workerpw_set_backend(pw_thread.test_thread_context pw_thread_stl.test_thread_context)
79*61c4878aSAndroid Build Coastguard Workerpw_set_backend(pw_thread.thread_iteration pw_thread_stl.thread_iteration)
80*61c4878aSAndroid Build Coastguard Worker
81*61c4878aSAndroid Build Coastguard Worker# Configure backends for pw_system
82*61c4878aSAndroid Build Coastguard Workerpw_set_backend(pw_system.target_hooks pw_system.stl_target_hooks)
83*61c4878aSAndroid Build Coastguard Workerpw_set_backend(pw_system.rpc_server pw_system.hdlc_rpc_server)
84*61c4878aSAndroid Build Coastguard Workerpw_set_backend(pw_system.io pw_system.sys_io_target_io)
85*61c4878aSAndroid Build Coastguard Worker
86*61c4878aSAndroid Build Coastguard Worker# Configure backends for pw_trace
87*61c4878aSAndroid Build Coastguard Workerpw_set_backend(pw_trace pw_trace_tokenized)
88*61c4878aSAndroid Build Coastguard Worker# Maybe this should just be a facade?
89*61c4878aSAndroid Build Coastguard Workerset(pw_trace_tokenizer_time pw_trace_tokenized.host_trace_time CACHE STRING "Tokenizer trace time implementation" FORCE)
90*61c4878aSAndroid Build Coastguard Worker
91*61c4878aSAndroid Build Coastguard Workerif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
92*61c4878aSAndroid Build Coastguard Worker    # The CIPD provided Clang/LLVM toolchain must link against the matched
93*61c4878aSAndroid Build Coastguard Worker    # libc++ which is also from CIPD. However, by default, Clang on Mac (but
94*61c4878aSAndroid Build Coastguard Worker    # not on Linux) will fall back to the system libc++, which is
95*61c4878aSAndroid Build Coastguard Worker    # incompatible due to an ABI change.
96*61c4878aSAndroid Build Coastguard Worker    #
97*61c4878aSAndroid Build Coastguard Worker    # Pull the appropriate paths from our Pigweed env setup.
98*61c4878aSAndroid Build Coastguard Worker    set(CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT} -nostdlib++ $ENV{PW_PIGWEED_CIPD_INSTALL_DIR}/lib/libc++.a")
99*61c4878aSAndroid Build Coastguard Worker
100*61c4878aSAndroid Build Coastguard Worker    # macOS uses llvm-libtool-darwin, which has different behavior.
101*61c4878aSAndroid Build Coastguard Worker    set(LIBTOOL_TOOL llvm-libtool-darwin)
102*61c4878aSAndroid Build Coastguard Worker    set(CMAKE_C_ARCHIVE_CREATE "${LIBTOOL_TOOL} -static -no_warning_for_no_symbols -o <TARGET> <LINK_FLAGS> <OBJECTS>")
103*61c4878aSAndroid Build Coastguard Worker    set(CMAKE_CXX_ARCHIVE_CREATE "${LIBTOOL_TOOL} -static -no_warning_for_no_symbols -o <TARGET> <LINK_FLAGS> <OBJECTS>")
104*61c4878aSAndroid Build Coastguard Workerelseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
105*61c4878aSAndroid Build Coastguard Worker    # Use the CIPD provided sysroot to make host builds more hermetic.
106*61c4878aSAndroid Build Coastguard Worker    set(CMAKE_SYSROOT "$ENV{PW_PIGWEED_CIPD_INSTALL_DIR}/clang_sysroot")
107*61c4878aSAndroid Build Coastguard Workerendif()
108*61c4878aSAndroid Build Coastguard Worker
109*61c4878aSAndroid Build Coastguard Worker# Explicitly use lld to link.
110*61c4878aSAndroid Build Coastguard Workerforeach(TYPE IN ITEMS EXE SHARED MODULE)
111*61c4878aSAndroid Build Coastguard Worker    set(CMAKE_${TYPE}_LINKER_FLAGS_INIT "${CMAKE_${TYPE}_LINKER_FLAGS_INIT} -fuse-ld=lld")
112*61c4878aSAndroid Build Coastguard Workerendforeach()
113*61c4878aSAndroid Build Coastguard Worker
114*61c4878aSAndroid Build Coastguard Workerset(pw_build_WARNINGS
115*61c4878aSAndroid Build Coastguard Worker    pw_build.strict_warnings
116*61c4878aSAndroid Build Coastguard Worker    pw_build.extra_strict_warnings
117*61c4878aSAndroid Build Coastguard Worker    pw_build.pedantic_warnings
118*61c4878aSAndroid Build Coastguard Worker  CACHE STRING "" FORCE
119*61c4878aSAndroid Build Coastguard Worker)
120