forked from jckarter/clay
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
126 lines (108 loc) · 3.92 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
project(clay)
cmake_minimum_required(VERSION 2.8.11)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
find_package(Subversion)
find_package(Mercurial)
find_package(Git)
set(Python_ADDITIONAL_VERSIONS "2.7")
include(FindPythonInterp)
include(CheckSymbolExists)
include(CPack)
if(UNIX)
if(DEFINED LLVM_DIR)
set(LLVM_CONFIG "${LLVM_DIR}/bin/llvm-config")
else()
find_program(LLVM_CONFIG llvm-config /usr/local/bin
DOC "path to llvm-config")
endif()
message("-- Using llvm-config: ${LLVM_CONFIG}")
execute_process(
COMMAND ${LLVM_CONFIG} --version
OUTPUT_VARIABLE LLVM_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE LLVM_CONFIG_VERSION_RESULT
)
if (NOT ${LLVM_CONFIG_VERSION_RESULT} EQUAL 0)
message(FATAL_ERROR "${LLVM_CONFIG} failed")
endif()
if(NOT ${LLVM_VERSION} MATCHES "^3.3(svn)?$")
message(FATAL_ERROR "Clay requires LLVM 3.3.")
endif()
execute_process(
COMMAND ${LLVM_CONFIG} --cxxflags
OUTPUT_VARIABLE LLVM_CXXFLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(LLVM_CXXFLAGS "${LLVM_CXXFLAGS}")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# llvm-config --cxxflags contains -O3
set(LLVM_CXXFLAGS "${LLVM_CXXFLAGS} -O0")
endif()
execute_process(
COMMAND ${LLVM_CONFIG} --ldflags
OUTPUT_VARIABLE LLVM_LDFLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${LLVM_CONFIG} --libs all
OUTPUT_VARIABLE LLVM_LIBS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${LLVM_CONFIG} --libdir
OUTPUT_VARIABLE LLVM_LIBDIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${LLVM_CONFIG} --prefix
OUTPUT_VARIABLE LLVM_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message("-- Using LLVM: ${LLVM_DIR}")
set(CMAKE_REQUIRED_INCLUDES ${LLVM_DIR}/include)
set(CMAKE_REQUIRED_LIBRARIES clang)
set(CMAKE_REQUIRED_FLAGS "-L${LLVM_LIBDIR}")
elseif(WIN32)
set(LLVM_DIR "$ENV{ProgramFiles}/LLVM" CACHE PATH "llvm install path")
if(IS_DIRECTORY ${LLVM_DIR})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${LLVM_DIR}/share/llvm/cmake")
include(LLVMConfig)
include_directories( ${LLVM_DIR}/include )
link_directories( ${LLVM_DIR}/lib )
add_definitions( ${LLVM_DEFINITIONS} )
llvm_map_components_to_libraries(LLVM_LIBS ${LLVM_TARGETS_TO_BUILD} jit interpreter native asmparser bitreader bitwriter ipo linker)
find_file(CLANG clang.exe HINTS ${LLVM_DIR}/bin)
else()
message(FATAL_ERROR "Could not find LLVM. Try setting LLVM_DIR")
endif()
set(CMAKE_REQUIRED_INCLUDES ${LLVM_DIR}/include)
set(CMAKE_REQUIRED_LIBRARIES ${LLVM_DIR}/lib/libclang.lib)
endif()
set(BUILD_BINDGEN True CACHE BOOL
"Build the clay-bindgen tool for generating Clay bindings from C header files.")
install(DIRECTORY doc/ DESTINATION share/doc/clay)
install(DIRECTORY examples/ DESTINATION share/doc/clay/examples)
install(DIRECTORY lib-clay DESTINATION lib)
add_subdirectory(compiler)
add_subdirectory(misc)
add_subdirectory(tools)
if(PYTHONINTERP_FOUND)
execute_process(
COMMAND ${PYTHON_EXECUTABLE} --version
ERROR_VARIABLE PYTHON_VERSION
ERROR_STRIP_TRAILING_WHITESPACE)
if(NOT ${PYTHON_VERSION} MATCHES "Python 2.7")
unset(PYTHON_EXECUTABLE)
find_program(PYTHON2_EXE python2)
if(PYTHON2_EXE)
set(PYTHON_EXECUTABLE ${PYTHON2_EXE})
endif()
endif()
if(DEFINED PYTHON_EXECUTABLE)
add_custom_target(test ${PYTHON_EXECUTABLE} "${PROJECT_SOURCE_DIR}/test/runtests.py" --buildflags="-Dtest.minimal")
add_dependencies(test clay)
else()
message("-- Python 2.x not found. You will not be able to run tests")
message("-- Try setting PYTHON_EXECUTABLE to the Python 2.x interpreter")
endif()
endif()