1# Copyright 2022 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 15include($ENV{PW_ROOT}/pw_build/pigweed.cmake) 16 17# GNU build IDs aren't supported by Windows and macOS. 18if(("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") OR 19 ("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")) 20 pw_add_error_target(pw_build_info.build_id 21 MESSAGE 22 "Attempted to build the pw_build_info.build_id for an unsupported system " 23 "(${CMAKE_SYSTEM_NAME})." 24 ) 25else() 26 pw_add_library(pw_build_info.build_id STATIC 27 HEADERS 28 public/pw_build_info/build_id.h 29 PUBLIC_INCLUDES 30 public 31 PUBLIC_DEPS 32 pw_span 33 PUBLIC_LINK_OPTIONS 34 -Wl,--build-id=sha1 35 SOURCES 36 build_id.cc 37 PRIVATE_DEPS 38 pw_preprocessor 39 ) 40endif() 41 42# Automatically add the gnu build ID linker sections when building for Linux. 43# macOS and Windows executables are not supported, and embedded targets must 44# manually add the snippet to their linker script in a read-only section. 45if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") 46 target_link_options(pw_build_info.build_id 47 PUBLIC 48 "-T${CMAKE_CURRENT_SOURCE_DIR}/add_build_id_to_default_linker_script.ld" 49 "-L${CMAKE_CURRENT_SOURCE_DIR}" 50 ) 51endif() 52