Skip to content

Commit

Permalink
AVRO-4112: [C++][CMake] Do not find Boost when test is not built (#3293)
Browse files Browse the repository at this point in the history
  • Loading branch information
wgtmac authored Jan 18, 2025
1 parent f59db49 commit 1144cb7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
12 changes: 3 additions & 9 deletions lang/c++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,13 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR})

option(AVRO_BUILD_EXECUTABLES "Build executables" ON)
option(AVRO_BUILD_TESTS "Build tests" ON)
option(AVRO_USE_BOOST "Use Boost" OFF)

if (WIN32 AND NOT CYGWIN AND NOT MSYS)
add_definitions (/EHa)
add_definitions (
-DNOMINMAX
-DBOOST_REGEX_DYN_LINK
-DBOOST_FILESYSTEM_DYN_LINK
-DBOOST_SYSTEM_DYN_LINK
-DBOOST_IOSTREAMS_DYN_LINK
-DBOOST_PROGRAM_OPTIONS_DYN_LINK
-DBOOST_ALL_NO_LIB)
endif()

Expand All @@ -81,11 +78,8 @@ if (AVRO_ADD_PROTECTOR_FLAGS)
endif ()
endif ()

if (AVRO_BUILD_TESTS OR AVRO_BUILD_EXECUTABLES)
find_package (Boost 1.38 REQUIRED
COMPONENTS filesystem iostreams program_options system)
else ()
find_package (Boost 1.38 REQUIRED COMPONENTS iostreams)
if (AVRO_BUILD_TESTS OR AVRO_USE_BOOST)
find_package (Boost 1.38 REQUIRED COMPONENTS system)
endif ()

include(FetchContent)
Expand Down
10 changes: 5 additions & 5 deletions lang/c++/test/DataFileTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
* limitations under the License.
*/

#include <boost/filesystem.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int_distribution.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test.hpp>

#include <chrono>
#include <filesystem>
#include <thread>

#include <sstream>
Expand Down Expand Up @@ -199,7 +199,7 @@ class DataFileTest {
using Pair = pair<ValidSchema, GenericDatum>;

void testCleanup() {
BOOST_CHECK(boost::filesystem::remove(filename));
BOOST_CHECK(std::filesystem::remove(filename));
}

void testWrite() {
Expand Down Expand Up @@ -278,12 +278,12 @@ class DataFileTest {

void testTruncate() {
testWriteDouble();
uintmax_t size = boost::filesystem::file_size(filename);
uintmax_t size = std::filesystem::file_size(filename);
{
avro::DataFileWriter<Pair> df(filename, writerSchema, 100);
df.close();
}
uintmax_t new_size = boost::filesystem::file_size(filename);
uintmax_t new_size = std::filesystem::file_size(filename);
BOOST_CHECK(size > new_size);
}

Expand Down Expand Up @@ -471,7 +471,7 @@ class DataFileTest {
void testReaderSplits() {
boost::mt19937 random(static_cast<uint32_t>(time(nullptr)));
avro::DataFileReader<ComplexInteger> df(filename, writerSchema);
int length = static_cast<int>(boost::filesystem::file_size(filename));
int length = static_cast<int>(std::filesystem::file_size(filename));
int splits = 10;
int end = length; // end of split
int remaining = end; // bytes remaining
Expand Down
7 changes: 4 additions & 3 deletions lang/c++/test/StreamTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

#include "Exception.hh"
#include "Stream.hh"
#include "boost/filesystem.hpp"
#include <boost/test/included/unit_test.hpp>
#include <boost/test/parameterized_test.hpp>

#include <filesystem>

namespace avro {
namespace stream {

Expand Down Expand Up @@ -136,9 +137,9 @@ void testNonEmpty2(const TestData &td) {
static const char filename[] = "test_str.bin";

struct FileRemover {
const boost::filesystem::path file;
const std::filesystem::path file;
explicit FileRemover(const char *fn) : file(fn) {}
~FileRemover() { boost::filesystem::remove(file); }
~FileRemover() { std::filesystem::remove(file); }
};

template<typename V>
Expand Down

0 comments on commit 1144cb7

Please sign in to comment.