blob: f144fe212161f3dd246483b34887d5c33e75c647 [file] [log] [blame]
Daniel Malea137c4d72013-02-28 23:11:46 +00001# If we are not building as a part of LLVM, build LLDB as an
2# standalone project, using LLVM as an external library:
3if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
4 project(lldb)
5 cmake_minimum_required(VERSION 2.8)
6
7 set(LLDB_PATH_TO_LLVM_SOURCE "" CACHE PATH
8 "Path to LLVM source code. Not necessary if using an installed LLVM.")
9 set(LLDB_PATH_TO_LLVM_BUILD "" CACHE PATH
10 "Path to the directory where LLVM was built or installed.")
11
12 set(LLDB_PATH_TO_CLANG_SOURCE "" CACHE PATH
13 "Path to Clang source code. Not necessary if using an installed Clang.")
14 set(LLDB_PATH_TO_CLANG_BUILD "" CACHE PATH
15 "Path to the directory where Clang was built or installed.")
16
17 set(LLDB_DISABLE_PYTHON 1 BOOL "Disables the Python scripting integration.")
18
19 if (LLDB_PATH_TO_LLVM_SOURCE)
20 if (NOT EXISTS "${LLDB_PATH_TO_LLVM_SOURCE}/cmake/config-ix.cmake")
21 message(FATAL_ERROR "Please set LLDB_PATH_TO_LLVM_SOURCE to the root "
22 "directory of LLVM source code.")
23 else()
24 get_filename_component(LLVM_MAIN_SRC_DIR ${LLDB_PATH_TO_LLVM_SOURCE}
25 ABSOLUTE)
26 list(APPEND CMAKE_MODULE_PATH "${LLVM_MAIN_SRC_DIR}/cmake/modules")
27 endif()
28 endif()
29
30 if (LLDB_PATH_TO_CLANG_SOURCE)
31 get_filename_component(CLANG_MAIN_SRC_DIR ${LLDB_PATH_TO_CLANG_SOURCE}
32 ABSOLUTE)
33 endif()
34
35 list(APPEND CMAKE_MODULE_PATH "${LLDB_PATH_TO_LLVM_BUILD}/share/llvm/cmake")
36
37 get_filename_component(PATH_TO_LLVM_BUILD ${LLDB_PATH_TO_LLVM_BUILD}
38 ABSOLUTE)
39
40 get_filename_component(PATH_TO_CLANG_BUILD ${LLDB_PATH_TO_CLANG_BUILD}
41 ABSOLUTE)
42
43 include(AddLLVM)
44 include("${LLDB_PATH_TO_LLVM_BUILD}/share/llvm/cmake/LLVMConfig.cmake")
45 include(HandleLLVMOptions)
46
47 set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
48
49 set(LLVM_MAIN_INCLUDE_DIR "${LLVM_MAIN_SRC_DIR}/include")
50 set(LLVM_BINARY_DIR ${CMAKE_BINARY_DIR})
51
52 set(CLANG_MAIN_INCLUDE_DIR "${CLANG_MAIN_SRC_DIR}/include")
53
54 set(CMAKE_INCLUDE_CURRENT_DIR ON)
55 include_directories("${PATH_TO_LLVM_BUILD}/include"
56 "${LLVM_MAIN_INCLUDE_DIR}"
57 "${PATH_TO_CLANG_BUILD}/include"
58 "${CLANG_MAIN_INCLUDE_DIR}"
59 "${CMAKE_CURRENT_SOURCE_DIR}/source")
60 link_directories("${PATH_TO_LLVM_BUILD}/lib"
61 "${PATH_TO_CLANG_BUILD}/lib")
62
63 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
64 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
65 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
66
67 set(LLDB_BUILT_STANDALONE 1)
68
69 if (LLDB_DISABLE_PYTHON)
70 add_definitions( -DLLDB_DISABLE_PYTHON )
71 endif()
72endif()
73
74macro(add_lldb_definitions)
75 # We don't want no semicolons on LLDB_DEFINITIONS:
76 foreach(arg ${ARGN})
77 set(LLDB_DEFINITIONS "${LLVM_DEFINITIONS} ${arg}")
78 endforeach(arg)
79 add_definitions( ${ARGN} )
80endmacro(add_lldb_definitions)
81
82include_directories(/usr/include/python2.7)
83include_directories(../clang/include)
84include_directories("${CMAKE_CURRENT_BINARY_DIR}/../clang/include")
85set(CMAKE_CXX_FLAGS "-std=c++11")
86
87# Disable MSVC warnings
88if( MSVC )
89 add_lldb_definitions(
90 -wd4018 # Suppress 'warning C4018: '>=' : signed/unsigned mismatch'
91 -wd4068 # Suppress 'warning C4068: unknown pragma'
92 -wd4150 # Suppress 'warning C4150: deletion of pointer to incomplete type'
93 -wd4521 # Suppress 'warning C4521: 'type' : multiple copy constructors specified'
94 )
95endif()
96
97set(LLDB_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
98set(LLDB_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
99
100if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
101 message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite "
102"the makefiles distributed with LLDB. Please create a directory and run cmake "
103"from there, passing the path to this source directory as the last argument. "
104"This process created the file `CMakeCache.txt' and the directory "
105"`CMakeFiles'. Please delete them.")
106endif()
107
108macro(add_lldb_library name)
109 llvm_process_sources(srcs ${ARGN})
110 if (MSVC_IDE OR XCODE)
111 string(REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR})
112 list(GET split_path -1 dir)
113 file(GLOB_RECURSE headers
114 ../../include/lldb${dir}/*.h)
115 set(srcs ${srcs} ${headers})
116 endif()
117 if (MODULE)
118 set(libkind MODULE)
119 elseif (SHARED_LIBRARY)
120 set(libkind SHARED)
121 else()
122 set(libkind STATIC)
123 endif()
124 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
125 add_library(${name} ${libkind} ${srcs})
126 #if (LLVM_COMMON_DEPENDS)
127 ##add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
128 #endif()
129
130 if(LLDB_USED_LIBS)
131 target_link_libraries(${name} -Wl,--start-group ${LLDB_USED_LIBS} -Wl,--end-group)
132 endif()
133 target_link_libraries(${name} ${CLANG_USED_LIBS})
134 target_link_libraries(${name} ${LLVM_USED_LIBS})
135 llvm_config(${name} ${LLVM_LINK_COMPONENTS})
136 target_link_libraries(${name} ${LLVM_COMMON_LIBS})
137 link_system_libs(${name})
138 if (LLVM_COMMON_DEPENDS)
139 add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
140 endif()
141
142 # Hack: only some LLDB libraries depend on the clang autogenerated headers,
143 # but it is simple enough to make all of LLDB depend on some of those
144 # headers without negatively impacting much of anything.
145 set (LLDB_DEPENDENCIES
Daniel Malea08561072013-03-05 21:59:12 +0000146 libclang
Daniel Malea137c4d72013-02-28 23:11:46 +0000147 )
148 add_dependencies(${name} ${LLDB_DEPENDENCIES})
149
150 install(TARGETS ${name}
151 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
152 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
153 set_target_properties(${name} PROPERTIES FOLDER "lldb libraries")
154endmacro(add_lldb_library)
155
156macro(add_lldb_executable name)
157 #add_llvm_executable(${name} ${ARGN})
158 llvm_process_sources( ALL_FILES ${ARGN} )
159 add_executable(${name} ${ALL_FILES})
160 #target_link_libraries(${name} ${CLANG_USED_LIBS})
161 #llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
162 #link_system_libs( ${name} )
163 #if (LLVM_COMMON_DEPENDS)
164 #add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
165 #endif()
166 set_target_properties(${name} PROPERTIES FOLDER "lldb executables")
167endmacro(add_lldb_executable)
168
169include_directories(BEFORE
170 ${CMAKE_CURRENT_BINARY_DIR}/include
171 ${CMAKE_CURRENT_SOURCE_DIR}/include
172 )
173
174install(DIRECTORY include/
175 DESTINATION include
176 FILES_MATCHING
177 PATTERN "*.h"
178 PATTERN ".svn" EXCLUDE
179 )
180
181#add_subdirectory(include)
182add_subdirectory(scripts)
183add_subdirectory(source)
184add_subdirectory(test)
185add_subdirectory(tools)