1 include(ExternalProject)
2 include(ProcessorCount)
4 # Provide a config.h which exposes build system information.
6 cmd/gllgo/config.h.cmake
7 ${CMAKE_CURRENT_BINARY_DIR}/cmd/gllgo/config.h)
8 include_directories(${CMAKE_CURRENT_BINARY_DIR}/cmd/gllgo)
10 list(APPEND LLVM_GO_PACKAGES "llvm.org/llgo=${CMAKE_CURRENT_SOURCE_DIR}")
12 llvm_add_go_executable(llgo llvm.org/llgo/cmd/gllgo ALL DEPENDS
45 string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" LLGO_VERSION
49 cmd/go/zdefaultcc.go.in
50 ${CMAKE_CURRENT_BINARY_DIR}/cmd/go/zdefaultcc.go)
53 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/go/build.go
54 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/go/clean.go
55 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/go/context.go
56 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/go/discovery.go
57 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/go/doc.go
58 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/go/env.go
59 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/go/fix.go
60 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/go/fmt.go
61 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/go/generate.go
62 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/go/get.go
63 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/go/go11.go
64 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/go/help.go
65 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/go/http.go
66 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/go/list.go
67 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/go/main.go
68 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/go/note.go
69 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/go/pkg.go
70 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/go/run.go
71 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/go/signal.go
72 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/go/signal_unix.go
73 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/go/testflag.go
74 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/go/test.go
75 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/go/tool.go
76 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/go/vcs.go
77 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/go/version.go
78 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/go/vet.go
79 ${CMAKE_CURRENT_BINARY_DIR}/cmd/go/zdefaultcc.go
82 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/bin/llgo-go${CMAKE_EXECUTABLE_SUFFIX}
83 COMMAND ${CMAKE_BINARY_DIR}/bin/llgo -static-libgo
84 -I ${CMAKE_CURRENT_BINARY_DIR}/libgo
85 -o ${CMAKE_BINARY_DIR}/bin/llgo-go${CMAKE_EXECUTABLE_SUFFIX}
87 ${CMAKE_CURRENT_BINARY_DIR}/libgo/zstdpkglist.go
88 DEPENDS llgo libgo ${LLGO_GO_SOURCES}
89 COMMENT "Building Go executable llgo-go"
91 add_custom_target(llgo-go ALL DEPENDS ${CMAKE_BINARY_DIR}/bin/llgo-go${CMAKE_EXECUTABLE_SUFFIX})
94 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/cgo/ast.go
95 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/cgo/doc.go
96 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/cgo/gcc.go
97 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/cgo/godefs.go
98 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/cgo/main.go
99 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/cgo/out.go
100 ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo/go/cmd/cgo/util.go
101 ${CMAKE_CURRENT_SOURCE_DIR}/cmd/cgo/zdefaultcc.go
104 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/lib/go/llgo-${LLGO_VERSION}/cgo
105 COMMAND ${CMAKE_BINARY_DIR}/bin/llgo -static-libgo
106 -o ${CMAKE_BINARY_DIR}/lib/go/llgo-${LLGO_VERSION}/cgo
108 DEPENDS llgo libgo ${LLGO_CGO_SOURCES}
109 COMMENT "Building Go executable cgo"
111 add_custom_target(cgo ALL DEPENDS ${CMAKE_BINARY_DIR}/lib/go/llgo-${LLGO_VERSION}/cgo)
113 llvm_add_go_executable(llgo-stage2 llvm.org/llgo/cmd/gllgo
114 DEPENDS libgo ${CMAKE_BINARY_DIR}/bin/llgo${CMAKE_EXECUTABLE_SUFFIX}
115 ${CMAKE_BINARY_DIR}/lib/go/llgo-${LLGO_VERSION}/cgo
116 ${CMAKE_BINARY_DIR}/bin/llgo-go${CMAKE_EXECUTABLE_SUFFIX}
117 GOFLAGS "cc=${CMAKE_BINARY_DIR}/bin/clang"
118 "cxx=${CMAKE_BINARY_DIR}/bin/clang++"
119 "go=${CMAKE_BINARY_DIR}/bin/llgo-go"
122 llvm_add_go_executable(llgo-stage3 llvm.org/llgo/cmd/gllgo
123 DEPENDS libgo ${CMAKE_BINARY_DIR}/bin/llgo-stage2${CMAKE_EXECUTABLE_SUFFIX}
124 GOFLAGS "cc=${CMAKE_BINARY_DIR}/bin/clang"
125 "cxx=${CMAKE_BINARY_DIR}/bin/clang++"
126 "go=${CMAKE_BINARY_DIR}/bin/llgo-go"
127 "llgo=${CMAKE_BINARY_DIR}/bin/llgo-stage2${CMAKE_EXECUTABLE_SUFFIX}"
130 llvm_add_go_executable(cc-wrapper llvm.org/llgo/cmd/cc-wrapper DEPENDS
131 cmd/cc-wrapper/main.go
134 llvm_add_go_executable(llgoi llvm.org/llgo/cmd/llgoi ALL
135 DEPENDS libgo ${CMAKE_BINARY_DIR}/bin/llgo${CMAKE_EXECUTABLE_SUFFIX}
136 ${CMAKE_BINARY_DIR}/lib/go/llgo-${LLGO_VERSION}/cgo
137 ${CMAKE_BINARY_DIR}/bin/llgo-go${CMAKE_EXECUTABLE_SUFFIX}
139 GOFLAGS "cc=${CMAKE_BINARY_DIR}/bin/clang"
140 "cxx=${CMAKE_BINARY_DIR}/bin/clang++"
141 "go=${CMAKE_BINARY_DIR}/bin/llgo-go"
144 install(FILES ${CMAKE_BINARY_DIR}/bin/llgo${CMAKE_EXECUTABLE_SUFFIX}
145 ${CMAKE_BINARY_DIR}/bin/llgoi${CMAKE_EXECUTABLE_SUFFIX}
146 ${CMAKE_BINARY_DIR}/bin/llgo-go${CMAKE_EXECUTABLE_SUFFIX}
148 PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
149 GROUP_READ GROUP_EXECUTE
150 WORLD_READ WORLD_EXECUTE)
152 function(add_clobber_steps name)
153 ExternalProject_Add_Step(${name} force-reconfigure
158 ExternalProject_Add_Step(${name} clobber
159 COMMAND ${CMAKE_COMMAND} -E remove_directory <BINARY_DIR>
160 COMMAND ${CMAKE_COMMAND} -E make_directory <BINARY_DIR>
161 COMMENT "Clobbering ${name} build directory..."
167 processorcount(PROCESSOR_COUNT)
169 function(add_libgo_variant suffix cflags gocflags deps exclude_from_all)
170 externalproject_add(libbacktrace${suffix}
171 DEPENDS clang ${deps}
172 SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libbacktrace
173 BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${suffix}/libbacktrace
174 CONFIGURE_COMMAND <SOURCE_DIR>/configure --disable-multilib --enable-host-shared "CC=${CMAKE_BINARY_DIR}/bin/clang ${cflags}"
175 BUILD_COMMAND make -j${PROCESSOR_COUNT}
180 set_property(TARGET libbacktrace${suffix}
181 PROPERTY EXCLUDE_FROM_ALL ${exclude_from_all})
183 add_clobber_steps(libbacktrace${suffix} clang ${deps})
185 externalproject_add(libffi${suffix}
186 DEPENDS clang ${deps}
187 SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libffi
188 BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${suffix}/libffi
189 CONFIGURE_COMMAND <SOURCE_DIR>/configure --disable-multilib "CC=${CMAKE_BINARY_DIR}/bin/clang ${cflags}"
190 BUILD_COMMAND make -j${PROCESSOR_COUNT}
195 set_property(TARGET libffi${suffix}
196 PROPERTY EXCLUDE_FROM_ALL ${exclude_from_all})
198 add_clobber_steps(libffi${suffix} clang ${deps})
200 externalproject_add(libgo${suffix}
201 DEPENDS clang llgo cc-wrapper libbacktrace${suffix} libffi${suffix} ${deps}
202 SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gofrontend/libgo
203 BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${suffix}/libgo
204 INSTALL_DIR ${CMAKE_BINARY_DIR}
205 CONFIGURE_COMMAND <SOURCE_DIR>/configure --disable-multilib --without-libatomic --prefix=<INSTALL_DIR> "CC=env REAL_CC=${CMAKE_BINARY_DIR}/bin/clang@SPACE@${cflags} ${CMAKE_BINARY_DIR}/bin/cc-wrapper" "GOC=${CMAKE_BINARY_DIR}/bin/llgo -no-prefix -fcompilerrt-prefix=${CMAKE_BINARY_DIR} ${gocflags}"
206 BUILD_COMMAND make -j${PROCESSOR_COUNT}
211 set_property(TARGET libgo${suffix}
212 PROPERTY EXCLUDE_FROM_ALL ${exclude_from_all})
214 add_clobber_steps(libgo${suffix} clang
215 ${CMAKE_BINARY_DIR}/bin/llgo${CMAKE_EXECUTABLE_SUFFIX}
216 ${CMAKE_BINARY_DIR}/bin/cc-wrapper${CMAKE_EXECUTABLE_SUFFIX})
219 add_libgo_variant("" "" "" "" FALSE)
222 add_libgo_variant("_asan" "-fsanitize=address" "-fsanitize=address" asan TRUE)
226 add_libgo_variant("_tsan" "-fsanitize=thread" "-fsanitize=thread" tsan TRUE)
230 add_libgo_variant("_msan" "-fsanitize=memory" "-fsanitize=memory" msan TRUE)
234 add_libgo_variant("_dfsan" "-fsanitize=dataflow" "-fsanitize=dataflow" dfsan TRUE)
237 set(LLGO_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX})
239 install(FILES ${LLGO_LIBRARY_DIR}/libgo-llgo.a
240 ${LLGO_LIBRARY_DIR}/libgo-llgo.so
241 ${LLGO_LIBRARY_DIR}/libgo-llgo.so.8
242 ${LLGO_LIBRARY_DIR}/libgo-llgo.so.8.0.0
243 ${LLGO_LIBRARY_DIR}/libgobegin-llgo.a
244 DESTINATION lib${LLVM_LIBDIR_SUFFIX})
246 install(DIRECTORY ${LLGO_LIBRARY_DIR}/go
247 DESTINATION lib${LLVM_LIBDIR_SUFFIX})
249 add_custom_target(check-libgo
250 COMMAND make -C ${CMAKE_CURRENT_BINARY_DIR}/libgo -j${PROCESSOR_COUNT} check
252 ${cmake_3_2_USES_TERMINAL}
253 COMMENT "Running libgo tests")
255 add_custom_target(check-llgo-bootstrap
256 COMMAND strip -R .note.gnu.build-id -o ${CMAKE_CURRENT_BINARY_DIR}/llgo-stage2.stripped
257 ${CMAKE_BINARY_DIR}/bin/llgo-stage2${CMAKE_EXECUTABLE_SUFFIX}
258 COMMAND strip -R .note.gnu.build-id -o ${CMAKE_CURRENT_BINARY_DIR}/llgo-stage3.stripped
259 ${CMAKE_BINARY_DIR}/bin/llgo-stage3${CMAKE_EXECUTABLE_SUFFIX}
260 COMMAND cmp ${CMAKE_CURRENT_BINARY_DIR}/llgo-stage2.stripped
261 ${CMAKE_CURRENT_BINARY_DIR}/llgo-stage3.stripped
262 DEPENDS llgo-stage2 llgo-stage3
263 COMMENT "Checking llgo bootstrap")
265 add_subdirectory(test)