forked from OpenCilk/cheetah
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
228 lines (185 loc) · 7.75 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# CMake build for Cheetah.
cmake_minimum_required(VERSION 3.9)
# Add path for custom cheetah modules.
set(CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
${CMAKE_MODULE_PATH}
)
# Check if cheetah is built as a standalone project.
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR CHEETAH_STANDALONE_BUILD)
project(Cheetah CXX C)
set(CHEETAH_STANDALONE_BUILD TRUE)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(PACKAGE_NAME Cheetah)
set(PACKAGE_VERSION 14.0.6)
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_BUGREPORT "https://github.com/OpenCilk/cheetah/issues/")
endif()
# Require out of source build.
include(MacroEnsureOutOfSourceBuild)
MACRO_ENSURE_OUT_OF_SOURCE_BUILD(
"${PROJECT_NAME} requires an out of source build. Please create a separate
build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there."
)
# Option to build cheetah into separate directories per target.
# Defaults to true.
option(CHEETAH_DIRECTORY_PER_TARGET "Build cheetah into a separate directory per target." ON)
if (LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
set(CHEETAH_ENABLE_PER_TARGET_RUNTIME_DIR ${LLVM_ENABLE_PER_TARGET_RUNTIME_DIR})
else()
set(CHEETAH_ENABLE_PER_TARGET_RUNTIME_DIR ${CHEETAH_DIRECTORY_PER_TARGET})
endif()
include(base-config-ix)
include(CheetahUtils)
#===============================================================================
# Setup CMake Options
#===============================================================================
include(CMakeDependentOption)
include(HandleCompilerRT)
# Basic options ---------------------------------------------------------------
option(CHEETAH_ENABLE_ASSERTIONS "Enable assertions independent of build mode." OFF)
option(CHEETAH_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
option(CHEETAH_USE_COMPILER_RT "Use compiler-rt instead of libgcc" OFF)
option(CHEETAH_INCLUDE_TESTS "Generate build targets for the cheetah unit tests." ${LLVM_INCLUDE_TESTS})
option(CHEETAH_INSTALL_LIBRARY "Install the cheetah library." ON)
option(CHEETAH_ENABLE_SHARED "Build cheetah as a shared library." ON)
option(CHEETAH_ENABLE_STATIC "Build cheetah as a static library." ON)
option(CHEETAH_ENABLE_ASAN "Build cheetah with ASan support." ON)
option(CHEETAH_EMULATE_TLS "Build Cheetah with emulated TLS. Necessary for some JITs." OFF)
set(CHEETAH_ABI_VERSION "1" CACHE STRING "ABI version of cheetah. Defaults to 1.")
if (NOT CHEETAH_ENABLE_SHARED AND NOT CHEETAH_ENABLE_STATIC)
message(FATAL_ERROR "cheetah must be built as either a shared or static library.")
endif()
# Target options --------------------------------------------------------------
# Default minimum OSX version to support, if
# CMAKE_OSX_DEPLOYMENT_TARGET is not specified
set(DEFAULT_CHEETAH_MIN_OSX_VERSION 10.14)
#===============================================================================
# Configure System
#===============================================================================
if (CHEETAH_STANDALONE_BUILD)
load_llvm_config()
if (TARGET intrinsics_gen)
# Loading the llvm config causes this target to be imported so place it
# under the appropriate folder in an IDE.
set_target_properties(intrinsics_gen PROPERTIES FOLDER "Cheetah Misc")
endif()
find_package(Python3 COMPONENTS Interpreter)
if(NOT Python3_Interpreter_FOUND)
message(WARNING "Python3 not found, using python2 as a fallback")
find_package(Python2 COMPONENTS Interpreter REQUIRED)
if(Python2_VERSION VERSION_LESS 2.7)
message(SEND_ERROR "Python 2.7 or newer is required")
endif()
# Treat python2 as python3
add_executable(Python3::Interpreter IMPORTED)
set_target_properties(Python3::Interpreter PROPERTIES
IMPORTED_LOCATION ${Python2_EXECUTABLE})
set(Python3_EXECUTABLE ${Python2_EXECUTABLE})
endif()
# Ensure that fat libraries are built correctly on Darwin
if(APPLE)
include(UseLibtool)
endif()
# Define default arguments to lit.
set(LIT_ARGS_DEFAULT "-sv")
if (MSVC OR XCODE)
set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
endif()
set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
set(LLVM_LIT_OUTPUT_DIR "${CHEETAH_EXEC_OUTPUT_DIR}")
# Define llvm-link path
set(LLVM_LINK_PATH "${LLVM_TOOLS_BINARY_DIR}/llvm-link")
endif()
construct_cheetah_default_triple()
if ("${CHEETAH_DEFAULT_TARGET_TRIPLE}" MATCHES ".*hf$")
if (${CHEETAH_DEFAULT_TARGET_ARCH} MATCHES "^arm")
set(CHEETAH_DEFAULT_TARGET_ARCH "armhf")
endif()
endif()
set(CHEETAH_C_FLAGS "")
if (CHEETAH_EMULATE_TLS)
set(CHEETAH_CXX_FLAGS "-femulated-tls")
set(CHEETAH_COMPILE_FLAGS "-femulated-tls")
else()
set(CHEETAH_CXX_FLAGS "")
set(CHEETAH_COMPILE_FLAGS "")
endif()
set(CHEETAH_COMPILE_DEFS "")
set(CHEETAH_LINK_FLAGS "")
set(CHEETAH_COMMON_LIBS "")
option(CHEETAH_EXTERNALIZE_DEBUGINFO
"Generate dSYM files and strip executables and libraries (Darwin Only)" OFF)
# Include macros for adding and removing cheetah flags.
include(HandleCheetahFlags)
#===============================================================================
# Setup Compiler Flags
#===============================================================================
# Configure compiler.
include(config-ix)
if (CHEETAH_USE_COMPILER_RT)
list(APPEND CHEETAH_LINK_FLAGS "--rtlib=compiler-rt")
endif()
# Get warning flags
add_compile_flags_if_supported(-Wall)
if (CHEETAH_ENABLE_WERROR)
add_compile_flags_if_supported(-Werror)
else()
add_compile_flags_if_supported(-Wno-error)
endif()
# The spawn_main symbol in cheetah is undefined. This routine
# corresponds to the entry point of the compiled Cilk program.
set(CHEETAH_HAS_UNDEFINED_SYMBOLS ON)
if (CHEETAH_HAS_UNDEFINED_SYMBOLS)
# Need to allow unresolved symbols if this is to work with shared library builds
if (APPLE)
list(APPEND CHEETAH_LINK_FLAGS "-undefined dynamic_lookup")
else()
# Relax this restriction from HandleLLVMOptions
string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
endif()
endif()
string(REPLACE ";" " " CHEETAH_CXX_FLAGS "${CHEETAH_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CHEETAH_CXX_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CHEETAH_C_FLAGS}")
include(AddCheetah)
#===============================================================================
# Setup Source Code
#===============================================================================
include_directories(runtime)
# Add source code. This also contains all of the logic for deciding linker flags
# soname, etc...
add_subdirectory(include)
add_subdirectory(runtime)
if (CHEETAH_INCLUDE_TESTS)
# TODO: Set up CMake for Cheetah tests.
# add_subdirectory(handcomp_test)
# add_subdirectory(bench)
endif()
#===============================================================================
# Setup CMAKE CONFIG PACKAGE
#===============================================================================
make_directory(${CHEETAH_CMAKE_BUILDDIR})
set(CHEETHA_LIBRARY_HOST "/lib/${LLVM_HOST_TARGET}")
if(CHEETAH_INSTALL_LIBRARY)
set(CHEETAH_LIBRARY_DIR "")
if (LLVM_TREE_AVAILABLE)
set(CHEETAH_LIBRARY_DIR "${CMAKE_INSTALL_PREFIX}/${CHEETAH_LIBRARY_INSTALL_DIR}")
else()
set(CHEETAH_LIBRARY_DIR "${CMAKE_INSTALL_PREFIX}")
endif()
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/CilkThreadsConfig.cmake.in
${CHEETAH_CMAKE_BUILDDIR}/CilkThreadsConfig.cmake
NO_SOURCE_PERMISSIONS
@ONLY)
else()
set(CHEETAH_LIBRARY_DIR ${CHEETAH_LIBRARY_OUTPUT_DIR})
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/CilkThreadsConfig.cmake.in
${CHEETAH_CMAKE_BUILDDIR}/CilkThreadsConfig.cmake
NO_SOURCE_PERMISSIONS
@ONLY)
endif()
install(FILES ${CHEETAH_CMAKE_BUILDDIR}/CilkThreadsConfig.cmake DESTINATION ${CHEETAH_CMAKE_INSTALLDIR})