2014-11-29 00:47:50 +01:00
|
|
|
#
|
2014-11-29 21:38:52 +01:00
|
|
|
# Monicelli: an esoteric language compiler
|
2014-11-29 00:47:50 +01:00
|
|
|
#
|
|
|
|
# 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 <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
2014-11-29 21:44:47 +01:00
|
|
|
project(Monicelli)
|
|
|
|
cmake_minimum_required(VERSION 2.8)
|
2014-11-28 19:01:34 +01:00
|
|
|
|
2015-03-08 13:27:39 +01:00
|
|
|
set(CMAKE_BUILD_TYPE Release)
|
|
|
|
|
2014-12-10 23:02:55 +01:00
|
|
|
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
|
|
|
|
|
2015-03-05 14:24:27 +01:00
|
|
|
try_run(
|
|
|
|
execution_results
|
2014-12-10 23:02:55 +01:00
|
|
|
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()
|
|
|
|
|
2015-03-05 14:24:27 +01:00
|
|
|
if (execution_results MATCHES FAILED_TO_RUN)
|
|
|
|
message(FATAL_ERROR
|
|
|
|
"Your compiler supports the set of C++11 features we need, "
|
|
|
|
"but something failed.\n"
|
|
|
|
"Run cmake with -Dcheckfeat=1 to see the exact cause."
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2014-12-10 23:02:55 +01:00
|
|
|
## 2. Find Flex and Bison
|
|
|
|
|
2014-11-29 21:44:47 +01:00
|
|
|
find_package(BISON REQUIRED)
|
2014-12-10 23:02:55 +01:00
|
|
|
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()
|
|
|
|
|
2015-03-05 17:35:52 +01:00
|
|
|
## 3. External components
|
2015-03-07 19:56:47 +01:00
|
|
|
find_package(Boost 1.48 REQUIRED regex system filesystem)
|
2015-03-07 17:23:46 +01:00
|
|
|
find_package(LLVM REQUIRED CONFIG)
|
2015-03-05 01:16:40 +01:00
|
|
|
|
2015-03-05 17:35:52 +01:00
|
|
|
add_definitions(
|
|
|
|
${Boost_DEFINITIONS}
|
2015-03-07 17:23:46 +01:00
|
|
|
${LLVM_DEFINITIONS}
|
2015-03-05 17:35:52 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
include_directories(
|
|
|
|
${Boost_INCLUDE_DIRS}
|
2015-03-07 17:23:46 +01:00
|
|
|
${LLVM_INCLUDE_DIRS}
|
2015-03-05 17:35:52 +01:00
|
|
|
)
|
|
|
|
|
2015-03-05 01:16:40 +01:00
|
|
|
## 4. Build
|
2014-11-29 11:11:43 +01:00
|
|
|
|
2014-11-29 21:44:47 +01:00
|
|
|
include_directories(
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
|
)
|
2014-11-23 19:04:25 +01:00
|
|
|
|
2015-03-07 17:24:25 +01:00
|
|
|
add_definitions(
|
2015-03-08 11:29:26 +01:00
|
|
|
-Wall -Wextra -Werror -Wno-unused-parameter -Wno-deprecated-register
|
2015-03-08 13:27:39 +01:00
|
|
|
-std=c++0x -DYYDEBUG=0
|
2015-03-07 17:24:25 +01:00
|
|
|
)
|
2014-11-29 11:11:43 +01:00
|
|
|
|
2014-11-29 21:44:47 +01:00
|
|
|
bison_target(Parser Monicelli.ypp ${CMAKE_CURRENT_BINARY_DIR}/Parser.cpp)
|
|
|
|
flex_target(Scanner Monicelli.lpp ${CMAKE_CURRENT_BINARY_DIR}/Lexer.cpp)
|
2014-12-04 21:50:15 +01:00
|
|
|
add_flex_bison_dependency(Scanner Parser)
|
2014-11-29 11:11:43 +01:00
|
|
|
|
2015-03-05 17:35:52 +01:00
|
|
|
add_executable(mcc
|
2015-03-08 13:25:59 +01:00
|
|
|
main.cpp Nodes.cpp ModuleRegistry.cpp
|
2015-03-05 01:16:40 +01:00
|
|
|
${BISON_Parser_OUTPUTS} ${FLEX_Scanner_OUTPUTS}
|
2015-03-07 17:23:46 +01:00
|
|
|
CppEmitter.cpp BitcodeEmitter.cpp
|
|
|
|
)
|
|
|
|
|
|
|
|
llvm_map_components_to_libnames(LLVM_LIBRARIES
|
|
|
|
support core jit native bitwriter
|
2014-11-29 21:44:47 +01:00
|
|
|
)
|
2014-11-23 19:04:25 +01:00
|
|
|
|
2015-03-05 17:35:52 +01:00
|
|
|
target_link_libraries(mcc
|
|
|
|
${Boost_LIBRARIES}
|
2015-03-07 17:23:46 +01:00
|
|
|
${LLVM_LIBRARIES}
|
2015-03-05 17:35:52 +01:00
|
|
|
)
|
2015-03-05 01:16:40 +01:00
|
|
|
|
2015-03-08 12:19:06 +01:00
|
|
|
## 6. Build the runtime library too
|
|
|
|
|
|
|
|
add_library(mcrt STATIC Runtime.cpp)
|
|
|
|
|