source: icGREP/icgrep-devel/llvm-3.8.0.src/CMakeLists.txt @ 5934

Last change on this file since 5934 was 5027, checked in by cameron, 3 years ago

Upgrade to llvm 3.8

File size: 26.8 KB
Line 
1# See docs/CMake.html for instructions about how to build LLVM with CMake.
2
3cmake_minimum_required(VERSION 2.8.12.2)
4
5if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
6  message(STATUS "No build type selected, default to Debug")
7  set(CMAKE_BUILD_TYPE "Debug")
8endif()
9
10if(POLICY CMP0022)
11  cmake_policy(SET CMP0022 NEW) # automatic when 2.8.12 is required
12endif()
13
14if (POLICY CMP0051)
15  # CMake 3.1 and higher include generator expressions of the form
16  # $<TARGETLIB:obj> in the SOURCES property.  These need to be
17  # stripped everywhere that access the SOURCES property, so we just
18  # defer to the OLD behavior of not including generator expressions
19  # in the output for now.
20  cmake_policy(SET CMP0051 OLD)
21endif()
22
23if(CMAKE_VERSION VERSION_LESS 3.1.20141117)
24  set(cmake_3_2_USES_TERMINAL)
25else()
26  set(cmake_3_2_USES_TERMINAL USES_TERMINAL)
27endif()
28
29if(NOT DEFINED LLVM_VERSION_MAJOR)
30  set(LLVM_VERSION_MAJOR 3)
31endif()
32if(NOT DEFINED LLVM_VERSION_MINOR)
33  set(LLVM_VERSION_MINOR 8)
34endif()
35if(NOT DEFINED LLVM_VERSION_PATCH)
36  set(LLVM_VERSION_PATCH 0)
37endif()
38if(NOT DEFINED LLVM_VERSION_SUFFIX)
39  set(LLVM_VERSION_SUFFIX "")
40endif()
41
42if (POLICY CMP0048)
43  cmake_policy(SET CMP0048 NEW)
44  set(cmake_3_0_PROJ_VERSION
45    VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH})
46  set(cmake_3_0_LANGUAGES LANGUAGES)
47endif()
48
49if (NOT PACKAGE_VERSION)
50  set(PACKAGE_VERSION
51    "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}")
52endif()
53
54project(LLVM
55  ${cmake_3_0_PROJ_VERSION}
56  ${cmake_3_0_LANGUAGES}
57  C CXX ASM)
58
59# The following only works with the Ninja generator in CMake >= 3.0.
60set(LLVM_PARALLEL_COMPILE_JOBS "" CACHE STRING
61  "Define the maximum number of concurrent compilation jobs.")
62if(LLVM_PARALLEL_COMPILE_JOBS)
63  if(CMAKE_VERSION VERSION_LESS 3.0 OR NOT CMAKE_MAKE_PROGRAM MATCHES "ninja")
64    message(WARNING "Job pooling is only available with Ninja generators and CMake 3.0 and later.")
65  else()
66    set_property(GLOBAL APPEND PROPERTY JOB_POOLS compile_job_pool=${LLVM_PARALLEL_COMPILE_JOBS})
67    set(CMAKE_JOB_POOL_COMPILE compile_job_pool)
68  endif()
69endif()
70
71set(LLVM_PARALLEL_LINK_JOBS "" CACHE STRING
72  "Define the maximum number of concurrent link jobs.")
73if(LLVM_PARALLEL_LINK_JOBS)
74  if(CMAKE_VERSION VERSION_LESS 3.0 OR NOT CMAKE_MAKE_PROGRAM MATCHES "ninja")
75    message(WARNING "Job pooling is only available with Ninja generators and CMake 3.0 and later.")
76  else()
77    set_property(GLOBAL APPEND PROPERTY JOB_POOLS link_job_pool=${LLVM_PARALLEL_LINK_JOBS})
78    set(CMAKE_JOB_POOL_LINK link_job_pool)
79  endif()
80endif()
81
82# Add path for custom modules
83set(CMAKE_MODULE_PATH
84  ${CMAKE_MODULE_PATH}
85  "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
86  "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
87  )
88
89# Generate a CompilationDatabase (compile_commands.json file) for our build,
90# for use by clang_complete, YouCompleteMe, etc.
91set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
92
93option(LLVM_INSTALL_UTILS "Include utility binaries in the 'install' target." OFF)
94
95option(LLVM_INSTALL_TOOLCHAIN_ONLY "Only include toolchain files in the 'install' target." OFF)
96
97option(LLVM_USE_FOLDERS "Enable solution folders in Visual Studio. Disable for Express versions." ON)
98if ( LLVM_USE_FOLDERS )
99  set_property(GLOBAL PROPERTY USE_FOLDERS ON)
100endif()
101
102include(VersionFromVCS)
103
104option(LLVM_APPEND_VC_REV
105  "Append the version control system revision id to LLVM version" OFF)
106
107if( LLVM_APPEND_VC_REV )
108  add_version_info_from_vcs(PACKAGE_VERSION)
109endif()
110
111set(PACKAGE_NAME LLVM)
112set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
113set(PACKAGE_BUGREPORT "http://llvm.org/bugs/")
114
115set(BUG_REPORT_URL "${PACKAGE_BUGREPORT}" CACHE STRING
116  "Default URL where bug reports are to be submitted.")
117
118# Configure CPack.
119set(CPACK_PACKAGE_INSTALL_DIRECTORY "LLVM")
120set(CPACK_PACKAGE_VENDOR "LLVM")
121set(CPACK_PACKAGE_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
122set(CPACK_PACKAGE_VERSION_MINOR ${LLVM_VERSION_MINOR})
123set(CPACK_PACKAGE_VERSION_PATCH ${LLVM_VERSION_PATCH})
124set(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION})
125set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.TXT")
126set(CPACK_NSIS_COMPRESSOR "/SOLID lzma \r\n SetCompressorDictSize 32")
127if(WIN32 AND NOT UNIX)
128  set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "LLVM")
129  set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_logo.bmp")
130  set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico")
131  set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\cmake\\\\nsis_icon.ico")
132  set(CPACK_NSIS_MODIFY_PATH "ON")
133  set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL "ON")
134  set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS
135    "ExecWait '$INSTDIR/tools/msbuild/install.bat'")
136  set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS
137    "ExecWait '$INSTDIR/tools/msbuild/uninstall.bat'")
138  if( CMAKE_CL_64 )
139    set(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64")
140  endif()
141endif()
142include(CPack)
143
144# Sanity check our source directory to make sure that we are not trying to
145# generate an in-tree build (unless on MSVC_IDE, where it is ok), and to make
146# sure that we don't have any stray generated files lying around in the tree
147# (which would end up getting picked up by header search, instead of the correct
148# versions).
149if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
150  message(FATAL_ERROR "In-source builds are not allowed.
151CMake would overwrite the makefiles distributed with LLVM.
152Please create a directory and run cmake from there, passing the path
153to this source directory as the last argument.
154This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
155Please delete them.")
156endif()
157if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
158  file(GLOB_RECURSE
159    tablegenned_files_on_include_dir
160    "${CMAKE_CURRENT_SOURCE_DIR}/include/llvm/*.gen")
161  file(GLOB_RECURSE
162    tablegenned_files_on_lib_dir
163    "${CMAKE_CURRENT_SOURCE_DIR}/lib/Target/*.inc")
164  if( tablegenned_files_on_include_dir OR tablegenned_files_on_lib_dir)
165    message(FATAL_ERROR "Apparently there is a previous in-source build,
166probably as the result of running `configure' and `make' on
167${CMAKE_CURRENT_SOURCE_DIR}.
168This may cause problems. The suspicious files are:
169${tablegenned_files_on_lib_dir}
170${tablegenned_files_on_include_dir}
171Please clean the source directory.")
172  endif()
173endif()
174
175string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
176
177if (CMAKE_BUILD_TYPE AND
178    NOT uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELEASE|RELWITHDEBINFO|MINSIZEREL)$")
179  message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
180endif()
181
182set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" )
183
184# They are used as destination of target generators.
185set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
186set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
187if(WIN32 OR CYGWIN)
188  # DLL platform -- put DLLs into bin.
189  set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
190else()
191  set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
192endif()
193
194# Each of them corresponds to llvm-config's.
195set(LLVM_TOOLS_BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) # --bindir
196set(LLVM_LIBRARY_DIR      ${LLVM_LIBRARY_OUTPUT_INTDIR}) # --libdir
197set(LLVM_MAIN_SRC_DIR     ${CMAKE_CURRENT_SOURCE_DIR}  ) # --src-root
198set(LLVM_MAIN_INCLUDE_DIR ${LLVM_MAIN_SRC_DIR}/include ) # --includedir
199set(LLVM_BINARY_DIR       ${CMAKE_CURRENT_BINARY_DIR}  ) # --prefix
200
201set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples)
202set(LLVM_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
203
204set(LLVM_ALL_TARGETS
205  AArch64
206  AMDGPU
207  ARM
208  BPF
209  CppBackend
210  Hexagon
211  Mips
212  MSP430
213  NVPTX
214  PowerPC
215  Sparc
216  SystemZ
217  X86
218  XCore
219  )
220
221# List of targets with JIT support:
222set(LLVM_TARGETS_WITH_JIT X86 PowerPC AArch64 ARM Mips SystemZ)
223
224set(LLVM_TARGETS_TO_BUILD "all"
225    CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
226
227set(LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ""
228  CACHE STRING "Semicolon-separated list of experimental targets to build.")
229
230option(BUILD_SHARED_LIBS
231  "Build all libraries as shared libraries instead of static" OFF)
232
233option(LLVM_ENABLE_TIMESTAMPS "Enable embedding timestamp information in build" ON)
234if(LLVM_ENABLE_TIMESTAMPS)
235  set(ENABLE_TIMESTAMPS 1)
236endif()
237
238option(LLVM_ENABLE_BACKTRACES "Enable embedding backtraces on crash." ON)
239if(LLVM_ENABLE_BACKTRACES)
240  set(ENABLE_BACKTRACES 1)
241endif()
242
243option(LLVM_ENABLE_CRASH_OVERRIDES "Enable crash overrides." ON)
244if(LLVM_ENABLE_CRASH_OVERRIDES)
245  set(ENABLE_CRASH_OVERRIDES 1)
246endif()
247
248option(LLVM_ENABLE_FFI "Use libffi to call external functions from the interpreter" OFF)
249set(FFI_LIBRARY_DIR "" CACHE PATH "Additional directory, where CMake should search for libffi.so")
250set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should search for ffi.h or ffi/ffi.h")
251
252set(LLVM_TARGET_ARCH "host"
253  CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
254
255option(LLVM_ENABLE_TERMINFO "Use terminfo database if available." ON)
256
257option(LLVM_ENABLE_THREADS "Use threads if available." ON)
258
259option(LLVM_ENABLE_ZLIB "Use zlib for compression/decompression if available." ON)
260
261if( LLVM_TARGETS_TO_BUILD STREQUAL "all" )
262  set( LLVM_TARGETS_TO_BUILD ${LLVM_ALL_TARGETS} )
263endif()
264
265set(LLVM_TARGETS_TO_BUILD
266   ${LLVM_TARGETS_TO_BUILD}
267   ${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD})
268list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
269
270include(AddLLVMDefinitions)
271
272option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
273option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
274option(LLVM_ENABLE_MODULES "Compile with C++ modules enabled." OFF)
275option(LLVM_ENABLE_CXX1Y "Compile with C++1y enabled." OFF)
276option(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF)
277option(LLVM_ENABLE_LIBCXXABI "Use libc++abi when using libc++." OFF)
278option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
279option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
280
281if( NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" )
282  option(LLVM_ENABLE_ASSERTIONS "Enable assertions" OFF)
283else()
284  option(LLVM_ENABLE_ASSERTIONS "Enable assertions" ON)
285endif()
286
287set(LLVM_ABI_BREAKING_CHECKS "WITH_ASSERTS" CACHE STRING
288  "Enable abi-breaking checks.  Can be WITH_ASSERTS, FORCE_ON or FORCE_OFF.")
289
290option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN
291       "Set to ON to force using an old, unsupported host toolchain." OFF)
292
293option(LLVM_USE_INTEL_JITEVENTS
294  "Use Intel JIT API to inform Intel(R) VTune(TM) Amplifier XE 2011 about JIT code"
295  OFF)
296
297if( LLVM_USE_INTEL_JITEVENTS )
298  # Verify we are on a supported platform
299  if( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" AND NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
300    message(FATAL_ERROR
301      "Intel JIT API support is available on Linux and Windows only.")
302  endif()
303endif( LLVM_USE_INTEL_JITEVENTS )
304
305option(LLVM_USE_OPROFILE
306  "Use opagent JIT interface to inform OProfile about JIT code" OFF)
307
308option(LLVM_EXTERNALIZE_DEBUGINFO
309  "Generate dSYM files and strip executables and libraries (Darwin Only)" OFF)
310
311# If enabled, verify we are on a platform that supports oprofile.
312if( LLVM_USE_OPROFILE )
313  if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
314    message(FATAL_ERROR "OProfile support is available on Linux only.")
315  endif( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
316endif( LLVM_USE_OPROFILE )
317
318set(LLVM_USE_SANITIZER "" CACHE STRING
319  "Define the sanitizer used to build binaries and tests.")
320
321option(LLVM_USE_SPLIT_DWARF
322  "Use -gsplit-dwarf when compiling llvm." OFF)
323
324option(WITH_POLLY "Build LLVM with Polly" ON)
325option(LINK_POLLY_INTO_TOOLS "Static link Polly into tools" OFF)
326
327# Define an option controlling whether we should build for 32-bit on 64-bit
328# platforms, where supported.
329if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32 )
330  # TODO: support other platforms and toolchains.
331  option(LLVM_BUILD_32_BITS "Build 32 bits executables and libraries." OFF)
332endif()
333
334# Define the default arguments to use with 'lit', and an option for the user to
335# override.
336set(LIT_ARGS_DEFAULT "-sv")
337if (MSVC_IDE OR XCODE)
338  set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
339endif()
340set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
341
342# On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
343if( WIN32 AND NOT CYGWIN )
344  set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
345endif()
346
347# Define options to control the inclusion and default build behavior for
348# components which may not strictly be necessary (tools, examples, and tests).
349#
350# This is primarily to support building smaller or faster project files.
351option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON)
352option(LLVM_BUILD_TOOLS
353  "Build the LLVM tools. If OFF, just generate build targets." ON)
354
355option(LLVM_INCLUDE_UTILS "Generate build targets for the LLVM utils." ON)
356
357option(LLVM_BUILD_RUNTIME
358  "Build the LLVM runtime libraries." ON)
359option(LLVM_BUILD_EXAMPLES
360  "Build the LLVM example programs. If OFF, just generate build targets." OFF)
361option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON)
362
363option(LLVM_BUILD_TESTS
364  "Build LLVM unit tests. If OFF, just generate build targets." OFF)
365option(LLVM_INCLUDE_TESTS "Generate build targets for the LLVM unit tests." ON)
366option(LLVM_INCLUDE_GO_TESTS "Include the Go bindings tests in test build targets." ON)
367
368option (LLVM_BUILD_DOCS "Build the llvm documentation." OFF)
369option (LLVM_INCLUDE_DOCS "Generate build targets for llvm documentation." ON)
370option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm API documentation." OFF)
371option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF)
372
373option (LLVM_BUILD_EXTERNAL_COMPILER_RT
374  "Build compiler-rt as an external project." OFF)
375
376# You can configure which libraries from LLVM you want to include in the
377# shared library by setting LLVM_DYLIB_COMPONENTS to a semi-colon delimited
378# list of LLVM components. All component names handled by llvm-config are valid.
379if(NOT DEFINED LLVM_DYLIB_COMPONENTS)
380  set(LLVM_DYLIB_COMPONENTS "all" CACHE STRING
381    "Semicolon-separated list of components to include in libLLVM, or \"all\".")
382endif()
383option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF)
384option(LLVM_BUILD_LLVM_C_DYLIB "Build libllvm-c re-export library (Darwin Only)" OFF)
385set(LLVM_BUILD_LLVM_DYLIB_default OFF)
386if(LLVM_LINK_LLVM_DYLIB OR LLVM_BUILD_LLVM_C_DYLIB)
387  set(LLVM_BUILD_LLVM_DYLIB_default ON)
388endif()
389option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_BUILD_LLVM_DYLIB_default})
390set(LLVM_DISABLE_LLVM_DYLIB_ATEXIT_DEFAULT ON)
391if (LLVM_LINK_LLVM_DYLIB)
392  set(LLVM_DISABLE_LLVM_DYLIB_ATEXIT_DEFAULT OFF)
393endif()
394option(LLVM_DISABLE_LLVM_DYLIB_ATEXIT "Disable llvm-shlib's atexit destructors." ${LLVM_DISABLE_LLVM_DYLIB_ATEXIT_DEFAULT})
395if(LLVM_DISABLE_LLVM_DYLIB_ATEXIT)
396  set(DISABLE_LLVM_DYLIB_ATEXIT 1)
397endif()
398
399option(LLVM_OPTIMIZED_TABLEGEN "Force TableGen to be built with optimization" OFF)
400if(CMAKE_CROSSCOMPILING OR (LLVM_OPTIMIZED_TABLEGEN AND LLVM_ENABLE_ASSERTIONS))
401  set(LLVM_USE_HOST_TOOLS ON)
402endif()
403
404# All options referred to from HandleLLVMOptions have to be specified
405# BEFORE this include, otherwise options will not be correctly set on
406# first cmake run
407include(config-ix)
408
409# By default, we target the host, but this can be overridden at CMake
410# invocation time.
411set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_HOST_TRIPLE}" CACHE STRING
412  "Default target for which LLVM will generate code." )
413set(TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
414
415include(HandleLLVMOptions)
416
417# Verify that we can find a Python 2 interpreter.  Python 3 is unsupported.
418# FIXME: We should support systems with only Python 3, but that requires work
419# on LLDB.
420set(Python_ADDITIONAL_VERSIONS 2.7)
421include(FindPythonInterp)
422if( NOT PYTHONINTERP_FOUND )
423  message(FATAL_ERROR
424"Unable to find Python interpreter, required for builds and testing.
425
426Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
427endif()
428
429if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 )
430  message(FATAL_ERROR "Python 2.7 or newer is required")
431endif()
432
433######
434# LLVMBuild Integration
435#
436# We use llvm-build to generate all the data required by the CMake based
437# build system in one swoop:
438#
439#  - We generate a file (a CMake fragment) in the object root which contains
440#    all the definitions that are required by CMake.
441#
442#  - We generate the library table used by llvm-config.
443#
444#  - We generate the dependencies for the CMake fragment, so that we will
445#    automatically reconfigure outselves.
446
447set(LLVMBUILDTOOL "${LLVM_MAIN_SRC_DIR}/utils/llvm-build/llvm-build")
448set(LLVMCONFIGLIBRARYDEPENDENCIESINC
449  "${LLVM_BINARY_DIR}/tools/llvm-config/LibraryDependencies.inc")
450set(LLVMBUILDCMAKEFRAG
451  "${LLVM_BINARY_DIR}/LLVMBuild.cmake")
452
453# Create the list of optional components that are enabled
454if (LLVM_USE_INTEL_JITEVENTS)
455  set(LLVMOPTIONALCOMPONENTS IntelJITEvents)
456endif (LLVM_USE_INTEL_JITEVENTS)
457if (LLVM_USE_OPROFILE)
458  set(LLVMOPTIONALCOMPONENTS ${LLVMOPTIONALCOMPONENTS} OProfileJIT)
459endif (LLVM_USE_OPROFILE)
460
461message(STATUS "Constructing LLVMBuild project information")
462execute_process(
463  COMMAND ${PYTHON_EXECUTABLE} ${LLVMBUILDTOOL}
464            --native-target "${LLVM_NATIVE_ARCH}"
465            --enable-targets "${LLVM_TARGETS_TO_BUILD}"
466            --enable-optional-components "${LLVMOPTIONALCOMPONENTS}"
467            --write-library-table ${LLVMCONFIGLIBRARYDEPENDENCIESINC}
468            --write-cmake-fragment ${LLVMBUILDCMAKEFRAG}
469            OUTPUT_VARIABLE LLVMBUILDOUTPUT
470            ERROR_VARIABLE LLVMBUILDERRORS
471            OUTPUT_STRIP_TRAILING_WHITESPACE
472            ERROR_STRIP_TRAILING_WHITESPACE
473  RESULT_VARIABLE LLVMBUILDRESULT)
474
475# On Win32, CMake doesn't properly handle piping the default output/error
476# streams into the GUI console. So, we explicitly catch and report them.
477if( NOT "${LLVMBUILDOUTPUT}" STREQUAL "")
478  message(STATUS "llvm-build output: ${LLVMBUILDOUTPUT}")
479endif()
480if( NOT "${LLVMBUILDRESULT}" STREQUAL "0" )
481  message(FATAL_ERROR
482    "Unexpected failure executing llvm-build: ${LLVMBUILDERRORS}")
483endif()
484
485# Include the generated CMake fragment. This will define properties from the
486# LLVMBuild files in a format which is easy to consume from CMake, and will add
487# the dependencies so that CMake will reconfigure properly when the LLVMBuild
488# files change.
489include(${LLVMBUILDCMAKEFRAG})
490
491######
492
493# Configure all of the various header file fragments LLVM uses which depend on
494# configuration variables.
495set(LLVM_ENUM_TARGETS "")
496set(LLVM_ENUM_ASM_PRINTERS "")
497set(LLVM_ENUM_ASM_PARSERS "")
498set(LLVM_ENUM_DISASSEMBLERS "")
499foreach(t ${LLVM_TARGETS_TO_BUILD})
500  set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
501
502  list(FIND LLVM_ALL_TARGETS ${t} idx)
503  list(FIND LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ${t} idy)
504  if( idx LESS 0 AND idy LESS 0 )
505    message(FATAL_ERROR "The target `${t}' does not exist.
506    It should be one of\n${LLVM_ALL_TARGETS}")
507  else()
508    set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${t})\n")
509  endif()
510
511  file(GLOB asmp_file "${td}/*AsmPrinter.cpp")
512  if( asmp_file )
513    set(LLVM_ENUM_ASM_PRINTERS
514      "${LLVM_ENUM_ASM_PRINTERS}LLVM_ASM_PRINTER(${t})\n")
515  endif()
516  if( EXISTS ${td}/AsmParser/CMakeLists.txt )
517    set(LLVM_ENUM_ASM_PARSERS
518      "${LLVM_ENUM_ASM_PARSERS}LLVM_ASM_PARSER(${t})\n")
519  endif()
520  if( EXISTS ${td}/Disassembler/CMakeLists.txt )
521    set(LLVM_ENUM_DISASSEMBLERS
522      "${LLVM_ENUM_DISASSEMBLERS}LLVM_DISASSEMBLER(${t})\n")
523  endif()
524endforeach(t)
525
526# Produce the target definition files, which provide a way for clients to easily
527# include various classes of targets.
528configure_file(
529  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmPrinters.def.in
530  ${LLVM_INCLUDE_DIR}/llvm/Config/AsmPrinters.def
531  )
532configure_file(
533  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/AsmParsers.def.in
534  ${LLVM_INCLUDE_DIR}/llvm/Config/AsmParsers.def
535  )
536configure_file(
537  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Disassemblers.def.in
538  ${LLVM_INCLUDE_DIR}/llvm/Config/Disassemblers.def
539  )
540configure_file(
541  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/Targets.def.in
542  ${LLVM_INCLUDE_DIR}/llvm/Config/Targets.def
543  )
544
545# Configure the three LLVM configuration header files.
546configure_file(
547  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/config.h.cmake
548  ${LLVM_INCLUDE_DIR}/llvm/Config/config.h)
549configure_file(
550  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Config/llvm-config.h.cmake
551  ${LLVM_INCLUDE_DIR}/llvm/Config/llvm-config.h)
552configure_file(
553  ${LLVM_MAIN_INCLUDE_DIR}/llvm/Support/DataTypes.h.cmake
554  ${LLVM_INCLUDE_DIR}/llvm/Support/DataTypes.h)
555
556# They are not referenced. See set_output_directory().
557set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/bin )
558set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
559set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
560
561set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
562if (APPLE)
563  set(CMAKE_INSTALL_NAME_DIR "@rpath")
564  set(CMAKE_INSTALL_RPATH "@executable_path/../lib")
565else(UNIX)
566  if(NOT DEFINED CMAKE_INSTALL_RPATH)
567    set(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}")
568    if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
569      set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,origin")
570      set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,origin")
571    endif()
572  endif(NOT DEFINED CMAKE_INSTALL_RPATH)
573endif()
574
575if(APPLE AND DARWIN_LTO_LIBRARY)
576  set(CMAKE_EXE_LINKER_FLAGS
577    "${CMAKE_EXE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
578  set(CMAKE_SHARED_LINKER_FLAGS
579    "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
580  set(CMAKE_MODULE_LINKER_FLAGS
581    "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-lto_library -Wl,${DARWIN_LTO_LIBRARY}")
582endif()
583
584# Work around a broken bfd ld behavior. When linking a binary with a
585# foo.so library, it will try to find any library that foo.so uses and
586# check its symbols. This is wasteful (the check was done when foo.so
587# was created) and can fail since it is not the dynamic linker and
588# doesn't know how to handle search paths correctly.
589if (UNIX AND NOT APPLE AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
590  set(CMAKE_EXE_LINKER_FLAGS
591      "${CMAKE_EXE_LINKER_FLAGS} -Wl,-allow-shlib-undefined")
592endif()
593
594set(CMAKE_INCLUDE_CURRENT_DIR ON)
595
596include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})
597
598# when crosscompiling import the executable targets from a file
599if(LLVM_USE_HOST_TOOLS)
600  include(CrossCompile)
601endif(LLVM_USE_HOST_TOOLS)
602if(LLVM_TARGET_IS_CROSSCOMPILE_HOST)
603# Dummy use to avoid CMake Wraning: Manually-specified variables were not used
604# (this is a variable that CrossCompile sets on recursive invocations)
605endif()
606
607if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
608  # On FreeBSD, /usr/local/* is not used by default. In order to build LLVM
609  # with libxml2, iconv.h, etc., we must add /usr/local paths.
610  include_directories("/usr/local/include")
611  link_directories("/usr/local/lib")
612endif(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
613
614if( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
615   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include llvm/Support/Solaris.h")
616endif( ${CMAKE_SYSTEM_NAME} MATCHES SunOS )
617
618# Make sure we don't get -rdynamic in every binary. For those that need it,
619# use export_executable_symbols(target).
620set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
621
622set(LLVM_PROFDATA_FILE "" CACHE FILEPATH
623  "Profiling data file to use when compiling in order to improve runtime performance.")
624
625if(LLVM_PROFDATA_FILE AND EXISTS ${LLVM_PROFDATA_FILE})
626  if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
627    add_definitions("-fprofile-instr-use=${LLVM_PROFDATA_FILE}")
628  else()
629    message(FATAL_ERROR "LLVM_PROFDATA_FILE can only be specified when compiling with clang")
630  endif()
631endif()
632
633include(AddLLVM)
634include(TableGen)
635
636if( MINGW )
637  # People report that -O3 is unreliable on MinGW. The traditional
638  # build also uses -O2 for that reason:
639  llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2")
640endif()
641
642# Put this before tblgen. Else we have a circular dependence.
643add_subdirectory(lib/Support)
644add_subdirectory(lib/TableGen)
645
646add_subdirectory(utils/TableGen)
647
648add_subdirectory(include/llvm)
649
650add_subdirectory(lib)
651
652if( LLVM_INCLUDE_UTILS )
653  add_subdirectory(utils/FileCheck)
654  add_subdirectory(utils/PerfectShuffle)
655  add_subdirectory(utils/count)
656  add_subdirectory(utils/not)
657  add_subdirectory(utils/llvm-lit)
658  add_subdirectory(utils/yaml-bench)
659else()
660  if ( LLVM_INCLUDE_TESTS )
661    message(FATAL_ERROR "Including tests when not building utils will not work.
662    Either set LLVM_INCLUDE_UTILS to On, or set LLVM_INCLDE_TESTS to Off.")
663  endif()
664endif()
665
666if(LLVM_INCLUDE_TESTS)
667  add_subdirectory(utils/unittest)
668endif()
669
670foreach( binding ${LLVM_BINDINGS_LIST} )
671  if( EXISTS "${LLVM_MAIN_SRC_DIR}/bindings/${binding}/CMakeLists.txt" )
672    add_subdirectory(bindings/${binding})
673  endif()
674endforeach()
675
676add_subdirectory(projects)
677
678if(WITH_POLLY)
679  if(NOT EXISTS ${LLVM_MAIN_SRC_DIR}/tools/polly/CMakeLists.txt)
680    set(WITH_POLLY OFF)
681  endif()
682endif(WITH_POLLY)
683
684if( LLVM_INCLUDE_TOOLS )
685  add_subdirectory(tools)
686endif()
687
688if( LLVM_INCLUDE_EXAMPLES )
689  add_subdirectory(examples)
690endif()
691
692if( LLVM_INCLUDE_TESTS )
693  if(EXISTS ${LLVM_MAIN_SRC_DIR}/projects/test-suite AND TARGET clang)
694    include(LLVMExternalProjectUtils)
695    llvm_ExternalProject_Add(test-suite ${LLVM_MAIN_SRC_DIR}/projects/test-suite
696      USE_TOOLCHAIN
697      EXCLUDE_FROM_ALL
698      NO_INSTALL)
699  endif()
700  add_subdirectory(test)
701  add_subdirectory(unittests)
702  if (MSVC)
703    # This utility is used to prevent crashing tests from calling Dr. Watson on
704    # Windows.
705    add_subdirectory(utils/KillTheDoctor)
706  endif()
707
708  # Add a global check rule now that all subdirectories have been traversed
709  # and we know the total set of lit testsuites.
710  get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
711  get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
712  get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
713  get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
714  add_lit_target(check-all
715    "Running all regression tests"
716    ${LLVM_LIT_TESTSUITES}
717    PARAMS ${LLVM_LIT_PARAMS}
718    DEPENDS ${LLVM_LIT_DEPENDS}
719    ARGS ${LLVM_LIT_EXTRA_ARGS}
720    )
721endif()
722
723if (LLVM_INCLUDE_DOCS)
724  add_subdirectory(docs)
725endif()
726
727add_subdirectory(cmake/modules)
728
729if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
730  install(DIRECTORY include/llvm include/llvm-c
731    DESTINATION include
732    COMPONENT llvm-headers
733    FILES_MATCHING
734    PATTERN "*.def"
735    PATTERN "*.h"
736    PATTERN "*.td"
737    PATTERN "*.inc"
738    PATTERN "LICENSE.TXT"
739    PATTERN ".svn" EXCLUDE
740    )
741
742  install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm
743    DESTINATION include
744    COMPONENT llvm-headers
745    FILES_MATCHING
746    PATTERN "*.def"
747    PATTERN "*.h"
748    PATTERN "*.gen"
749    PATTERN "*.inc"
750    # Exclude include/llvm/CMakeFiles/intrinsics_gen.dir, matched by "*.def"
751    PATTERN "CMakeFiles" EXCLUDE
752    PATTERN "config.h" EXCLUDE
753    PATTERN ".svn" EXCLUDE
754    )
755
756  if (NOT CMAKE_CONFIGURATION_TYPES)
757    add_custom_target(installhdrs
758                      DEPENDS ${name}
759                      COMMAND "${CMAKE_COMMAND}"
760                              -DCMAKE_INSTALL_COMPONENT=llvm-headers
761                              -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
762  endif()
763endif()
Note: See TracBrowser for help on using the repository browser.