Skip to content

Commit

Permalink
Statically build and link the ANTLR4 runtime.
Browse files Browse the repository at this point in the history
Signed-off-by: Dusty DeWeese <[email protected]>
  • Loading branch information
HackerFoo committed Dec 15, 2020
1 parent 700a4d2 commit 8530708
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
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")
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

0 comments on commit 8530708

Please sign in to comment.