forked from halide/Halide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
209 lines (187 loc) · 7.15 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
project(Halide)
cmake_minimum_required(VERSION 2.8.12)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(LLVM_BIN "llvm3.6/bin/Debug/"
CACHE PATH "Path to LLVM bin directory")
set(LLVM_LIB "llvm3.6/lib/Debug/"
CACHE PATH "Path to LLVM lib directory")
set(LLVM_INCLUDE "llvm3.6/include/"
CACHE PATH "Path to LLVM include directory")
set(LLVM_VERSION "36" CACHE STRING "First two digits of LLVM version (omitting '.')")
file(TO_NATIVE_PATH "${LLVM_BIN}/llvm-as${CMAKE_EXECUTABLE_SUFFIX}" LLVM_AS)
file(TO_NATIVE_PATH "${LLVM_BIN}/llvm-nm${CMAKE_EXECUTABLE_SUFFIX}" LLVM_NM)
file(TO_NATIVE_PATH "${LLVM_BIN}/clang${CMAKE_EXECUTABLE_SUFFIX}" CLANG)
# Check LLVM
function(check_dir VARNAME PATH)
if (NOT IS_ABSOLUTE "${PATH}")
message(FATAL_ERROR "\"${PATH}\" (${VARNAME}) must be an absolute path")
endif()
if (NOT IS_DIRECTORY "${PATH}")
message(FATAL_ERROR "\"${PATH}\" (${VARNAME}) must be a directory")
endif()
endfunction()
function(check_tool_exists NAME PATH)
# Need to convert to CMake path so that backslashes don't get
# interpreted as an escape.
file(TO_CMAKE_PATH "${PATH}" TOOL_PATH)
if (NOT EXISTS "${TOOL_PATH}")
message(FATAL_ERROR "Tool ${NAME} not found at ${TOOL_PATH}")
endif()
message(STATUS "Using ${NAME} at ${TOOL_PATH}")
endfunction()
# Notify the user what paths and LLVM version we are using
message(STATUS "LLVM_BIN:${LLVM_BIN}")
message(STATUS "LLVM_LIB:${LLVM_LIB}")
message(STATUS "LLVM_INCLUDE:${LLVM_INCLUDE}")
message(STATUS "LLVM_VERSION:${LLVM_VERSION}")
# Check path to LLVM directories exist
check_dir(LLVM_BIN "${LLVM_BIN}")
check_dir(LLVM_LIB "${LLVM_LIB}")
# Include might be a list of directories if LLVM was built out of source
foreach( include_dir ${LLVM_INCLUDE})
check_dir(LLVM_INCLUDE "${include_dir}")
endforeach()
# Check LLVM tools exist
check_tool_exists(llvm-as "${LLVM_AS}")
check_tool_exists(llvm-nm "${LLVM_NM}")
check_tool_exists(clang "${CLANG}")
# Check reported LLVM version
if (NOT "${LLVM_VERSION}" MATCHES "^[0-9][0-9]$")
message(FATAL_ERROR "LLVM_VERSION not specified correctly. Must be <major><minor> E.g. LLVM 3.5 is \"35\"")
endif()
if (LLVM_VERSION LESS 35)
message(FATAL_ERROR "LLVM version must be 3.5 or newer")
endif()
option(TARGET_NATIVE_CLIENT "Include Native Client" OFF)
option(TARGET_X86 "Include x86 target" ON)
option(TARGET_ARM "Include ARM target" ON)
option(TARGET_AARCH64 "Include AARCH64 (arm64) target" ON)
option(TARGET_METAL "Include Metal target" ON)
option(TARGET_MIPS "Include MIPS target" ON)
option(TARGET_PTX "Include PTX target" ON)
option(TARGET_OPENCL "Include OpenCL-C target" ON)
option(TARGET_OPENGL "Include OpenGL/GLSL target" ON)
option(TARGET_OPENGLCOMPUTE "Include OpenGLCompute target" ON)
option(HALIDE_SHARED_LIBRARY "Build as a shared library" ON)
function(halide_project name folder)
add_executable("${name}" ${ARGN})
target_link_libraries("${name}" PRIVATE Halide)
target_include_directories("${name}" PRIVATE "${CMAKE_SOURCE_DIR}/src")
set_target_properties("${name}" PROPERTIES FOLDER "${folder}")
if (WIN32)
set_target_properties("${name}" PROPERTIES LINK_FLAGS "/STACK:8388608,1048576")
target_compile_definitions("${name}" PRIVATE _CRT_SECURE_NO_WARNINGS)
target_link_libraries("${name}" PRIVATE Kernel32)
endif()
endfunction(halide_project)
# Set warnings globally
option(WARNINGS_AS_ERRORS "Treat warnings as errors" ON)
if (WARNINGS_AS_ERRORS)
message(STATUS "WARNINGS_AS_ERRORS enabled")
else()
message(STATUS "WARNINGS_AS_ERRORS disabled")
endif()
if (NOT MSVC)
add_compile_options(-Wall
-Wno-unused-function
-Wcast-qual
-Woverloaded-virtual
-Wignored-qualifiers)
if (WARNINGS_AS_ERRORS)
add_compile_options(-Werror)
endif()
else()
add_compile_options(/W3)
message(WARNING "WARNINGS_AS_ERROR is currently ignored for MSVC")
# TODO: Uncomment below and remove above warning once we can build without warnings
#if (WARNINGS_AS_ERRORS)
# add_compile_options(/WX)
#endif()
endif()
# Look for OpenMP
find_package(OpenMP QUIET)
if (OPENMP_FOUND)
message(STATUS "Found OpenMP")
endif()
# -----------------------------------------------------------------------------
# Option to enable/disable assertions
# -----------------------------------------------------------------------------
# Filter out definition of NDEBUG definition from the default build
# configuration flags. # We will add this ourselves if we want to disable
# assertions.
# FIXME: Perhaps our own default ``cxx_flags_overrides.cmake`` file would be better?
foreach (build_config Debug Release RelWithDebInfo MinSizeRel)
string(TOUPPER ${build_config} upper_case_build_config)
foreach (language CXX C)
set(VAR_TO_MODIFY "CMAKE_${language}_FLAGS_${upper_case_build_config}")
string(REGEX REPLACE "(^| )[/-]D *NDEBUG($| )"
" "
replacement
"${${VAR_TO_MODIFY}}"
)
#message("Original (${VAR_TO_MODIFY}) is ${${VAR_TO_MODIFY}} replacement is ${replacement}")
set(${VAR_TO_MODIFY} "${replacement}" CACHE STRING "Default flags for ${build_config} configuration" FORCE)
endforeach()
endforeach()
option(WITH_ASSERTIONS "Build with assertions enabled" ON)
if (WITH_ASSERTIONS)
# NDEBUG was already removed.
message(STATUS "Building with asserts")
else()
# Note this definition doesn't appear in the cache variables.
add_definitions(-DNDEBUG)
message(STATUS "Building without asserts")
endif()
add_subdirectory(src)
add_subdirectory(tools)
option(WITH_TESTS "Build tests" ON)
if (WITH_TESTS)
message(STATUS "Building tests enabled")
add_subdirectory(test)
else()
message(STATUS "Building tests disabled")
endif()
# Look for libpng. Some apps and tutorials depend on it
find_package(PNG)
option(WITH_APPS "Build apps" ON)
if (WITH_APPS)
if (NOT WIN32)
message(STATUS "Building apps enabled")
add_subdirectory(apps)
else()
message(WARNING "Apps cannot be built under Windows")
endif()
else()
message(STATUS "Building apps disabled")
endif()
option(WITH_TUTORIALS "Build Tutorials" ON)
if (WITH_TUTORIALS)
message(STATUS "Building tutorials enabled")
add_subdirectory(tutorial)
else()
message(STATUS "Building tutorials disabled")
endif()
option(WITH_DOCS "Enable building of documentation" OFF)
if (WITH_DOCS)
find_package(Doxygen)
if (NOT DOXYGEN_FOUND)
message(FATAL_ERROR "Could not find Doxygen. Either install it or set WITH_DOCS to OFF")
endif()
configure_file(${CMAKE_SOURCE_DIR}/Doxyfile.in ${CMAKE_BINARY_DIR}/Doxyfile @ONLY)
# Note documentation is not built by default, the user needs to build the "doc" target
add_custom_target(doc
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Building Doxygen documentation"
)
endif()
option(WITH_UTILS "Build utils" ON)
if (WITH_UTILS)
message(STATUS "Building utils enabled")
add_subdirectory(util)
else()
message(STATUS "Building utils disabled")
endif()