Skip to content

Commit 1bda584

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 1bda584

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-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: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,16 @@ if (NOT hasParent)
1717
option (BUILD_WRITERS "Build with writer support (encoders)" ON)
1818
option (BUILD_READERS "Build with reader support (decoders)" ON)
1919
set(BUILD_DEPENDENCIES "AUTO")
20-
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/core)
21-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/core ZXing EXCLUDE_FROM_ALL)
20+
21+
set(CORE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/core)
22+
if(IS_SYMLINK ${CORE_PATH})
23+
# This is needed because otherwise GCC resolves the symlink which causes paths to randomly
24+
# be prefixed by /core or by /wrappers/python/core depending on include order.
25+
set(CORE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../core)
26+
endif()
27+
28+
if(EXISTS ${CORE_PATH})
29+
add_subdirectory(${CORE_PATH} ZXing EXCLUDE_FROM_ALL)
2230
include(${CMAKE_CURRENT_SOURCE_DIR}/zxing.cmake)
2331
else()
2432
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