Improve build scripts, add MONICELLI_ARCH cache variable.
This commit is contained in:
parent
68dee1250d
commit
c4c70182a1
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
Reference in New Issue
Block a user