diff --git a/CMakeLists.txt b/CMakeLists.txt index dc89a43..af0afe0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,12 @@ # Copyright 2017 the Monicelli project authors. All rights reserved. # Use of this source code is governed by a GPLv3 license, see LICENSE.txt. -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.7) project(Monicelli CXX) list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") -include(MonicelliDoc) +include(Doxycelli) add_subdirectory(src) diff --git a/README.md b/README.md index 8907ac4..7eac147 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ library, by yourself. You can disable the invocation of an external linker and make `mcc` compilable on Windows during CMake configuration by forcing the appropriate flag to OFF: - $ cmake .. -DENABLE_LINKER=OFF + $ cmake .. -DMONICELLI_LINKER=OFF ## Tested platforms diff --git a/cmake/MonicelliDoc.cmake b/cmake/Doxycelli.cmake similarity index 100% rename from cmake/MonicelliDoc.cmake rename to cmake/Doxycelli.cmake diff --git a/cmake/FindRagel.cmake b/cmake/FindRagel.cmake index df71b5e..f942e16 100644 --- a/cmake/FindRagel.cmake +++ b/cmake/FindRagel.cmake @@ -9,19 +9,19 @@ else() message(STATUS "Found ragel: ${RAGEL}") endif() -function(add_ragel_library name source header) - set(generated_cpp "${source}.cpp") +function(add_ragel_library name ragel_source) + set(generated_source "${ragel_source}.cpp") + set(extra_sources "${ARGN}") add_custom_command( - OUTPUT "${generated_cpp}" - MAIN_DEPENDENCY "${source}" - DEPENDS "${header}" - COMMAND ${RAGEL} -G2 "${CMAKE_CURRENT_SOURCE_DIR}/${source}" -o "${generated_cpp}" + OUTPUT "${generated_source}" + MAIN_DEPENDENCY "${ragel_source}" + COMMAND ${RAGEL} -G2 "${CMAKE_CURRENT_SOURCE_DIR}/${ragel_source}" -o "${generated_source}" WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" VERBATIM ) - add_library(${name} "${generated_cpp}") + add_library(${name} "${generated_source}" "${extra_sources}") set_target_properties(${name} PROPERTIES @@ -32,5 +32,5 @@ function(add_ragel_library name source header) # The lexer uses implicit fallthroughs all over, but it's OK. target_compile_options(${name} PRIVATE -Wno-implicit-fallthrough) - target_include_directories(${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) + target_include_directories(${name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) endfunction() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 20be759..11b9aba 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,9 +4,15 @@ find_package(LLVM REQUIRED CONFIG) find_package(Ragel REQUIRED) -option(MONICELLI_ENABLE_LINKER "Enable the Monicelli linker. Requires POSIX." ON) +set(MONICELLI_LINKER ON CACHE BOOL "Enable the Monicelli linker. Requires POSIX.") +set(MONICELLI_ARCH "x86" CACHE STRING "Target architecture for Monicelli.") -add_ragel_library(lexer lexer.rl lexer.h) +add_ragel_library(lexer + lexer.rl + lexer.h + lexer.cpp + lexer.def +) add_executable(mcc main.cpp @@ -18,8 +24,6 @@ add_executable(mcc ast-visitor.h ast-printer.cpp parser.cpp - lexer.cpp - lexer.def options.cpp errors.cpp support.cpp @@ -37,12 +41,17 @@ set_target_properties(mcc target_compile_options(mcc PRIVATE -Wall -Wextra -Werror) -if (MONICELLI_ENABLE_LINKER) +target_link_libraries(mcc PRIVATE lexer) + +llvm_config(mcc + core + support + "${MONICELLI_ARCH}codegen" + "${MONICELLI_ARCH}asmparser" +) + +if (MONICELLI_LINKER) target_compile_definitions(mcc PRIVATE MONICELLI_ENABLE_LINKER) endif() -# TODO expand this line to support compiling on other architectures and cross-compilation. -llvm_config(mcc core support x86codegen x86asmparser) -target_link_libraries(mcc PRIVATE lexer) - install(TARGETS mcc RUNTIME DESTINATION bin)