Skip to content
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

cmake: add reproducible build option #1370

Merged
merged 8 commits into from
Jul 29, 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
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ cmake_dependent_option(
option(PCAPPP_BUILD_TESTS "Build Tests" ${PCAPPP_MAIN_PROJECT})
option(PCAPPP_BUILD_COVERAGE "Generate Coverage Report" OFF)
option(PCAPPP_BUILD_FUZZERS "Build Fuzzers binaries" OFF)
option(PCAPPP_BUILD_REPRODUCIBLE "Build a reproducible version" OFF)

option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)

Expand Down Expand Up @@ -259,6 +260,23 @@ if(PCAPPP_TARGET_COMPILER_CLANG
add_compile_options(-Wall)
endif()

if(PCAPPP_BUILD_REPRODUCIBLE)
add_definitions(-DPCAPPP_BUILD_REPRODUCIBLE)
if(APPLE)
if(NOT $ENV{ZERO_AR_DATE})
message(FATAL_ERROR "You need to set `export ZERO_AR_DATE=1`")
endif()
elseif(MSVC)
message(FATAL_ERROR "Unsupported with MSVC compiler")
# Try to build a reproducible static library with MSVC doesn't work but this option should make it work for shared
# libraries or executables. add_compile_options(/Brepro) add_compile_options(/experimental:deterministic)
# add_link_options(/Brepro) add_link_options(/experimental:deterministic) add_link_options(/INCREMENTAL:NO)
else()
# We should not use __DATE__ nor __TIME__ in case of reproducible build
add_compile_options(-Wdate-time)
endif()
endif()

if(PCAPPP_BUILD_FUZZERS)
add_compile_options(-w)
endif()
Expand Down
7 changes: 7 additions & 0 deletions Common++/header/PcapPlusPlusVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,17 @@ namespace pcpp
/**
* @return The build date and time in a format of "Mmm dd yyyy hh:mm:ss"
*/
#ifdef PCAPPP_BUILD_REPRODUCIBLE
inline std::string getBuildDateTime()
{
return " ";
}
#else
inline std::string getBuildDateTime()
{
return std::string(__DATE__) + " " + std::string(__TIME__);
}
#endif

/**
* @return The Git commit (revision) the binaries are built from
Expand Down
Loading