AMDGPU: Fix warnings introduced by r310336
[llvm-project.git] / llgo / CMakeLists.txt
blobabe89624aa15cfa3c4a874cc374922c5912e6ab9
1 include(ExternalProject)
2 include(ProcessorCount)
4 # Provide a config.h which exposes build system information.
5 configure_file(
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
13   build/context.go
14   cmd/gllgo/gllgo.go
15   debug/debug.go
16   driver/parser.go
17   irgen/annotations.go
18   irgen/attribute.go
19   irgen/builtins.go
20   irgen/cabi.go
21   irgen/call.go
22   irgen/channels.go
23   irgen/closures.go
24   irgen/compiler.go
25   irgen/errors.go
26   irgen/indirect.go
27   irgen/interfaces.go
28   irgen/maps.go
29   irgen/predicates.go
30   irgen/println.go
31   irgen/runtime.go
32   irgen/slice.go
33   irgen/ssa.go
34   irgen/strings.go
35   irgen/switches.go
36   irgen/targets.go
37   irgen/typemap.go
38   irgen/types.go
39   irgen/utils.go
40   irgen/value.go
41   irgen/version.go
42   ssaopt/esc.go
45 string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" LLGO_VERSION
46   ${PACKAGE_VERSION})
48 configure_file(
49   cmd/go/zdefaultcc.go.in
50   ${CMAKE_CURRENT_BINARY_DIR}/cmd/go/zdefaultcc.go)
52 set(LLGO_GO_SOURCES
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}
86           ${LLGO_GO_SOURCES}
87           ${CMAKE_CURRENT_BINARY_DIR}/libgo/zstdpkglist.go
88   DEPENDS llgo libgo ${LLGO_GO_SOURCES}
89   COMMENT "Building Go executable llgo-go"
90   VERBATIM)
91 add_custom_target(llgo-go ALL DEPENDS ${CMAKE_BINARY_DIR}/bin/llgo-go${CMAKE_EXECUTABLE_SUFFIX})
93 set(LLGO_CGO_SOURCES
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
107           ${LLGO_CGO_SOURCES}
108   DEPENDS llgo libgo ${LLGO_CGO_SOURCES}
109   COMMENT "Building Go executable cgo"
110   VERBATIM)
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}
138           cmd/llgoi/llgoi.go
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}
147         DESTINATION bin
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
154     DEPENDERS configure
155     ALWAYS 1
156     )
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..."
162     DEPENDERS configure
163     DEPENDS ${ARGN}
164     )
165 endfunction()
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}
176     INSTALL_COMMAND ""
177     LOG_CONFIGURE 1
178     LOG_BUILD 1
179   )
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}
191     INSTALL_COMMAND ""
192     LOG_CONFIGURE 1
193     LOG_BUILD 1
194   )
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}
207     LOG_CONFIGURE 1
208     LOG_BUILD 1
209     LOG_INSTALL 1
210   )
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})
217 endfunction()
219 add_libgo_variant("" "" "" "" FALSE)
221 if(TARGET asan)
222   add_libgo_variant("_asan" "-fsanitize=address" "-fsanitize=address" asan TRUE)
223 endif()
225 if(TARGET tsan)
226   add_libgo_variant("_tsan" "-fsanitize=thread" "-fsanitize=thread" tsan TRUE)
227 endif()
229 if(TARGET msan)
230   add_libgo_variant("_msan" "-fsanitize=memory" "-fsanitize=memory" msan TRUE)
231 endif()
233 if(TARGET dfsan)
234   add_libgo_variant("_dfsan" "-fsanitize=dataflow" "-fsanitize=dataflow" dfsan TRUE)
235 endif()
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
251   DEPENDS libgo
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)