-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
59 lines (49 loc) · 2.47 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
cmake_minimum_required(VERSION 2.8)
project(epilog)
set(epilog_CXX_SRCS
# Compile the Pegmatite source files directly into the program (rather than creating a separate library).
lib/Pegmatite/ast.cc
# Compile the Epilog source files.
src/ast.cc
src/interpreter.cc
src/main.cc
src/runtime.cc
)
set(LLVM_LIBS all)
# Define the Epilog program that we will build.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
add_executable(epilog ${epilog_CXX_SRCS})
# We're using Pegmatite in the RTTI mode.
add_definitions(-DUSE_RTTI=1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g -I../lib")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CLANG_FLAGS "-Wdeprecated -Wno-zero-length-array -Wno-unknown-attributes")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CLANG_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
endif()
find_program(LLVM_CONFIG NAMES llvm-config DOC "Path to llvm-config utility")
if (${LLVM_CONFIG} STREQUAL "LLVM_CONFIG-NOTFOUND")
message(SEND_ERROR "llvm-config not found, please manually set path with -DLLVM_CONFIG")
endif()
message(STATUS "Using llvm-config: ${LLVM_CONFIG}")
# Define LLVM version macros so that we can support multiple versions in the source.
exec_program(${LLVM_CONFIG} ARGS --version OUTPUT_VARIABLE LLVM_VER)
exec_program(${LLVM_CONFIG} ARGS --cxxflags OUTPUT_VARIABLE LLVM_CXXFLAGS)
exec_program(${LLVM_CONFIG} ARGS --libs ${LLVM_LIBS} OUTPUT_VARIABLE LLVM_LIBS_FLAGS)
exec_program(${LLVM_CONFIG} ARGS --ldflags OUTPUT_VARIABLE LLVM_LDFLAGS)
exec_program(${LLVM_CONFIG} ARGS --system-libs OUTPUT_VARIABLE LLVM_SYSTEMLIBS)
exec_program(${LLVM_CONFIG} ARGS --libdir OUTPUT_VARIABLE LLVM_LIBDIR)
exec_program(${LLVM_CONFIG} ARGS --bindir OUTPUT_VARIABLE LLVM_BINDIR)
string(REGEX REPLACE "([0-9]*).([0-9]*).*" "-DLLVM_MAJOR=\\1 -DLLVM_MINOR=\\2" LLVM_VERSION "${LLVM_VER}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LLVM_CXXFLAGS} ${LLVM_VERSION}")
target_link_libraries(epilog ${LLVM_LIBS_FLAGS})
# llvm-config only gained a --system-libs flag in 3.5
if(LLVM_VER VERSION_GREATER 3.4)
target_link_libraries(epilog ${LLVM_SYSTEMLIBS})
endif()
set(CMAKE_EXE_LINKER_FLAGS "${LLVM_LDFLAGS} ${LIBGC} ${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,${LLVM_LIBDIR}")
# Make sure that we use the LLVM path as an rpath so that we can dynamically link to LLVM. Don't let CMake specify its own rpath.
set(CMAKE_SKIP_RPATH true)
# Make sure that LLVM is able to find functions in the main executable.
SET_TARGET_PROPERTIES(epilog PROPERTIES ENABLE_EXPORTS TRUE)