[antlr-cpp-runtime]failed to compile the runtime when use ccache and ExternalAntlr4Cpp.
- Dominant language
- Java
- Stars
- 19k
- Forks
- 3.5k
- PR merge metrics
- No merged PRs in 30d
Description
target information: C++
antlr version: antlr 4.10
smallest possible grammar: None
### smallest possible code to reproduce:
when following environment was set, I cannot use ExternalAntlr4Cpp to compile the antlr_runtime:
It's a CentOS 7. The system's gcc is version 4.8.5, ccache version is v4.0 , and I installed gcc 7.3.0 using scl toolset.
```bash
export CCACHE_NOHASHDIR=1 && export GCC_HOME=/opt/rh/devtoolset-7/root/usr/ && export PATH=/opt/rh/devtoolset-7/root/usr/:$PATH && export ASM="${CCACHE_HOME}/bin/ccache ${GCC_HOME}/bin/gcc" && export CC="${CCACHE_HOME}/bin/ccache ${GCC_HOME}/bin/gcc" && export CXX="${CCACHE_HOME} ${GCC_HOME}/bin/g++"
```
It has an error:
```
CMake Error at CMakeLists.txt:114
LIBANTLR4 requires g++ 5.0 or greater.
```
I found the following code cannot get the version 7.3.0 in the latest version:
https://github.com/antlr/antlr4/blob/aa1f1f12a846846fcb78544bdb2ad135471376db/runtime/Cpp/CMakeLists.txt#L124-L130
as the same in v4.10.1:
https://github.com/antlr/antlr4/blob/44d87bc1d130c88aa452894aa5f7e2f710f68253/runtime/Cpp/CMakeLists.txt#L110-L116
Here the variable value of `CMAKE_CXX_COMPILER` is the path to ccache(ccache's version is 4.0), and the gcc is in the variable `CMAKE_CXX_COMPILER_ARG1`. The variable `GCC_VERSION` here may be empty.
### expected behavior:
ExternalAntlr4Cpp can work when using ccache.
### a possible solution:
use `CMAKE_CXX_COMPILER_VERSION` other than `${CMAKE_CXX_COMPILER} -dumpversion`
When the file changed, the behavior is normal:
```
if(NOT (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 5.0))
message(FATAL_ERROR "${PROJECT_NAME} requires g++ 5.0 or greater.")
endif ()
```
### reference:
reference 1 Check GCC minor: https://stackoverflow.com/questions/4058565/check-gcc-minor-in-cmake
reference 2 How to use ccache with cmake:https://stackoverflow.com/questions/1815688/how-to-use-ccache-with-cmake
### some code segment
Addition cmake file segment:
```
set(ANTLR4_ZIP_REPOSITORY ${CMAKE_SOURCE_DIR}/3rdparty/antlr4-4.10.1.zip)
set(ANTLR4_CMAKE_ROOT ${PROJECT_SOURCE_DIR}/deps/antlr4-4.10.1/runtime/Cpp/cmake)
set(ANTLR_EXECUTABLE ${CMAKE_SOURCE_DIR}/3rdparty/antlr4-4.10.1-complete.jar)
if ((NOT EXISTS ${ANTLR4_CMAKE_ROOT}))
if ((NOT EXISTS ${ANTLR4_ZIP_REPOSITORY}))
message(fatal_error "cannot find dependency antlr4 in the path ${ANTLR4_ZIP_REPOSITORY}.")
endif()
execute_process(
COMMAND unzip -o ${ANTLR4_ZIP_REPOSITORY} "*.cmake" -d ${PROJECT_SOURCE_DIR}/deps/
)
endif()
list(APPEND CMAKE_MODULE_PATH ${ANTLR4_CMAKE_ROOT})
add_definitions(-DANTLR4CPP_STATIC)
set(ANTLR_BUILD_CPP_TESTS OFF)
set(ANTLR4_WITH_STATIC_CRT OFF)
include(ExternalAntlr4Cpp)
include_directories(${ANTLR4_INCLUDE_DIRS})
```
and then link antlr4_static to the project:
```
target_link_libraries(${Program_NAME} antlr4_static)
```
Contributor guide
Research direction
Start in runtime/Cpp/CMakeLists.txt, around the compiler-version check referenced in the issue, and review how CMake identifies ccache through CMAKE_CXX_COMPILER and CMAKE_CXX_COMPILER_ARG1. Reproduce the ExternalAntlr4Cpp configuration with ccache and the CentOS 7 toolset, then verify that the supported compiler is detected and the runtime configures successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, cpp
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 28/100