From 1bda584b7bf7595351424174bbd6a60b0d78c503 Mon Sep 17 00:00:00 2001 From: Axel Gembe Date: Sat, 17 Feb 2024 13:42:54 +0700 Subject: [PATCH] cmake: Make build reproducible across different build directories Without this, the usage of the __FILE__ macro leaves the build directory in the binary. When building the Python extension with build isolation enabled this would lead to random paths in the binary. --- core/CMakeLists.txt | 13 +++++++++++-- wrappers/python/CMakeLists.txt | 12 ++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 2afedb078a..938eb5941b 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -44,6 +44,17 @@ else() -Wall -Wextra -Wno-missing-braces -Werror=undef -Werror=return-type) endif() +include (CheckCXXCompilerFlag) + +# This is needed for reproducible builds across different build directories. +# Without this, the usage of the __FILE__ macro leaves the build directory in +# the binary. When building the Python extension with build isolation enabled +# this would lead to random paths in the binary. +set(FILE_PREFIX_ARG "-ffile-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=") +check_cxx_compiler_flag("${FILE_PREFIX_ARG}" HAS_FILE_PREFIX_ARG) +if(HAS_FILE_PREFIX_ARG) + set(ZXING_CORE_LOCAL_DEFINES ${ZXING_CORE_LOCAL_DEFINES} "${FILE_PREFIX_ARG}") +endif() ################# Source files @@ -458,8 +469,6 @@ target_compile_options (ZXing PRIVATE ${ZXING_CORE_LOCAL_DEFINES} ) -include (CheckCXXCompilerFlag) - target_compile_features(ZXing PUBLIC cxx_std_17) target_link_libraries (ZXing PRIVATE Threads::Threads) diff --git a/wrappers/python/CMakeLists.txt b/wrappers/python/CMakeLists.txt index 9610420485..1cb3fd749b 100644 --- a/wrappers/python/CMakeLists.txt +++ b/wrappers/python/CMakeLists.txt @@ -17,8 +17,16 @@ if (NOT hasParent) option (BUILD_WRITERS "Build with writer support (encoders)" ON) option (BUILD_READERS "Build with reader support (decoders)" ON) set(BUILD_DEPENDENCIES "AUTO") - if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/core) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/core ZXing EXCLUDE_FROM_ALL) + + set(CORE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/core) + if(IS_SYMLINK ${CORE_PATH}) + # This is needed because otherwise GCC resolves the symlink which causes paths to randomly + # be prefixed by /core or by /wrappers/python/core depending on include order. + set(CORE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../core) + endif() + + if(EXISTS ${CORE_PATH}) + add_subdirectory(${CORE_PATH} ZXing EXCLUDE_FROM_ALL) include(${CMAKE_CURRENT_SOURCE_DIR}/zxing.cmake) else() message(FATAL_ERROR "Unable to locate zxing source code") pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy