Skip to content

Commit

Permalink
1021 Error when compiling on Mac with new boost (#1146)
Browse files Browse the repository at this point in the history
- Change compiler flag disabling warnings from boost depending on Clang version.
- Treat compiler ID "AppleClang" as "Clang" and warn about it.
- Change two occurrences of vector\<bool\> to array to sidestep a libc++ extension for const bool references in vector.
  • Loading branch information
reneSchm authored Nov 26, 2024
1 parent fc0ebaf commit c6e9f15
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
6 changes: 6 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ option(MEMILIO_ENABLE_PROFILING "Enable runtime performance profiling of memilio

mark_as_advanced(MEMILIO_USE_BUNDLED_SPDLOG MEMILIO_SANITIZE_ADDRESS MEMILIO_SANITIZE_UNDEFINED)

# try to treat AppleClang as Clang, but warn about missing support
if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
message(WARNING "The compiler ID \"AppleClang\" is not supported, trying to compile with \"Clang\" options.")
set(CMAKE_CXX_COMPILER_ID "Clang")
endif()

set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

Expand Down
5 changes: 3 additions & 2 deletions cpp/tests/test_abm_serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "models/abm/person.h"
#include "models/abm/trip_list.h"
#include "models/abm/model.h"
#include <cstddef>

#ifdef MEMILIO_HAS_JSONCPP

Expand Down Expand Up @@ -125,10 +126,10 @@ TEST(TestAbmSerialization, TestingScheme)
unsigned i = 1; // counter s.t. members have different values

Json::Value testing_criteria;
std::vector<bool> ages_bits(mio::abm::MAX_NUM_AGE_GROUPS, false);
std::array<bool, mio::abm::MAX_NUM_AGE_GROUPS> ages_bits{}; // initialize to false
ages_bits[i++] = true;
testing_criteria["ages"]["bitset"] = mio::serialize_json(ages_bits).value();
std::vector<bool> inf_st_bits((size_t)mio::abm::InfectionState::Count, false);
std::array<bool, (size_t)mio::abm::InfectionState::Count> inf_st_bits{}; // initialize to false
inf_st_bits[i++] = true;
testing_criteria["infection_states"]["bitset"] = mio::serialize_json(inf_st_bits).value();

Expand Down
8 changes: 6 additions & 2 deletions cpp/thirdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ if(MEMILIO_USE_BUNDLED_BOOST)
add_library(Boost::boost ALIAS boost)
target_include_directories(boost SYSTEM INTERFACE $<BUILD_INTERFACE:${boost_SOURCE_DIR}>)

if (NOT MSVC)
target_compile_options(boost INTERFACE "-Wno-c++20-attribute-extensions")
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 14)
target_compile_options(boost INTERFACE "-Wno-c++20-attribute-extensions")
else()
target_compile_options(boost INTERFACE "-Wno-c++20-extensions")
endif()
endif()

add_library(boost_disable_autolink INTERFACE)
Expand Down

0 comments on commit c6e9f15

Please sign in to comment.