blob: 93e7643e4d7dd944030508ae7d5649faa9213989 [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")
Matt Kopec44ef1bf2013-03-21 20:52:53 +000085
Filipe Cabecinhas86981e52013-04-19 00:19:04 +000086# lldb requires c++11 to build. Make sure that we have a compiler and standard
87# library combination that can do that.
88if (MSVC11)
89 # Do nothing, we're good.
90elseif (NOT MSVC)
91 # gcc and clang require the -std=c++0x or -std=c++11 flag.
92 if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR
93 "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
94 if (NOT ("${CMAKE_CXX_FLAGS}" MATCHES "-std=c\\+\\+0x" OR
95 "${CMAKE_CXX_FLAGS}" MATCHES "-std=gnu\\+\\+0x" OR
96 "${CMAKE_CXX_FLAGS}" MATCHES "-std=c\\+\\+11" OR
97 "${CMAKE_CXX_FLAGS}" MATCHES "-std=gnu\\+\\+11"))
98 if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
99 if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.7")
100 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
101 else()
102 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
103 endif()
104 else()
105 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
106 endif()
107 endif()
Matt Kopec44ef1bf2013-03-21 20:52:53 +0000108 endif()
109else()
Filipe Cabecinhas86981e52013-04-19 00:19:04 +0000110 message(FATAL_ERROR "The selected compiler does not support c++11 which is "
111 "required to build lldb.")
Matt Kopec44ef1bf2013-03-21 20:52:53 +0000112endif()
Daniel Malea137c4d72013-02-28 23:11:46 +0000113
Daniel Malea1ce3d862013-04-17 19:27:31 +0000114# Disable Clang warnings
115if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
116 add_lldb_definitions(
117 -Wno-deprecated-declarations # Suppress "deprecated auto_ptr" warnings
118 )
119endif()
120
Daniel Malea137c4d72013-02-28 23:11:46 +0000121# Disable MSVC warnings
122if( MSVC )
123 add_lldb_definitions(
124 -wd4018 # Suppress 'warning C4018: '>=' : signed/unsigned mismatch'
125 -wd4068 # Suppress 'warning C4068: unknown pragma'
126 -wd4150 # Suppress 'warning C4150: deletion of pointer to incomplete type'
127 -wd4521 # Suppress 'warning C4521: 'type' : multiple copy constructors specified'
128 )
129endif()
130
Daniel Malead7982f82013-03-07 00:48:53 +0000131# If building on a 32-bit system, make sure off_t can store offsets > 2GB
132if( CMAKE_SIZEOF_VOID_P EQUAL 4 )
133 add_lldb_definitions(
134 -D_LARGEFILE_SOURCE
135 -D_FILE_OFFSET_BITS=64
136 )
137endif()
138
Daniel Malea137c4d72013-02-28 23:11:46 +0000139set(LLDB_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
140set(LLDB_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
141
142if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
143 message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite "
144"the makefiles distributed with LLDB. Please create a directory and run cmake "
145"from there, passing the path to this source directory as the last argument. "
146"This process created the file `CMakeCache.txt' and the directory "
147"`CMakeFiles'. Please delete them.")
148endif()
149
Daniel Malea26868912013-05-17 18:51:03 +0000150# Compute the LLDB version from the LLVM version.
151string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" LLDB_VERSION
152 ${PACKAGE_VERSION})
153message(STATUS "LLDB version: ${LLDB_VERSION}")
154
Daniel Malea137c4d72013-02-28 23:11:46 +0000155macro(add_lldb_library name)
156 llvm_process_sources(srcs ${ARGN})
157 if (MSVC_IDE OR XCODE)
158 string(REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR})
159 list(GET split_path -1 dir)
160 file(GLOB_RECURSE headers
161 ../../include/lldb${dir}/*.h)
162 set(srcs ${srcs} ${headers})
163 endif()
164 if (MODULE)
165 set(libkind MODULE)
166 elseif (SHARED_LIBRARY)
167 set(libkind SHARED)
168 else()
169 set(libkind STATIC)
170 endif()
171 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
172 add_library(${name} ${libkind} ${srcs})
173 #if (LLVM_COMMON_DEPENDS)
174 ##add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
175 #endif()
176
177 if(LLDB_USED_LIBS)
Filipe Cabecinhas86981e52013-04-19 00:19:04 +0000178 if (CMAKE_SYSTEM_NAME MATCHES "Linux")
179 target_link_libraries(${name} -Wl,--start-group ${LLDB_USED_LIBS} -Wl,--end-group)
Filipe Cabecinhasaad68fa2013-04-25 01:36:53 +0000180 else()
181 target_link_libraries(${name} ${LLDB_USED_LIBS})
Filipe Cabecinhas86981e52013-04-19 00:19:04 +0000182 endif()
Daniel Malea137c4d72013-02-28 23:11:46 +0000183 endif()
184 target_link_libraries(${name} ${CLANG_USED_LIBS})
185 target_link_libraries(${name} ${LLVM_USED_LIBS})
186 llvm_config(${name} ${LLVM_LINK_COMPONENTS})
187 target_link_libraries(${name} ${LLVM_COMMON_LIBS})
188 link_system_libs(${name})
189 if (LLVM_COMMON_DEPENDS)
190 add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
191 endif()
192
193 # Hack: only some LLDB libraries depend on the clang autogenerated headers,
194 # but it is simple enough to make all of LLDB depend on some of those
195 # headers without negatively impacting much of anything.
196 set (LLDB_DEPENDENCIES
Daniel Malea08561072013-03-05 21:59:12 +0000197 libclang
Daniel Malea137c4d72013-02-28 23:11:46 +0000198 )
199 add_dependencies(${name} ${LLDB_DEPENDENCIES})
200
201 install(TARGETS ${name}
202 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
203 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
204 set_target_properties(${name} PROPERTIES FOLDER "lldb libraries")
205endmacro(add_lldb_library)
206
207macro(add_lldb_executable name)
208 #add_llvm_executable(${name} ${ARGN})
209 llvm_process_sources( ALL_FILES ${ARGN} )
210 add_executable(${name} ${ALL_FILES})
211 #target_link_libraries(${name} ${CLANG_USED_LIBS})
212 #llvm_config( ${name} ${LLVM_LINK_COMPONENTS} )
213 #link_system_libs( ${name} )
214 #if (LLVM_COMMON_DEPENDS)
215 #add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
216 #endif()
217 set_target_properties(${name} PROPERTIES FOLDER "lldb executables")
218endmacro(add_lldb_executable)
219
220include_directories(BEFORE
221 ${CMAKE_CURRENT_BINARY_DIR}/include
222 ${CMAKE_CURRENT_SOURCE_DIR}/include
223 )
224
225install(DIRECTORY include/
226 DESTINATION include
227 FILES_MATCHING
228 PATTERN "*.h"
229 PATTERN ".svn" EXCLUDE
230 )
231
Filipe Cabecinhasaad68fa2013-04-25 01:36:53 +0000232
233# Find libraries or frameworks that may be needed
234if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
235 find_library(CARBON_LIBRARY Carbon)
236 find_library(FOUNDATION_LIBRARY Foundation)
237 find_library(CORE_FOUNDATION_LIBRARY CoreFoundation)
238 find_library(CORE_SERVICES_LIBRARY CoreServices)
239 find_library(SECURITY_LIBRARY Security)
240 find_library(DEBUG_SYMBOLS_LIBRARY DebugSymbols PATHS "/System/Library/PrivateFrameworks")
241
242 set(LIBXML2_INCLUDE_DIR "/usr/include/libxml2")
243 list(APPEND system_libs xml2)
244 list(APPEND system_libs ${CARBON_LIBRARY} ${FOUNDATION_LIBRARY}
245 ${CORE_FOUNDATION_LIBRARY} ${CORE_SERVICES_LIBRARY} ${SECURITY_LIBRARY}
246 ${DEBUG_SYMBOLS_LIBRARY})
247endif()
248
Daniel Malea137c4d72013-02-28 23:11:46 +0000249#add_subdirectory(include)
Daniel Malea56c7ef62013-05-28 03:47:34 +0000250add_subdirectory(docs)
Daniel Malea137c4d72013-02-28 23:11:46 +0000251add_subdirectory(scripts)
252add_subdirectory(source)
253add_subdirectory(test)
254add_subdirectory(tools)