Fixed some cmake issues. Closes issue #13 and issue #8.

Additionally a warning was fixed (std::move prevents copy elision)
This commit is contained in:
Mike Lischke 2016-07-20 16:24:12 +02:00
parent 196e8ab53d
commit d46ef90aa0
5 changed files with 37 additions and 12 deletions

View File

@ -18,6 +18,8 @@ if(NOT WITH_DEMO)
FORCE)
endif(NOT WITH_DEMO)
option(WITH_LIBCXX "Building with clang++ and libc++(in Linux). To enable with: -DWITH_LIBCXX=On" On)
project(LIBANTLR4)
if(CMAKE_VERSION VERSION_EQUAL "3.0.0" OR
@ -36,11 +38,12 @@ if(APPLE)
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
endif()
find_package(Java REQUIRED)
file(STRINGS "VERSION" ANTLR_VERSION)
if (WITH_DEMO)
# Java is not necessary if building without demos.
find_package(Java REQUIRED)
if (NOT ANTLR_JAR_LOCATION)
message(FATAL_ERROR "Missing antlr4.jar location. You can specify it's path using: -DANTLR_JAR_LOCATION=<path>")
else()
@ -56,18 +59,21 @@ endif(WITH_DEMO)
set(MY_CXX_WARNING_FLAGS " -Wall -pedantic -W")
# Initialize CXXFLAGS.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11 ${MY_CXX_WARNING_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g -std=c++11 ${MY_CXX_WARNING_FLAGS}")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -Os -DNDEBUG -std=c++11 ${MY_CXX_WARNING_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG -std=c++11 ${MY_CXX_WARNING_FLGAS}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O2 -g -std=c++11 ${MY_CXX_WARNING_FLAGS}")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall ${MY_CXX_WARNING_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g ${MY_CXX_WARNING_FLAGS}")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -Os -DNDEBUG ${MY_CXX_WARNING_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG ${MY_CXX_WARNING_FLGAS}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O2 -g ${MY_CXX_WARNING_FLAGS}")
# Compiler-specific C++11 activation.
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
if (NOT (GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7))
message(FATAL_ERROR "${PROJECT_NAME} requires g++ 4.7 or greater.")
# 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 ()
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
@ -77,6 +83,10 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND CMAKE_SYSTEM_NAME MATCHES
if (NOT (CLANG_VERSION VERSION_GREATER 4.2.1 OR CLANG_VERSION VERSION_EQUAL 4.2.1))
message(FATAL_ERROR "${PROJECT_NAME} requires clang 4.2.1 or greater.")
endif ()
# You can use libc++ to compile this project when g++ is NOT greater than or equal to 5.0.
if (WITH_LIBCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
else ()
message(FATAL_ERROR "Your C++ compiler does not support C++11.")
endif ()

View File

@ -38,7 +38,7 @@ The minimum C++ version to compile the ANTLR C++ runtime with is C++11. The supp
Include the antlr4-runtime.h umbrella header in your target application to get everything needed to use the library.
If you are compiling with cmake, the minimum version required is cmake 3.3.
If you are compiling with cmake, the minimum version required is cmake 2.8.
#### Compiling on Windows
Simply open the VS solution (VS 2013+) and build it.

View File

@ -24,6 +24,16 @@ file(GLOB libantlrcpp_SRC
add_library(antlr4_shared SHARED ${libantlrcpp_SRC})
add_library(antlr4_static STATIC ${libantlrcpp_SRC})
set(LIB_OUTPUT_DIR "${CMAKE_HOME_DIRECTORY}/dist") # put generated libraries here.
message(STATUS "Output libraries to ${LIB_OUTPUT_DIR}")
# make sure 'make' works fine even if ${LIB_OUTPUT_DIR} is deleted.
add_custom_target(make_lib_output_dir ALL
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIB_OUTPUT_DIR}
)
add_dependencies(antlr4_shared make_lib_output_dir)
add_dependencies(antlr4_static make_lib_output_dir)
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
target_link_libraries(antlr4_shared ${UUID_LIBRARIES})
@ -45,12 +55,17 @@ set_target_properties(antlr4_shared
PROPERTIES VERSION ${ANTLR_VERSION}
SOVERSION ${ANTLR_VERSION}
OUTPUT_NAME antlr4-runtime
LIBRARY_OUTPUT_DIRECTORY ${LIB_OUTPUT_DIR}
# TODO: test in windows. DLL is treated as runtime.
# see https://cmake.org/cmake/help/v3.0/prop_tgt/LIBRARY_OUTPUT_DIRECTORY.html
RUNTIME_OUTPUT_DIRECTORY ${LIB_OUTPUT_DIR}
COMPILE_FLAGS "${disabled_compile_warnings}")
set_target_properties(antlr4_static
PROPERTIES VERSION ${ANTLR_VERSION}
SOVERSION ${ANTLR_VERSION}
OUTPUT_NAME antlr4-runtime
ARCHIVE_OUTPUT_DIRECTORY ${LIB_OUTPUT_DIR}
COMPILE_FLAGS "${disabled_compile_warnings}")
install(TARGETS antlr4_shared

View File

@ -57,7 +57,7 @@ ANTLRInputStream::ANTLRInputStream(std::istream &stream) {
}
void ANTLRInputStream::load(const std::string &input) {
// Remove the UTF-8 BOM if present
// Remove the UTF-8 BOM if present.
const char bom[4] = "\xef\xbb\xbf";
if (input.compare(0, 3, bom, 3) == 0)
_data = antlrcpp::utfConverter.from_bytes(input.substr(3, std::string::npos));

View File

@ -101,7 +101,7 @@ ParseTreeMatch ParseTreePatternMatcher::match(Ref<ParseTree> const& tree, const
}
ParseTreePattern ParseTreePatternMatcher::compile(const std::string &pattern, int patternRuleIndex) {
ListTokenSource tokenSrc(std::move(tokenize(pattern)));
ListTokenSource tokenSrc(tokenize(pattern));
CommonTokenStream tokens(&tokenSrc);
ParserInterpreter parserInterp(_parser->getGrammarFileName(), _parser->getVocabulary(),