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= where 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) 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() find_package(Java REQUIRED) file(STRINGS "VERSION" ANTLR_VERSION) if (NOT ANTLR_JAR_LOCATION) message(FATAL_ERROR "Missing antlr4.jar location. You can specify it's path using: -DANTLR_JAR_LOCATION=") else() 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() endif() 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}") # 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.") 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 () 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")