Skip to content

Commit 0ae543a

Browse files
committed
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.
1 parent 6faf0f8 commit 0ae543a

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

core/CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ else()
4444
-Wall -Wextra -Wno-missing-braces -Werror=undef -Werror=return-type)
4545
endif()
4646

47+
include (CheckCXXCompilerFlag)
48+
49+
# This is needed for reproducible builds across different build directories.
50+
# Without this, the usage of the __FILE__ macro leaves the build directory in
51+
# the binary. When building the Python extension with build isolation enabled
52+
# this would lead to random paths in the binary.
53+
set(FILE_PREFIX_ARG "-ffile-prefix-map=${CMAKE_CURRENT_SOURCE_DIR}=")
54+
check_cxx_compiler_flag("${FILE_PREFIX_ARG}" HAS_FILE_PREFIX_ARG)
55+
if(HAS_FILE_PREFIX_ARG)
56+
set(ZXING_CORE_LOCAL_DEFINES ${ZXING_CORE_LOCAL_DEFINES} "${FILE_PREFIX_ARG}")
57+
endif()
4758

4859
################# Source files
4960

@@ -458,8 +469,6 @@ target_compile_options (ZXing
458469
PRIVATE ${ZXING_CORE_LOCAL_DEFINES}
459470
)
460471

461-
include (CheckCXXCompilerFlag)
462-
463472
target_compile_features(ZXing PUBLIC cxx_std_17)
464473

465474
target_link_libraries (ZXing PRIVATE Threads::Threads)

wrappers/python/CMakeLists.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ project(ZXingPython)
44
set (pybind11_git_repo https://github.com/pybind/pybind11.git)
55
set (pybind11_git_rev v2.11.1)
66

7+
function(get_core_path REAL_PATH_VAR PATH)
8+
if(IS_SYMLINK "${PATH}")
9+
get_filename_component(COREPATH "${PATH}" REALPATH)
10+
set(${REAL_PATH_VAR} "${COREPATH}" PARENT_SCOPE)
11+
else()
12+
set(${REAL_PATH_VAR} "${PATH}" PARENT_SCOPE)
13+
endif()
14+
endfunction()
15+
716
# check if we are called from the top-level ZXing project
817
get_directory_property(hasParent PARENT_DIRECTORY)
918
if (NOT hasParent)
@@ -17,8 +26,11 @@ if (NOT hasParent)
1726
option (BUILD_WRITERS "Build with writer support (encoders)" ON)
1827
option (BUILD_READERS "Build with reader support (decoders)" ON)
1928
set(BUILD_DEPENDENCIES "AUTO")
20-
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/core)
21-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/core ZXing EXCLUDE_FROM_ALL)
29+
# This is needed because otherwise GCC resolves the symlink which causes paths to randomly
30+
# be prefixed by /core or by /wrappers/python/core depending on include order.
31+
get_core_path(CORE_REAL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/core)
32+
if(EXISTS ${CORE_REAL_PATH})
33+
add_subdirectory(${CORE_REAL_PATH} ZXing EXCLUDE_FROM_ALL)
2234
include(${CMAKE_CURRENT_SOURCE_DIR}/zxing.cmake)
2335
else()
2436
message(FATAL_ERROR "Unable to locate zxing source code")

0 commit comments

Comments
 (0)
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