Skip to content

Commit c6e9f15

Browse files
authored
1021 Error when compiling on Mac with new boost (#1146)
- 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.
1 parent fc0ebaf commit c6e9f15

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

cpp/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ option(MEMILIO_ENABLE_PROFILING "Enable runtime performance profiling of memilio
2424

2525
mark_as_advanced(MEMILIO_USE_BUNDLED_SPDLOG MEMILIO_SANITIZE_ADDRESS MEMILIO_SANITIZE_UNDEFINED)
2626

27+
# try to treat AppleClang as Clang, but warn about missing support
28+
if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
29+
message(WARNING "The compiler ID \"AppleClang\" is not supported, trying to compile with \"Clang\" options.")
30+
set(CMAKE_CXX_COMPILER_ID "Clang")
31+
endif()
32+
2733
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
2834
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
2935

cpp/tests/test_abm_serialization.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "models/abm/person.h"
3333
#include "models/abm/trip_list.h"
3434
#include "models/abm/model.h"
35+
#include <cstddef>
3536

3637
#ifdef MEMILIO_HAS_JSONCPP
3738

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

127128
Json::Value testing_criteria;
128-
std::vector<bool> ages_bits(mio::abm::MAX_NUM_AGE_GROUPS, false);
129+
std::array<bool, mio::abm::MAX_NUM_AGE_GROUPS> ages_bits{}; // initialize to false
129130
ages_bits[i++] = true;
130131
testing_criteria["ages"]["bitset"] = mio::serialize_json(ages_bits).value();
131-
std::vector<bool> inf_st_bits((size_t)mio::abm::InfectionState::Count, false);
132+
std::array<bool, (size_t)mio::abm::InfectionState::Count> inf_st_bits{}; // initialize to false
132133
inf_st_bits[i++] = true;
133134
testing_criteria["infection_states"]["bitset"] = mio::serialize_json(inf_st_bits).value();
134135

cpp/thirdparty/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,12 @@ if(MEMILIO_USE_BUNDLED_BOOST)
9898
add_library(Boost::boost ALIAS boost)
9999
target_include_directories(boost SYSTEM INTERFACE $<BUILD_INTERFACE:${boost_SOURCE_DIR}>)
100100

101-
if (NOT MSVC)
102-
target_compile_options(boost INTERFACE "-Wno-c++20-attribute-extensions")
101+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
102+
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 14)
103+
target_compile_options(boost INTERFACE "-Wno-c++20-attribute-extensions")
104+
else()
105+
target_compile_options(boost INTERFACE "-Wno-c++20-extensions")
106+
endif()
103107
endif()
104108

105109
add_library(boost_disable_autolink INTERFACE)

0 commit comments

Comments
 (0)