Skip to content
This repository
Newer
Older
100644 140 lines (114 sloc) 4.353 kb
2ec63a36 »
2011-12-18 Initial commit. Code by Nick Kledzik. Cleanups and build system by me.
1 # If we are not building as a part of LLVM, build lld as a standalone project,
2 # using LLVM as an external library.
3
c1845dd9 »
2012-03-08 Sources now require C++11 to build.
4
5
2ec63a36 »
2011-12-18 Initial commit. Code by Nick Kledzik. Cleanups and build system by me.
6 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
7 project(lld)
8 cmake_minimum_required(VERSION 2.8)
9
10 set(LLD_PATH_TO_LLVM_SOURCE "" CACHE PATH
11 "Path to LLVM source code. Not necessary if using an installed LLVM.")
12 set(LLD_PATH_TO_LLVM_BUILD "" CACHE PATH
13 "Path to the directory where LLVM was built or installed.")
14
15 if (LLD_PATH_TO_LLVM_SOURCE)
16 if (NOT EXISTS "${LLD_PATH_TO_LLVM_SOURCE}/cmake/config-ix.cmake")
17 message(FATAL_ERROR "Please set LLD_PATH_TO_LLVM_SOURCE to the root "
18 "directory of LLVM source code.")
19 else()
20 get_filename_component(LLVM_MAIN_SRC_DIR ${LLD_PATH_TO_LLVM_SOURCE}
21 ABSOLUTE)
22 list(APPEND CMAKE_MODULE_PATH "${LLVM_MAIN_SRC_DIR}/cmake/modules")
23 endif()
24 endif()
25
26 list(APPEND CMAKE_MODULE_PATH "${LLD_PATH_TO_LLVM_BUILD}/share/llvm/cmake")
27
28 get_filename_component(PATH_TO_LLVM_BUILD ${LLD_PATH_TO_LLVM_BUILD}
29 ABSOLUTE)
30
31 include(AddLLVM)
32 include("${LLD_PATH_TO_LLVM_BUILD}/share/llvm/cmake/LLVMConfig.cmake")
33 include(HandleLLVMOptions)
34
35 set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
36
37 set(LLVM_MAIN_INCLUDE_DIR "${LLVM_MAIN_SRC_DIR}/include")
38 set(LLVM_BINARY_DIR ${CMAKE_BINARY_DIR})
39
40 set(CMAKE_INCLUDE_CURRENT_DIR ON)
41 include_directories("${PATH_TO_LLVM_BUILD}/include"
42 "${LLVM_MAIN_INCLUDE_DIR}")
43 link_directories("${PATH_TO_LLVM_BUILD}/lib")
44
45 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
46 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
47 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
48
49 set(LLD_BUILT_STANDALONE 1)
50 endif()
51
52 set(LLD_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
53 set(LLD_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
54
55 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
56 message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite "
57 "the makefiles distributed with LLVM. Please create a directory and run cmake "
58 "from there, passing the path to this source directory as the last argument. "
59 "This process created the file `CMakeCache.txt' and the directory "
60 "`CMakeFiles'. Please delete them.")
61 endif()
62
c1845dd9 »
2012-03-08 Sources now require C++11 to build.
63 #
64 # lld now requires C++11 to build
65 #
66 # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
ee6366ba »
2012-03-09 Fix MSVC incompatibilities.
67 if (NOT MSVC)
68 include(CheckCXXCompilerFlag)
69 check_cxx_compiler_flag("-std=c++0x" SUPPORTS_CXX11_FLAG)
70 if( SUPPORTS_CXX11_FLAG )
71 message(STATUS "Building with -std=c++0x")
72 set(CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS}")
73 else( SUPPORTS_CXX11_FLAG )
74 message(WARNING "-std=c++0x not supported.")
75 endif()
c1845dd9 »
2012-03-08 Sources now require C++11 to build.
76 endif()
77
78
2ec63a36 »
2011-12-18 Initial commit. Code by Nick Kledzik. Cleanups and build system by me.
79 macro(add_lld_library name)
80 llvm_process_sources(srcs ${ARGN})
81 if (MSVC_IDE OR XCODE)
82 string(REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR})
83 list(GET split_path -1 dir)
84 file(GLOB_RECURSE headers
85 ../../include/lld${dir}/*.h)
86 set(srcs ${srcs} ${headers})
87 endif()
88 if (MODULE)
89 set(libkind MODULE)
90 elseif (SHARED_LIBRARY)
91 set(libkind SHARED)
92 else()
93 set(libkind)
94 endif()
95 add_library(${name} ${libkind} ${srcs})
96 if (LLVM_COMMON_DEPENDS)
97 add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
98 endif()
99
100 target_link_libraries(${name} ${LLVM_USED_LIBS})
101 llvm_config(${name} ${LLVM_LINK_COMPONENTS})
102 target_link_libraries(${name} ${LLVM_COMMON_LIBS})
103 link_system_libs(${name})
104
105 if(MSVC)
106 get_target_property(cflag ${name} COMPILE_FLAGS)
107 if(NOT cflag)
108 set(cflag "")
109 endif(NOT cflag)
110 set(cflag "${cflag} /Za")
111 set_target_properties(${name} PROPERTIES COMPILE_FLAGS ${cflag})
112 endif(MSVC)
113 install(TARGETS ${name}
114 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
115 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
116 set_target_properties(${name} PROPERTIES FOLDER "lld libraries")
117 endmacro(add_lld_library)
118
119 macro(add_lld_executable name)
120 add_llvm_executable(${name} ${ARGN})
121 set_target_properties(${name} PROPERTIES FOLDER "lld executables")
122 endmacro(add_lld_executable)
123
124 include_directories(BEFORE
125 ${CMAKE_CURRENT_BINARY_DIR}/include
126 ${CMAKE_CURRENT_SOURCE_DIR}/include
127 )
128
129 install(DIRECTORY include/
130 DESTINATION include
131 FILES_MATCHING
132 PATTERN "*.h"
133 PATTERN ".svn" EXCLUDE
134 )
135
136 add_subdirectory(lib)
137 add_subdirectory(tools)
138
139 add_subdirectory(test)
Something went wrong with that request. Please try again.