Merge pull request #3071 from felixn/cxx-17
Cpp target: allow building runtime with newer C++ standards
This commit is contained in:
commit
fde0b28dfb
|
@ -76,8 +76,13 @@ endif()
|
|||
|
||||
# Initialize CXXFLAGS.
|
||||
if("${CMAKE_VERSION}" VERSION_GREATER 3.1.0)
|
||||
if(NOT DEFINED CMAKE_CXX_STANDARD)
|
||||
# only set CMAKE_CXX_STANDARD if not already set
|
||||
# this allows the standard to be set by the caller, for example with -DCMAKE_CXX_STANDARD:STRING=17
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
endif()
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11")
|
||||
|
|
|
@ -40,6 +40,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 2.8.
|
||||
By default, the libraries produced by the CMake build target C++11. If you want to target a different C++ standard, you can explicitly pass the standard - e.g. `-DCMAKE_CXX_STANDARD=17`.
|
||||
|
||||
#### Compiling on Windows with Visual Studio using he Visual Studio projects
|
||||
Simply open the VS project from the runtime folder (VS 2013+) and build it.
|
||||
|
@ -69,5 +70,3 @@ If the CMake variable 'ANTLR4_INSTALL' is set, CMake Packages will be build and
|
|||
They expose two packages: antlr4_runtime and antlr4_generator which can be referenced to ease up the use of the
|
||||
ANTLR Generator and runtime.
|
||||
Use and Sample can be found [here](cmake/Antlr4Package.md)
|
||||
|
||||
|
||||
|
|
|
@ -88,6 +88,8 @@ if(ANTLR4_ZIP_REPOSITORY)
|
|||
CMAKE_CACHE_ARGS
|
||||
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
|
||||
-DWITH_STATIC_CRT:BOOL=${ANTLR4_WITH_STATIC_CRT}
|
||||
# -DCMAKE_CXX_STANDARD:STRING=17 # if desired, compile the runtime with a different C++ standard
|
||||
# -DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD} # alternatively, compile the runtime with the same C++ standard as the outer project
|
||||
INSTALL_COMMAND ""
|
||||
EXCLUDE_FROM_ALL 1)
|
||||
else()
|
||||
|
@ -104,6 +106,8 @@ else()
|
|||
CMAKE_CACHE_ARGS
|
||||
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
|
||||
-DWITH_STATIC_CRT:BOOL=${ANTLR4_WITH_STATIC_CRT}
|
||||
# -DCMAKE_CXX_STANDARD:STRING=17 # if desired, compile the runtime with a different C++ standard
|
||||
# -DCMAKE_CXX_STANDARD:STRING=${CMAKE_CXX_STANDARD} # alternatively, compile the runtime with the same C++ standard as the outer project
|
||||
INSTALL_COMMAND ""
|
||||
EXCLUDE_FROM_ALL 1)
|
||||
endif()
|
||||
|
|
|
@ -129,6 +129,8 @@ The ANTLR C++ runtime source is downloaded from GitHub by default. However, user
|
|||
|
||||
Visual C++ compiler users may want to additionally define `ANTLR4_WITH_STATIC_CRT` before including the file. Set `ANTLR4_WITH_STATIC_CRT` to true if ANTLR4 C++ runtime library should be compiled with `/MT` flag, otherwise will be compiled with `/MD` flag. This variable has a default value of `OFF`. Changing `ANTLR4_WITH_STATIC_CRT` after building the library may require reinitialization of CMake or `clean` for the library to get rebuilt.
|
||||
|
||||
You may need to modify your local copy of ExternalAntlr4Cpp.cpp to modify some build settings. For example, to specify the C++ standard to use when building the runtime, add `-DCMAKE_CXX_STANDARD:STRING=17` to `CMAKE_CACHE_ARGS`.
|
||||
|
||||
### Examples
|
||||
|
||||
To build and link ANTLR4 static library to a target one may call:
|
||||
|
|
Loading…
Reference in New Issue