Port the build scripts to CMake 3.5, refactor them.
* Use the official LLVMConfig rather than our FindLLVM. * Add target rule for Ragel. * Remove useless dependencies by only compiling for the native target. * Use target rules.
This commit is contained in:
parent
3b5a9be6b9
commit
68dee1250d
|
@ -1,31 +1,13 @@
|
||||||
# Copyright 2017 the Monicelli project authors. All rights reserved.
|
# Copyright 2017 the Monicelli project authors. All rights reserved.
|
||||||
# Use of this source code is governed by a GPLv3 license, see LICENSE.txt.
|
# Use of this source code is governed by a GPLv3 license, see LICENSE.txt.
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.0)
|
cmake_minimum_required(VERSION 3.5)
|
||||||
project(Monicelli)
|
project(Monicelli CXX)
|
||||||
|
|
||||||
set(CMAKE_BUILD_TYPE Release)
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
|
|
||||||
|
|
||||||
find_package(Doxygen)
|
include(MonicelliDoc)
|
||||||
|
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
|
||||||
if (DOXYGEN_FOUND)
|
|
||||||
set(DOXYGEN_CONFIG ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
|
|
||||||
|
|
||||||
configure_file(
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in
|
|
||||||
${DOXYGEN_CONFIG}
|
|
||||||
@ONLY
|
|
||||||
)
|
|
||||||
|
|
||||||
add_custom_target(doc
|
|
||||||
DEPENDS ${DOXYGEN_CONFIG}
|
|
||||||
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_CONFIG}
|
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
||||||
VERBATIM
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
install(FILES README.md LICENSE.txt DESTINATION doc/monicelli)
|
install(FILES README.md LICENSE.txt DESTINATION doc/monicelli)
|
||||||
|
|
|
@ -1,54 +0,0 @@
|
||||||
# Copyright 2017 the Monicelli project authors. All rights reserved.
|
|
||||||
# Use of this source code is governed by a GPLv3 license, see LICENSE.txt.
|
|
||||||
|
|
||||||
find_program(LLVM_CONFIG llvm-config)
|
|
||||||
|
|
||||||
if (LLVM_CONFIG STREQUAL "LLVM_CONFIG-NOTFOUND")
|
|
||||||
message(FATAL_ERROR "Please install the LLVM dev package to compile Monicelli.")
|
|
||||||
else()
|
|
||||||
message(STATUS "Found llvm-config: ${LLVM_CONFIG}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
execute_process(
|
|
||||||
COMMAND ${LLVM_CONFIG} --version
|
|
||||||
OUTPUT_VARIABLE LLVM_VERSION
|
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
||||||
)
|
|
||||||
|
|
||||||
set(TARGET_LLVM_VERSION "6.0.0")
|
|
||||||
|
|
||||||
if (NOT LLVM_VERSION STREQUAL ${TARGET_LLVM_VERSION})
|
|
||||||
message(WARNING "Expected LLVM ${TARGET_LLVM_VERSION}, found ${LLVM_VERSION}, build may fail.")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
execute_process(
|
|
||||||
COMMAND ${LLVM_CONFIG} --includedir
|
|
||||||
OUTPUT_VARIABLE LLVM_INCLUDE_DIR
|
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
||||||
)
|
|
||||||
|
|
||||||
execute_process(
|
|
||||||
COMMAND ${LLVM_CONFIG} --libdir
|
|
||||||
OUTPUT_VARIABLE LLVM_LIBRARY_DIR
|
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
||||||
)
|
|
||||||
|
|
||||||
execute_process(
|
|
||||||
COMMAND ${LLVM_CONFIG} --cxxflags
|
|
||||||
OUTPUT_VARIABLE LLVM_CXXFLAGS
|
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
||||||
)
|
|
||||||
|
|
||||||
execute_process(
|
|
||||||
COMMAND ${LLVM_CONFIG} --libs all
|
|
||||||
OUTPUT_VARIABLE LLVM_MODULE_LIBS
|
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
||||||
)
|
|
||||||
|
|
||||||
execute_process(
|
|
||||||
COMMAND ${LLVM_CONFIG} --system-libs
|
|
||||||
OUTPUT_VARIABLE LLVM_SYSTEM_LIBS
|
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
||||||
)
|
|
||||||
|
|
||||||
set(LLVM_LIBS ${LLVM_MODULE_LIBS} ${LLVM_SYSTEM_LIBS})
|
|
|
@ -8,3 +8,29 @@ if (${RAGEL} STREQUAL "RAGEL-NOTFOUND")
|
||||||
else()
|
else()
|
||||||
message(STATUS "Found ragel: ${RAGEL}")
|
message(STATUS "Found ragel: ${RAGEL}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
function(add_ragel_library name source header)
|
||||||
|
set(generated_cpp "${source}.cpp")
|
||||||
|
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT "${generated_cpp}"
|
||||||
|
MAIN_DEPENDENCY "${source}"
|
||||||
|
DEPENDS "${header}"
|
||||||
|
COMMAND ${RAGEL} -G2 "${CMAKE_CURRENT_SOURCE_DIR}/${source}" -o "${generated_cpp}"
|
||||||
|
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
|
||||||
|
VERBATIM
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(${name} "${generated_cpp}")
|
||||||
|
|
||||||
|
set_target_properties(${name}
|
||||||
|
PROPERTIES
|
||||||
|
CXX_STANDARD 11
|
||||||
|
CXX_STANDARD_REQUIRED true
|
||||||
|
)
|
||||||
|
|
||||||
|
# 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})
|
||||||
|
endfunction()
|
||||||
|
|
22
cmake/MonicelliDoc.cmake
Normal file
22
cmake/MonicelliDoc.cmake
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# Copyright 2019 the Monicelli project authors. All rights reserved.
|
||||||
|
# Use of this source code is governed by a GPLv3 license, see LICENSE.txt.
|
||||||
|
|
||||||
|
find_package(Doxygen)
|
||||||
|
|
||||||
|
if (DOXYGEN_FOUND)
|
||||||
|
set(MONICELLI_DOXYGEN_CONFIG ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
|
||||||
|
|
||||||
|
configure_file(
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in
|
||||||
|
${MONICELLI_DOXYGEN_CONFIG}
|
||||||
|
@ONLY
|
||||||
|
)
|
||||||
|
|
||||||
|
add_custom_target(doc
|
||||||
|
DEPENDS ${MONICELLI_DOXYGEN_CONFIG}
|
||||||
|
COMMAND ${DOXYGEN_EXECUTABLE} ${MONICELLI_DOXYGEN_CONFIG}
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
VERBATIM
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
|
@ -1,41 +1,12 @@
|
||||||
# Copyright 2017 the Monicelli project authors. All rights reserved.
|
# Copyright 2017 the Monicelli project authors. All rights reserved.
|
||||||
# Use of this source code is governed by a GPLv3 license, see LICENSE.txt.
|
# Use of this source code is governed by a GPLv3 license, see LICENSE.txt.
|
||||||
|
|
||||||
find_package(LLVM REQUIRED)
|
find_package(LLVM REQUIRED CONFIG)
|
||||||
find_package(Ragel REQUIRED)
|
find_package(Ragel REQUIRED)
|
||||||
|
|
||||||
option(ENABLE_LINKER "Enable the Monicelli linker. Requires POSIX." ON)
|
option(MONICELLI_ENABLE_LINKER "Enable the Monicelli linker. Requires POSIX." ON)
|
||||||
|
|
||||||
if (ENABLE_LINKER)
|
add_ragel_library(lexer lexer.rl lexer.h)
|
||||||
add_definitions(-DMONICELLI_ENABLE_LINKER)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_definitions(
|
|
||||||
-std=c++11
|
|
||||||
-Wall -Wextra -Werror
|
|
||||||
# The lexer uses implicit fallthroughs all over, but it's OK.
|
|
||||||
-Wno-implicit-fallthrough
|
|
||||||
${LLVM_CXXFLAGS}
|
|
||||||
-g -O2 -UNDEBUG
|
|
||||||
)
|
|
||||||
|
|
||||||
include_directories(
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}
|
|
||||||
${LLVM_INCLUDE_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
link_directories(
|
|
||||||
${LLVM_LIBRARY_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
add_custom_command(
|
|
||||||
OUTPUT lexer.rl.cpp
|
|
||||||
MAIN_DEPENDENCY lexer.rl
|
|
||||||
DEPENDS lexer.h
|
|
||||||
COMMAND ${RAGEL} -G2 "${CMAKE_CURRENT_SOURCE_DIR}/lexer.rl" -o lexer.rl.cpp
|
|
||||||
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
|
|
||||||
VERBATIM
|
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(mcc
|
add_executable(mcc
|
||||||
main.cpp
|
main.cpp
|
||||||
|
@ -49,7 +20,6 @@ add_executable(mcc
|
||||||
parser.cpp
|
parser.cpp
|
||||||
lexer.cpp
|
lexer.cpp
|
||||||
lexer.def
|
lexer.def
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/lexer.rl.cpp"
|
|
||||||
options.cpp
|
options.cpp
|
||||||
errors.cpp
|
errors.cpp
|
||||||
support.cpp
|
support.cpp
|
||||||
|
@ -59,6 +29,20 @@ add_executable(mcc
|
||||||
operators.def
|
operators.def
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(mcc ${LLVM_LIBS})
|
set_target_properties(mcc
|
||||||
|
PROPERTIES
|
||||||
|
CXX_STANDARD 11
|
||||||
|
CXX_STANDARD_REQUIRED true
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_options(mcc PRIVATE -Wall -Wextra -Werror)
|
||||||
|
|
||||||
|
if (MONICELLI_ENABLE_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)
|
install(TARGETS mcc RUNTIME DESTINATION bin)
|
||||||
|
|
|
@ -24,11 +24,9 @@
|
||||||
namespace monicelli {
|
namespace monicelli {
|
||||||
|
|
||||||
void registerTargets() {
|
void registerTargets() {
|
||||||
llvm::InitializeAllTargetInfos();
|
llvm::InitializeNativeTarget();
|
||||||
llvm::InitializeAllTargets();
|
llvm::InitializeNativeTargetAsmParser();
|
||||||
llvm::InitializeAllTargetMCs();
|
llvm::InitializeNativeTargetAsmPrinter();
|
||||||
llvm::InitializeAllAsmParsers();
|
|
||||||
llvm::InitializeAllAsmPrinters();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::TargetMachine* getTargetMachine(const std::string& triple, const std::string& cpu,
|
llvm::TargetMachine* getTargetMachine(const std::string& triple, const std::string& cpu,
|
||||||
|
|
Reference in New Issue
Block a user