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

Statically build and link the ANTLR4 runtime. #41

Merged
merged 12 commits into from
Dec 17, 2020
8 changes: 7 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../third_party/antlr4/

set(CMAKE_CXX_STANDARD 11)

# required if linking to static library
add_definitions(-DANTLR4CPP_STATIC)

# add external build for antlrcpp
include(ExternalAntlr4Cpp)

# add antrl4cpp artifacts to project environment
include_directories(${ANTLR4_INCLUDE_DIRS})

Expand All @@ -25,7 +31,7 @@ set(ANTLR_EXECUTABLE ${CMAKE_CURRENT_SOURCE_DIR}/../third_party/antlr4/antlr-4.9
# add macros to generate ANTLR Cpp code from grammar
find_package(ANTLR REQUIRED)

find_library(ANTLR4_RUNTIME NAMES antlr4-runtime REQUIRED)
set(ANTLR4_RUNTIME antlr4_static)

# Unit testing library
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../third_party/googletest EXCLUDE_FROM_ALL googletest)
Expand Down
5 changes: 3 additions & 2 deletions third_party/antlr4/runtime/Cpp/cmake/ExternalAntlr4Cpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ endif()
if(${CMAKE_GENERATOR} MATCHES ".* Makefiles")
# This avoids
# 'warning: jobserver unavailable: using -j1. Add '+' to parent make rule.'
set(ANTLR4_BUILD_COMMAND $(MAKE))
set(ANTLR4_BUILD_COMMAND $(MAKE) CXX_FLAGS="-fPIC" C_FLAGS="-fPIC")
HackerFoo marked this conversation as resolved.
Show resolved Hide resolved
elseif(${CMAKE_GENERATOR} MATCHES "Visual Studio.*")
set(ANTLR4_BUILD_COMMAND
${CMAKE_COMMAND}
Expand All @@ -68,7 +68,8 @@ else()
set(ANTLR4_BUILD_COMMAND
${CMAKE_COMMAND}
--build .
--target)
--target
-DCMAKE_POSITION_INDEPENDENT_CODE=ON)
endif()

if(NOT DEFINED ANTLR4_WITH_STATIC_CRT)
Expand Down