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/pw_build_info/util.h 30 PUBLIC_INCLUDES 31 public 32 PUBLIC_DEPS 33 pw_span 34 PUBLIC_LINK_OPTIONS 35 -Wl,--build-id=sha1 36 SOURCES 37 build_id.cc 38 util.cc 39 PRIVATE_DEPS 40 pw_log 41 pw_preprocessor 42 pw_string 43 ) 44endif() 45 46# Automatically add the gnu build ID linker sections when building for Linux. 47# macOS and Windows executables are not supported, and embedded targets must 48# manually add the snippet to their linker script in a read-only section. 49if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") 50 target_link_options(pw_build_info.build_id 51 PUBLIC 52 "-T${CMAKE_CURRENT_SOURCE_DIR}/add_build_id_to_default_linker_script.ld" 53 "-L${CMAKE_CURRENT_SOURCE_DIR}" 54 ) 55endif() 56