Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[antlr-cpp-runtime]failed to compile the runtime when use ccache and ExternalAntlr4Cpp. #3930

Open
hagen666 opened this issue Oct 17, 2022 · 3 comments

Comments

@hagen666
Copy link

hagen666 commented Oct 17, 2022

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.

 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:

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
# Just g++-5.0 and greater contain <codecvt> header. (test in ubuntu)
if(NOT (GCC_VERSION VERSION_GREATER 5.0 OR GCC_VERSION VERSION_EQUAL 5.0))
message(FATAL_ERROR "${PROJECT_NAME} requires g++ 5.0 or greater.")
endif ()

as the same in v4.10.1:
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Intel")
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
# Just g++-5.0 and greater contain <codecvt> header. (test in ubuntu)
if(NOT (GCC_VERSION VERSION_GREATER 5.0 OR GCC_VERSION VERSION_EQUAL 5.0))
message(FATAL_ERROR "${PROJECT_NAME} requires g++ 5.0 or greater.")
endif ()

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)
@hagen666
Copy link
Author

No one response?

@sheth-de
Copy link

Facing the same issue while using Antlr-4.x
The build fails with the error:

CMake Error at CMakeLists.txt:112 (message):
LIBANTLR4 requires g++ 5.0 or greater.

Is there a fix for this issue?

@hagen666
Copy link
Author

in runtime/Cpp/CMakeLists.txt, replace the 'GCC_VERSION' with 'CMAKE_CXX_COMPILER_VERSION'.

Facing the same issue while using Antlr-4.x The build fails with the error:

CMake Error at CMakeLists.txt:112 (message):
LIBANTLR4 requires g++ 5.0 or greater.

Is there a fix for this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants