Skip to content

cmake: Make build reproducible across different build directories #730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
12 changes: 10 additions & 2 deletions wrappers/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this line, it occurred to me that is does not make any sense in current HEAD because core always exists. Then I realized: your function is not necessary at all. Simply do the IS_SYMLINK check on core (which will fail in an sdist build) and if it is a symlink, then hardcode the ../../core path. Less lines of code to worry about.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change, but maybe not today.

Copy link
Contributor Author

@EchterAgo EchterAgo Feb 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, I still kept the EXISTS check but made a variable CORE_PATH that is set conditionally based on whether ./core is a symlink.

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")
Expand Down
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