-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
155 lines (126 loc) · 5.6 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# Copyright 2018 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
# Notes:
#
# The code in gofrontend depends on functions from GMP, MPC, and MPFR;
# these libraries are currently handled via the cmake "ExternalProject"
# utility.
#
include(ExternalProject)
include(ProcessorCount)
include(LLVMExternalProjectUtils)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
set(GOLLVM_USE_SPLIT_STACK ON CACHE BOOL "use split stack by default")
set(GOLLVM_DEFAULT_LINKER gold CACHE STRING "default linker for Go links")
include(CmakeUtils)
include(AddGollvm)
# So that we can issue "make -jN" cmds in externalproject_add
processorcount(PROCESSOR_COUNT)
set(EXTINSTALLDIR ${CMAKE_CURRENT_BINARY_DIR}/external/install)
set(EXTLIBDIR "${EXTINSTALLDIR}/lib")
set(EXTINCLUDEDIR "${EXTINSTALLDIR}/include")
set(EXTCPPFLAGS "CFLAGS=-I${EXTINCLUDEDIR}")
if(NOT "${CMAKE_SYSROOT}" STREQUAL "")
string(APPEND EXTCPPFLAGS " --sysroot=${CMAKE_SYSROOT}")
endif()
if(LLVM_ENABLE_PIC)
string(APPEND EXTCPPFLAGS " -fPIC -DPIC")
endif()
set(EXTLDFLAGS "LDFLAGS=-L${EXTLIBDIR}")
set(EXTCC "CC=${CMAKE_C_COMPILER}" "CXX=${CMAKE_CXX_COMPILER}")
set(gollvm_binroot "${CMAKE_CURRENT_BINARY_DIR}")
# Set MPN path according to the target processor
string(REGEX REPLACE "-" " " lht_components ${LLVM_DEFAULT_TARGET_TRIPLE})
separate_arguments(lht_components)
list(GET lht_components 0 llarch)
if( ${llarch} STREQUAL "x86_64" )
set(MPN_PATH "x86_64 generic")
elseif( ${llarch} STREQUAL "aarch64" )
set(MPN_PATH "arm64 generic")
elseif( ${llarch} STREQUAL "riscv64" )
set(MPN_PATH "riscv generic")
else()
message(SEND_ERROR "Arch ${llarch} not yet supported")
endif()
externalproject_add(libgmp
URL https://gmplib.org/download/gmp/gmp-6.2.0.tar.bz2 https://mirrors.kernel.org/gnu/gmp/gmp-6.2.0.tar.bz2
URL_MD5 c24161e0dd44cae78cd5f67193492a21
DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}/external-downloads
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/external/gmp-build
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/external/gmp
CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=${EXTINSTALLDIR} ${EXTCPPFLAGS} ${EXTLDFLAGS} ${EXTCC} --build=${LLVM_HOST_TRIPLE} --host=${LLVM_DEFAULT_TARGET_TRIPLE} MPN_PATH=${MPN_PATH}
BUILD_COMMAND make -j${PROCESSOR_COUNT} install
LOG_CONFIGURE 1
LOG_BUILD 1
LOG_INSTALL 1
)
externalproject_add(libmpfr
DEPENDS libgmp
URL https://www.mpfr.org/mpfr-current/mpfr-4.1.0.tar.bz2 https://mirrors.kernel.org/gnu/mpfr/mpfr-4.1.0.tar.bz2
URL_MD5 44b892bc5a45bafb4294d134e13aad1d
DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}/external-downloads
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/external/mpfr
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/external/mpfr
CONFIGURE_COMMAND <SOURCE_DIR>/configure --with-gmp=${CMAKE_CURRENT_BINARY_DIR}/external/gmp --prefix=${EXTINSTALLDIR} ${EXTCPPFLAGS} ${EXTLDFLAGS} ${EXTCC} -build=${LLVM_HOST_TRIPLE} --host=${LLVM_DEFAULT_TARGET_TRIPLE}
BUILD_COMMAND make -j${PROCESSOR_COUNT} install
LOG_CONFIGURE 1
LOG_BUILD 1
LOG_INSTALL 1
)
externalproject_add(libmpc
DEPENDS libgmp libmpfr
URL https://ftp.gnu.org/gnu/mpc/mpc-1.2.0.tar.gz https://mirrors.kernel.org/gnu/mpc/mpc-1.2.0.tar.gz
URL_MD5 2f1ce56ac775f2be090863f364931a03
DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}/external-downloads
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/external/mpc
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/external/mpc
PREFIX ${EXTINSTALLDIR}
CONFIGURE_COMMAND <SOURCE_DIR>/configure --with-gmp=${CMAKE_CURRENT_BINARY_DIR}/external/gmp --with-mpfr=${CMAKE_CURRENT_BINARY_DIR}/external/mpfr --prefix=${EXTINSTALLDIR} ${EXTCPPFLAGS} ${EXTLDFLAGS} ${EXTCC} -build=${LLVM_HOST_TRIPLE} --host=${LLVM_DEFAULT_TARGET_TRIPLE}
BUILD_COMMAND make -j${PROCESSOR_COUNT} install
LOG_CONFIGURE 1
LOG_BUILD 1
LOG_INSTALL 1
)
# Top level targets for building, installing
add_custom_target(gollvm ALL)
add_custom_target(install-gollvm)
# In most use cases, we want to force a rebuild of all objects built
# from Go source if the compiler changes.
set(gocdep llvm-goc llvm-goc-token)
# For compiler developers, however, the dependence this can be a
# hassle-- when hacking on the compiler, it is annoying to have each
# tiny change force a library rebuild, so the DISABLE_LIBGO_GOC_DEP can
# be set as an (unsafe) escape hatch to break the dependence from golibs
# to compiler. In this case we still need to insure that the compiler
# exists, but we don't care whether it is up to date or not.
if (DISABLE_LIBGO_GOC_DEP)
set(gocdep llvm-goc-token)
endif()
# Root of gollvm source code.
set(GOLLVM_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
# Location of gofrontend source code.
set(GOFRONTEND_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/gofrontend/go)
# Location of bridge source code.
set(BRIDGE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/bridge)
# Location of gollvm specific passes source code.
set(PASSES_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/passes)
# Location of driver utilities source code.
set(DRIVER_UTILS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/driver)
# Subdirectory for the middle layer that translates Backend method
# calls into LLVM IR.
add_subdirectory(bridge)
# Subdirectory for gollvm specific backend passes.
add_subdirectory(passes)
# Subdirectory for compiler driver utilities library.
add_subdirectory(driver)
# Subdirectory for compiler driver executable.
add_subdirectory(driver-main)
# Go standard library
add_subdirectory(libgo)
# Go tools (go, gofmt, etc)
add_subdirectory(gotools)
# Subdir for unit tests
add_subdirectory(unittests)
# Top-level check target for gollvm
add_custom_target(check-gollvm DEPENDS check-libgo check-gotools)