Skip to content

Commit 11eb010

Browse files
authored
cmake: add reproducible build option (#1370)
* cmake: add reproductible build option * fix typo + add MSVC * fix cmake format * cmake: disable incremental build in reproducible mode * fix * cmake: fix format * fix
1 parent d21c05c commit 11eb010

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ cmake_dependent_option(
101101
option(PCAPPP_BUILD_TESTS "Build Tests" ${PCAPPP_MAIN_PROJECT})
102102
option(PCAPPP_BUILD_COVERAGE "Generate Coverage Report" OFF)
103103
option(PCAPPP_BUILD_FUZZERS "Build Fuzzers binaries" OFF)
104+
option(PCAPPP_BUILD_REPRODUCIBLE "Build a reproducible version" OFF)
104105

105106
option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)
106107

@@ -259,6 +260,23 @@ if(PCAPPP_TARGET_COMPILER_CLANG
259260
add_compile_options(-Wall)
260261
endif()
261262

263+
if(PCAPPP_BUILD_REPRODUCIBLE)
264+
add_definitions(-DPCAPPP_BUILD_REPRODUCIBLE)
265+
if(APPLE)
266+
if(NOT $ENV{ZERO_AR_DATE})
267+
message(FATAL_ERROR "You need to set `export ZERO_AR_DATE=1`")
268+
endif()
269+
elseif(MSVC)
270+
message(FATAL_ERROR "Unsupported with MSVC compiler")
271+
# Try to build a reproducible static library with MSVC doesn't work but this option should make it work for shared
272+
# libraries or executables. add_compile_options(/Brepro) add_compile_options(/experimental:deterministic)
273+
# add_link_options(/Brepro) add_link_options(/experimental:deterministic) add_link_options(/INCREMENTAL:NO)
274+
else()
275+
# We should not use __DATE__ nor __TIME__ in case of reproducible build
276+
add_compile_options(-Wdate-time)
277+
endif()
278+
endif()
279+
262280
if(PCAPPP_BUILD_FUZZERS)
263281
add_compile_options(-w)
264282
endif()

Common++/header/PcapPlusPlusVersion.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,17 @@ namespace pcpp
3737
/**
3838
* @return The build date and time in a format of "Mmm dd yyyy hh:mm:ss"
3939
*/
40+
#ifdef PCAPPP_BUILD_REPRODUCIBLE
41+
inline std::string getBuildDateTime()
42+
{
43+
return " ";
44+
}
45+
#else
4046
inline std::string getBuildDateTime()
4147
{
4248
return std::string(__DATE__) + " " + std::string(__TIME__);
4349
}
50+
#endif
4451

4552
/**
4653
* @return The Git commit (revision) the binaries are built from

0 commit comments

Comments
 (0)