Skip to content

Commit

Permalink
cmake: add reproducible build option (#1370)
Browse files Browse the repository at this point in the history
* cmake: add reproductible build option

* fix typo + add MSVC

* fix cmake format

* cmake: disable incremental build in reproducible mode

* fix

* cmake: fix format

* fix
  • Loading branch information
clementperon authored Jul 29, 2024
1 parent d21c05c commit 11eb010
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
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

0 comments on commit 11eb010

Please sign in to comment.