From 715b0fe840d1563ee045a882a06d8cd458aff3b9 Mon Sep 17 00:00:00 2001 From: Stefano Sanfilippo Date: Wed, 10 Dec 2014 23:02:55 +0100 Subject: [PATCH] Compiler features discovery and Bison version check. --- CMakeLists.txt | 36 ++++++++++++++++++++- bison2.patch => cmake/bison2.patch | 0 cmake/features.cpp | 52 ++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) rename bison2.patch => cmake/bison2.patch (100%) create mode 100644 cmake/features.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 3be8b9e..6d95090 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,8 +20,42 @@ project(Monicelli) cmake_minimum_required(VERSION 2.8) +message("== Only a limited set of platforms was tested. We need your help!") +message("== Report build errors to https://github.com/esseks/monicelli/issues") + +## 1. Compiler sanity check + +try_compile( + supported_compiler + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/features.cpp + COMPILE_DEFINITIONS -std=c++0x + OUTPUT_VARIABLE features_build_log +) + +if (checkfeat) + message(${features_build_log}) +endif() + +if (NOT supported_compiler) + message(FATAL_ERROR + "Some C++11 features we need are not implemented by your compiler.\n" + "Run cmake with -Dcheckfeat=1 to see the exact cause." + ) +endif() + +## 2. Find Flex and Bison + find_package(BISON REQUIRED) -find_package(FLEX REQUIRED) +find_package(FLEX 2.5 REQUIRED) + +if (BISON_VERSION VERSION_LESS 2.5) + message(FATAL_ERROR "At least Bison 2.5 is required.") +elseif(BISON_VERSION VERSION_LESS 3.0) + message("== Bison 2.5 was found. You have to apply cmake/bison2.patch...") +endif() + +## 3. Build include_directories( ${CMAKE_CURRENT_BINARY_DIR} diff --git a/bison2.patch b/cmake/bison2.patch similarity index 100% rename from bison2.patch rename to cmake/bison2.patch diff --git a/cmake/features.cpp b/cmake/features.cpp new file mode 100644 index 0000000..051ba0e --- /dev/null +++ b/cmake/features.cpp @@ -0,0 +1,52 @@ +/* + * Monicelli: an esoteric language compiler + * + * Copyright (C) 2014 Stefano Sanfilippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * Minimum program containing all required C++11 features. + * If a compiler cannot compile this, then it won't compile Monicelli. + */ + +#include +#include +#include + +#include +#include + +enum class Dummy { + FOO, BAR, BAZ +}; + +class Banana { + int yep() const noexcept { + return 0; + } +}; + +int main() { + std::unique_ptr foo(new int{0}); + std::vector bar = {1, 2, 3}; + for (int baz: bar) { + baz += 1; + } + char *str = nullptr; + Banana a; + Banana b = std::move(a); + long c = std::stol("100"); +}