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
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "third_party/googletest"]
path = third_party/googletest
url = https://github.com/google/googletest.git
[submodule "third_party/antlr4"]
path = third_party/antlr4
url = https://github.com/antlr/antlr4.git
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ prune docs/env

include src/*
include src/antlr/*
recursive-include third_party *
graft third_party
global-exclude .git
exclude .gitmodules
exclude .clang-format
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ format-cpp:
build install clean develop:
$(IN_ENV) python setup.py $@

.PHONY: build-shared
build-shared:
$(IN_ENV) python setup.py build_ext --antlr-runtime=shared build

.PHONY: check
check:
$(IN_ENV) python setup.py check -m -s
Expand Down
21 changes: 20 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ def __init__(self, name, sourcedir='', prefix=''):


class CMakeBuild(build_ext):
user_options = [
(
'antlr-runtime=', None,
"Whether to use a 'static' or 'shared' ANTLR runtime."),
]

def copy_extensions_to_source(self):
original_extensions = list(self.extensions)
self.extensions = [
Expand Down Expand Up @@ -79,7 +85,8 @@ def build_extension(self, ext):
cmake_args = [
'-DCMAKE_INSTALL_PREFIX=' + extdir,
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
'-DPYTHON_EXECUTABLE=' + sys.executable
'-DPYTHON_EXECUTABLE=' + sys.executable,
'-DANTLR_RUNTIME_TYPE=' + self.antlr_runtime
]

cfg = 'Debug' if self.debug else 'Release'
Expand All @@ -92,6 +99,8 @@ def build_extension(self, ext):
env.get('CXXFLAGS', ''), self.distribution.get_version())
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
os.environ["CXXFLAGS"] = "-fPIC"
HackerFoo marked this conversation as resolved.
Show resolved Hide resolved
os.environ["CFLAGS"] = "-fPIC"
subprocess.check_call(
['cmake', ext.sourcedir] + cmake_args,
cwd=self.build_temp,
Expand All @@ -105,6 +114,16 @@ def build_extension(self, ext):
else:
super().build_extension(ext)

def initialize_options(self):
super().initialize_options()
self.antlr_runtime = 'static'

def finalize_options(self):
super().finalize_options()
assert self.antlr_runtime in [
'static', 'shared'
], 'Invalid antlr_runtime'
HackerFoo marked this conversation as resolved.
Show resolved Hide resolved


setuptools.setup(
name="fasm",
Expand Down
16 changes: 14 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,29 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../third_party/antlr4/

set(CMAKE_CXX_STANDARD 11)

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

# add external build for antlrcpp
include(ExternalAntlr4Cpp)
endif()

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

# set variable pointing to the antlr tool that supports C++
# this is not required if the jar file can be found under PATH environment
set(ANTLR_EXECUTABLE ${CMAKE_CURRENT_SOURCE_DIR}/../third_party/antlr4/antlr-4.9-complete.jar)
set(ANTLR_EXECUTABLE ${CMAKE_CURRENT_SOURCE_DIR}/../third_party/antlr4_lib/antlr-4.9-complete.jar)

# add macros to generate ANTLR Cpp code from grammar
find_package(ANTLR REQUIRED)

find_library(ANTLR4_RUNTIME NAMES antlr4-runtime REQUIRED)
if(ANTLR_RUNTIME_TYPE STREQUAL "static")
set(ANTLR4_RUNTIME antlr4_static)
else()
find_library(ANTLR4_RUNTIME NAMES antlr4-runtime REQUIRED)
endif()

# Unit testing library
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../third_party/googletest EXCLUDE_FROM_ALL googletest)
Expand Down
1 change: 1 addition & 0 deletions third_party/antlr4
Submodule antlr4 added at c79b0f
154 changes: 0 additions & 154 deletions third_party/antlr4/runtime/Cpp/cmake/ExternalAntlr4Cpp.cmake

This file was deleted.

124 changes: 0 additions & 124 deletions third_party/antlr4/runtime/Cpp/cmake/FindANTLR.cmake

This file was deleted.

Loading