diff --git a/CMakeLists.txt b/CMakeLists.txt index 9231ce4..f1785ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,17 @@ else() FetchContent_Declare(antlr4 ${_antlr_fetch_args}) FetchContent_MakeAvailable(antlr4) + # The runtime forgets some standard #includes ( for one), which newer + # standard libraries, notably Visual C++'s, no longer paper over. Supply them. + if(TARGET antlr4_static) + set(_compat "${CMAKE_CURRENT_SOURCE_DIR}/cmake/antlr_runtime_compat.h") + if(MSVC) + target_compile_options(antlr4_static PRIVATE "/FI${_compat}") + else() + target_compile_options(antlr4_static PRIVATE -include "${_compat}") + endif() + endif() + set(ANTLRLAB_RUNTIME_LIBS antlr4_static) set(ANTLRLAB_RUNTIME_INCLUDES "${antlr4_SOURCE_DIR}/runtime/Cpp/runtime/src") set(ANTLRLAB_RUNTIME_DEFS ANTLR4CPP_STATIC) diff --git a/cmake/antlr_runtime_compat.h b/cmake/antlr_runtime_compat.h new file mode 100644 index 0000000..848582a --- /dev/null +++ b/cmake/antlr_runtime_compat.h @@ -0,0 +1,38 @@ +// Force-included into the ANTLR C++ runtime's own build (see CMakeLists.txt). +// +// ANTLR 4.13's sources use some standard library facilities (std::chrono in +// ProfilingATNSimulator.cpp, for one) without including the header that +// declares them. That only worked because older standard libraries included +// those headers indirectly; newer Visual C++ versions no longer do, and the +// build fails with errors like "'high_resolution_clock': is not a class or +// namespace name". Including them up front is harmless everywhere else. +#pragma once + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include