2016-05-06 22:48:59 +08:00
|
|
|
cmake_minimum_required (VERSION 2.8)
|
|
|
|
# 2.8 needed because of ExternalProject
|
|
|
|
|
|
|
|
# Detect build type, fallback to release and throw a warning if use didn't specify any
|
|
|
|
if(NOT CMAKE_BUILD_TYPE)
|
|
|
|
message(WARNING "Build type not set, falling back to Release mode.
|
|
|
|
To specify build type use:
|
|
|
|
-DCMAKE_BUILD_TYPE=<mode> where <mode> is Debug or Release.")
|
|
|
|
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
|
|
|
|
"Choose the type of build, options are: Debug Release."
|
|
|
|
FORCE)
|
|
|
|
endif(NOT CMAKE_BUILD_TYPE)
|
|
|
|
|
|
|
|
if(NOT WITH_DEMO)
|
|
|
|
message(STATUS "Building without demo. To enable demo build use: -DWITH_DEMO=True")
|
|
|
|
set(WITH_DEMO False CACHE STRING
|
|
|
|
"Chose to build with or without demo executable"
|
|
|
|
FORCE)
|
|
|
|
endif(NOT WITH_DEMO)
|
|
|
|
|
2016-07-20 22:24:12 +08:00
|
|
|
option(WITH_LIBCXX "Building with clang++ and libc++(in Linux). To enable with: -DWITH_LIBCXX=On" On)
|
|
|
|
|
2016-05-06 22:48:59 +08:00
|
|
|
project(LIBANTLR4)
|
|
|
|
|
|
|
|
if(CMAKE_VERSION VERSION_EQUAL "3.0.0" OR
|
|
|
|
CMAKE_VERSION VERSION_GREATER "3.0.0")
|
|
|
|
CMAKE_POLICY(SET CMP0026 OLD)
|
|
|
|
CMAKE_POLICY(SET CMP0045 OLD)
|
|
|
|
CMAKE_POLICY(SET CMP0042 OLD)
|
|
|
|
CMAKE_POLICY(SET CMP0059 OLD)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
|
|
|
|
find_package(PkgConfig REQUIRED)
|
|
|
|
pkg_check_modules(UUID REQUIRED uuid)
|
|
|
|
endif()
|
|
|
|
if(APPLE)
|
|
|
|
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
file(STRINGS "VERSION" ANTLR_VERSION)
|
|
|
|
|
2016-05-23 15:40:48 +08:00
|
|
|
if (WITH_DEMO)
|
2016-07-20 22:24:12 +08:00
|
|
|
# Java is not necessary if building without demos.
|
|
|
|
find_package(Java REQUIRED)
|
|
|
|
|
2016-05-23 15:40:48 +08:00
|
|
|
if (NOT ANTLR_JAR_LOCATION)
|
|
|
|
message(FATAL_ERROR "Missing antlr4.jar location. You can specify it's path using: -DANTLR_JAR_LOCATION=<path>")
|
2016-05-06 22:48:59 +08:00
|
|
|
else()
|
2016-05-23 15:40:48 +08:00
|
|
|
get_filename_component(ANTLR_NAME ${ANTLR_JAR_LOCATION} NAME_WE)
|
|
|
|
if(NOT EXISTS "${ANTLR_JAR_LOCATION}")
|
|
|
|
message(FATAL_ERROR "Unable to find ${ANTLR_NAME} in ${ANTLR_JAR_LOCATION}")
|
|
|
|
else()
|
|
|
|
message(STATUS "Found ${ANTLR_NAME}: ${ANTLR_JAR_LOCATION}")
|
|
|
|
endif()
|
2016-05-06 22:48:59 +08:00
|
|
|
endif()
|
2016-05-23 15:40:48 +08:00
|
|
|
endif(WITH_DEMO)
|
|
|
|
|
2016-05-06 22:48:59 +08:00
|
|
|
set(MY_CXX_WARNING_FLAGS " -Wall -pedantic -W")
|
|
|
|
|
|
|
|
# Initialize CXXFLAGS.
|
2016-07-20 22:24:12 +08:00
|
|
|
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}")
|
2016-05-06 22:48:59 +08:00
|
|
|
|
|
|
|
# Compiler-specific C++11 activation.
|
|
|
|
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
|
2016-07-20 22:24:12 +08:00
|
|
|
# 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.")
|
2016-05-06 22:48:59 +08:00
|
|
|
endif ()
|
|
|
|
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND APPLE)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
|
|
|
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND CMAKE_SYSTEM_NAME MATCHES "Linux")
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE CLANG_VERSION)
|
|
|
|
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 ()
|
2016-07-20 22:24:12 +08:00
|
|
|
# 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()
|
2016-05-06 22:48:59 +08:00
|
|
|
else ()
|
|
|
|
message(FATAL_ERROR "Your C++ compiler does not support C++11.")
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
|
|
|
|
add_subdirectory(runtime)
|
|
|
|
if (WITH_DEMO)
|
|
|
|
add_subdirectory(demo)
|
|
|
|
endif(WITH_DEMO)
|
|
|
|
|
|
|
|
install(FILES License.txt README.md VERSION
|
|
|
|
DESTINATION "share/doc/libantlr4")
|