2014-02-03 00:59:36 +08:00
|
|
|
cmake_minimum_required(VERSION 2.8.8)
|
|
|
|
|
2014-02-26 14:45:11 +08:00
|
|
|
# FIXME: It may be removed when we use 2.8.12.
|
|
|
|
if(CMAKE_VERSION VERSION_LESS 2.8.12)
|
|
|
|
# Invalidate a couple of keywords.
|
|
|
|
set(cmake_2_8_12_INTERFACE)
|
|
|
|
set(cmake_2_8_12_PRIVATE)
|
|
|
|
else()
|
|
|
|
# Use ${cmake_2_8_12_KEYWORD} intead of KEYWORD in target_link_libraries().
|
|
|
|
set(cmake_2_8_12_INTERFACE INTERFACE)
|
|
|
|
set(cmake_2_8_12_PRIVATE PRIVATE)
|
|
|
|
if(POLICY CMP0022)
|
|
|
|
cmake_policy(SET CMP0022 NEW) # automatic when 2.8.12 is required
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2011-02-04 04:57:53 +08:00
|
|
|
# If we are not building as a part of LLVM, build Clang as an
|
|
|
|
# standalone project, using LLVM as an external library:
|
|
|
|
if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
|
|
|
|
project(Clang)
|
|
|
|
|
2013-12-20 00:44:32 +08:00
|
|
|
# Rely on llvm-config.
|
|
|
|
set(CONFIG_OUTPUT)
|
|
|
|
find_program(LLVM_CONFIG "llvm-config")
|
|
|
|
if(LLVM_CONFIG)
|
|
|
|
message(STATUS "Found LLVM_CONFIG as ${LLVM_CONFIG}")
|
2013-12-20 02:39:05 +08:00
|
|
|
set(CONFIG_COMMAND ${LLVM_CONFIG}
|
2013-12-20 00:44:32 +08:00
|
|
|
"--assertion-mode"
|
|
|
|
"--bindir"
|
|
|
|
"--libdir"
|
|
|
|
"--includedir"
|
|
|
|
"--prefix"
|
2013-12-20 02:39:05 +08:00
|
|
|
"--src-root")
|
|
|
|
execute_process(
|
|
|
|
COMMAND ${CONFIG_COMMAND}
|
|
|
|
RESULT_VARIABLE HAD_ERROR
|
2013-12-20 00:44:32 +08:00
|
|
|
OUTPUT_VARIABLE CONFIG_OUTPUT
|
2013-12-20 02:39:05 +08:00
|
|
|
)
|
|
|
|
if(NOT HAD_ERROR)
|
|
|
|
string(REGEX REPLACE
|
|
|
|
"[ \t]*[\r\n]+[ \t]*" ";"
|
|
|
|
CONFIG_OUTPUT ${CONFIG_OUTPUT})
|
|
|
|
else()
|
|
|
|
string(REPLACE ";" " " CONFIG_COMMAND_STR "${CONFIG_COMMAND}")
|
|
|
|
message(STATUS "${CONFIG_COMMAND_STR}")
|
|
|
|
message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}")
|
|
|
|
endif()
|
2013-12-20 00:44:32 +08:00
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "llvm-config not found -- ${LLVM_CONFIG}")
|
2011-02-04 04:57:53 +08:00
|
|
|
endif()
|
|
|
|
|
2013-12-20 00:44:32 +08:00
|
|
|
list(GET CONFIG_OUTPUT 0 ENABLE_ASSERTIONS)
|
|
|
|
list(GET CONFIG_OUTPUT 1 TOOLS_BINARY_DIR)
|
|
|
|
list(GET CONFIG_OUTPUT 2 LIBRARY_DIR)
|
|
|
|
list(GET CONFIG_OUTPUT 3 INCLUDE_DIR)
|
|
|
|
list(GET CONFIG_OUTPUT 4 LLVM_OBJ_ROOT)
|
|
|
|
list(GET CONFIG_OUTPUT 5 MAIN_SRC_DIR)
|
|
|
|
|
|
|
|
if(NOT MSVC_IDE)
|
|
|
|
set(LLVM_ENABLE_ASSERTIONS ${ENABLE_ASSERTIONS}
|
|
|
|
CACHE BOOL "Enable assertions")
|
|
|
|
# Assertions should follow llvm-config's.
|
|
|
|
mark_as_advanced(LLVM_ENABLE_ASSERTIONS)
|
2011-02-04 04:57:53 +08:00
|
|
|
endif()
|
|
|
|
|
2013-12-20 00:44:32 +08:00
|
|
|
set(LLVM_TOOLS_BINARY_DIR ${TOOLS_BINARY_DIR} CACHE PATH "Path to llvm/bin")
|
|
|
|
set(LLVM_LIBRARY_DIR ${LIBRARY_DIR} CACHE PATH "Path to llvm/lib")
|
|
|
|
set(LLVM_MAIN_INCLUDE_DIR ${INCLUDE_DIR} CACHE PATH "Path to llvm/include")
|
|
|
|
set(LLVM_BINARY_DIR ${LLVM_OBJ_ROOT} CACHE PATH "Path to LLVM build tree")
|
|
|
|
set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree")
|
2011-02-04 04:57:53 +08:00
|
|
|
|
2013-12-20 02:39:05 +08:00
|
|
|
find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR}
|
|
|
|
NO_DEFAULT_PATH)
|
2011-02-04 04:57:53 +08:00
|
|
|
|
2013-12-20 00:44:32 +08:00
|
|
|
set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR}/share/llvm/cmake")
|
|
|
|
set(LLVMCONFIG_FILE "${LLVM_CMAKE_PATH}/LLVMConfig.cmake")
|
|
|
|
if(EXISTS ${LLVMCONFIG_FILE})
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}")
|
|
|
|
include(${LLVMCONFIG_FILE})
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Not found: ${LLVMCONFIG_FILE}")
|
|
|
|
endif()
|
|
|
|
|
2014-01-19 20:55:14 +08:00
|
|
|
# They are used as destination of target generators.
|
|
|
|
set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
|
2014-12-29 20:09:03 +08:00
|
|
|
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
|
2015-01-05 22:06:14 +08:00
|
|
|
if(WIN32 OR CYGWIN)
|
|
|
|
# DLL platform -- put DLLs into bin.
|
|
|
|
set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
|
|
|
|
else()
|
|
|
|
set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
|
|
|
|
endif()
|
2013-12-17 12:14:17 +08:00
|
|
|
|
2014-01-26 14:18:06 +08:00
|
|
|
option(LLVM_INSTALL_TOOLCHAIN_ONLY
|
|
|
|
"Only include toolchain files in the 'install' target." OFF)
|
2013-08-24 08:22:23 +08:00
|
|
|
|
2014-01-14 06:22:24 +08:00
|
|
|
option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN
|
2014-01-26 14:18:06 +08:00
|
|
|
"Set to ON to force using an old, unsupported host toolchain." OFF)
|
2015-08-06 01:38:12 +08:00
|
|
|
option(CLANG_ENABLE_BOOTSTRAP "Generate the clang bootstrap target" OFF)
|
2014-01-14 06:22:24 +08:00
|
|
|
|
2011-02-04 04:57:53 +08:00
|
|
|
include(AddLLVM)
|
|
|
|
include(TableGen)
|
|
|
|
include(HandleLLVMOptions)
|
|
|
|
|
|
|
|
set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
|
|
|
|
|
2013-12-17 04:54:13 +08:00
|
|
|
if (NOT DEFINED LLVM_INCLUDE_TESTS)
|
|
|
|
set(LLVM_INCLUDE_TESTS ON)
|
|
|
|
endif()
|
|
|
|
|
2013-12-20 00:44:32 +08:00
|
|
|
include_directories("${LLVM_BINARY_DIR}/include" "${LLVM_MAIN_INCLUDE_DIR}")
|
|
|
|
link_directories("${LLVM_LIBRARY_DIR}")
|
2013-12-17 12:14:26 +08:00
|
|
|
|
2011-02-04 04:57:53 +08:00
|
|
|
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
|
2014-12-29 20:09:03 +08:00
|
|
|
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
|
|
|
|
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
|
2011-02-04 04:57:53 +08:00
|
|
|
|
2013-12-20 00:44:32 +08:00
|
|
|
if(LLVM_INCLUDE_TESTS)
|
2015-08-21 17:38:46 +08:00
|
|
|
set(Python_ADDITIONAL_VERSIONS 2.7)
|
|
|
|
include(FindPythonInterp)
|
|
|
|
if(NOT PYTHONINTERP_FOUND)
|
|
|
|
message(FATAL_ERROR
|
|
|
|
"Unable to find Python interpreter, required for builds and testing.
|
|
|
|
|
|
|
|
Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if( ${PYTHON_VERSION_STRING} VERSION_LESS 2.7 )
|
|
|
|
message(FATAL_ERROR "Python 2.7 or newer is required")
|
|
|
|
endif()
|
|
|
|
|
2013-12-20 00:44:32 +08:00
|
|
|
# Check prebuilt llvm/utils.
|
|
|
|
if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX}
|
2014-02-03 00:46:07 +08:00
|
|
|
AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/count${CMAKE_EXECUTABLE_SUFFIX}
|
|
|
|
AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/not${CMAKE_EXECUTABLE_SUFFIX})
|
2013-12-20 00:44:32 +08:00
|
|
|
set(LLVM_UTILS_PROVIDED ON)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
|
|
|
|
set(LLVM_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
|
|
|
|
if(NOT LLVM_UTILS_PROVIDED)
|
2014-02-03 00:46:07 +08:00
|
|
|
add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck)
|
|
|
|
add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/count utils/count)
|
|
|
|
add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/not utils/not)
|
|
|
|
set(LLVM_UTILS_PROVIDED ON)
|
|
|
|
set(CLANG_TEST_DEPS FileCheck count not)
|
2013-12-20 00:44:32 +08:00
|
|
|
endif()
|
|
|
|
set(UNITTEST_DIR ${LLVM_MAIN_SRC_DIR}/utils/unittest)
|
|
|
|
if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h
|
|
|
|
AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
|
2014-02-03 00:46:07 +08:00
|
|
|
AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt)
|
|
|
|
add_subdirectory(${UNITTEST_DIR} utils/unittest)
|
2013-12-20 00:44:32 +08:00
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
# Seek installed Lit.
|
|
|
|
find_program(LLVM_LIT "lit.py" ${LLVM_MAIN_SRC_DIR}/utils/lit
|
2014-02-03 00:46:07 +08:00
|
|
|
DOC "Path to lit.py")
|
2013-12-20 00:44:32 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(LLVM_LIT)
|
|
|
|
# Define the default arguments to use with 'lit', and an option for the user
|
|
|
|
# to override.
|
|
|
|
set(LIT_ARGS_DEFAULT "-sv")
|
|
|
|
if (MSVC OR XCODE)
|
2014-02-03 00:46:07 +08:00
|
|
|
set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
|
2013-12-20 00:44:32 +08:00
|
|
|
endif()
|
|
|
|
set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
|
|
|
|
|
|
|
|
# On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
|
|
|
|
if( WIN32 AND NOT CYGWIN )
|
2014-02-03 00:46:07 +08:00
|
|
|
set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
|
2013-12-20 00:44:32 +08:00
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
set(LLVM_INCLUDE_TESTS OFF)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2011-02-15 15:54:28 +08:00
|
|
|
set( CLANG_BUILT_STANDALONE 1 )
|
2014-06-06 18:36:22 +08:00
|
|
|
set(BACKEND_PACKAGE_STRING "LLVM ${LLVM_PACKAGE_VERSION}")
|
|
|
|
else()
|
|
|
|
set(BACKEND_PACKAGE_STRING "${PACKAGE_STRING}")
|
2014-06-06 13:01:47 +08:00
|
|
|
endif()
|
2012-12-19 03:39:40 +08:00
|
|
|
|
2015-08-12 23:01:15 +08:00
|
|
|
find_package(LibXml2 2.5.3 QUIET)
|
2014-06-06 13:01:47 +08:00
|
|
|
if (LIBXML2_FOUND)
|
|
|
|
set(CLANG_HAVE_LIBXML 1)
|
2011-02-04 04:57:53 +08:00
|
|
|
endif()
|
2009-09-17 05:59:05 +08:00
|
|
|
|
2011-02-04 06:48:20 +08:00
|
|
|
set(CLANG_RESOURCE_DIR "" CACHE STRING
|
|
|
|
"Relative directory from the Clang binary to its resource files.")
|
|
|
|
|
|
|
|
set(C_INCLUDE_DIRS "" CACHE STRING
|
|
|
|
"Colon separated list of directories clang will search for headers.")
|
|
|
|
|
2012-04-16 12:16:43 +08:00
|
|
|
set(GCC_INSTALL_PREFIX "" CACHE PATH "Directory where gcc is installed." )
|
|
|
|
set(DEFAULT_SYSROOT "" CACHE PATH
|
|
|
|
"Default <path> to all compiler invocations for --sysroot=<path>." )
|
|
|
|
|
2015-12-10 13:47:10 +08:00
|
|
|
set(CLANG_DEFAULT_OPENMP_RUNTIME "libomp" CACHE STRING
|
[omp] Re-work Clang's handling of -fopenmp and undo r237769.
This isn't an actual revert of r237769, it just restores the behavior of
the Clang driver prior to it while completely re-implementing how that
behavior works.
This also re-does the work of making the default OpenMP runtime
selectable at CMake (or configure) time to work in the way all of our
other such hooks do (config.h, configure and cmake hooks, etc.).
I've re-implemented how we manage the '-fopenmp' flagset in an important
way. Now, the "default" hook just makes '-fopenmp' equivalent to
'-fopenmp=<default>' rather than a separate special beast. Also, there
is an '-fno-openmp' flag which does the obvious thing. Also, the code is
shared between all the places to select a known OpenMP runtime and act
on it.
Finally, and most significantly, I've taught the driver to inspect the
selected runtime when choosing whether to propagate the '-fopenmp' flag
to the frontend in the CC1 commandline. Without this, it isn't possible
to use Clang with libgomp, even if you were happy with the serial,
boring way in which it worked previously (ignoring all #pragmas but
linking in the library to satisfy direct calls into the runtime).
While I'm here, I've gone ahead and sketched out a path for the future
name of LLVM's OpenMP runtime (libomp) and the legacy support for its
current name (libiomp5) in what seems a more reasonable way.
To re-enable LLVM's OpenMP runtime (which I think should wait until the
normal getting started instructions are a reasonable way for falks to
check out, build, and install Clang with the runtime) all that needs to
change is the default string in the CMakeLists.txt and configure.ac
file. No code changes necessary.
I also added a test for the driver's behavior around OpenMP since it was
*completely missing* previously. Makes it unsurprising that we got it
wrong.
llvm-svn: 238389
2015-05-28 09:52:38 +08:00
|
|
|
"Default OpenMP runtime used by -fopenmp.")
|
|
|
|
|
2011-05-20 23:57:59 +08:00
|
|
|
set(CLANG_VENDOR "" CACHE STRING
|
|
|
|
"Vendor-specific text for showing with version information.")
|
|
|
|
|
|
|
|
if( CLANG_VENDOR )
|
|
|
|
add_definitions( -DCLANG_VENDOR="${CLANG_VENDOR} " )
|
|
|
|
endif()
|
|
|
|
|
2013-08-16 03:22:33 +08:00
|
|
|
set(CLANG_REPOSITORY_STRING "" CACHE STRING
|
|
|
|
"Vendor-specific text for showing the repository the source is taken from.")
|
|
|
|
|
|
|
|
if(CLANG_REPOSITORY_STRING)
|
|
|
|
add_definitions(-DCLANG_REPOSITORY_STRING="${CLANG_REPOSITORY_STRING}")
|
|
|
|
endif()
|
|
|
|
|
2013-08-16 03:22:36 +08:00
|
|
|
set(CLANG_VENDOR_UTI "org.llvm.clang" CACHE STRING
|
|
|
|
"Vendor-specific uti.")
|
|
|
|
|
2014-12-29 20:09:08 +08:00
|
|
|
# The libdir suffix must exactly match whatever LLVM's configuration used.
|
|
|
|
set(CLANG_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}")
|
|
|
|
|
2009-09-17 08:07:10 +08:00
|
|
|
set(CLANG_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
set(CLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
|
2010-04-18 04:12:02 +08:00
|
|
|
if( CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE )
|
|
|
|
message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite "
|
|
|
|
"the makefiles distributed with LLVM. Please create a directory and run cmake "
|
|
|
|
"from there, passing the path to this source directory as the last argument. "
|
|
|
|
"This process created the file `CMakeCache.txt' and the directory "
|
|
|
|
"`CMakeFiles'. Please delete them.")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR )
|
|
|
|
file(GLOB_RECURSE
|
|
|
|
tablegenned_files_on_include_dir
|
|
|
|
"${CLANG_SOURCE_DIR}/include/clang/*.inc")
|
|
|
|
if( tablegenned_files_on_include_dir )
|
|
|
|
message(FATAL_ERROR "Apparently there is a previous in-source build, "
|
|
|
|
"probably as the result of running `configure' and `make' on "
|
|
|
|
"${CLANG_SOURCE_DIR}. This may cause problems. The suspicious files are:\n"
|
|
|
|
"${tablegenned_files_on_include_dir}\nPlease clean the source directory.")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2010-06-26 07:34:47 +08:00
|
|
|
# Compute the Clang version from the LLVM version.
|
2010-09-11 05:13:16 +08:00
|
|
|
string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION
|
2010-06-26 07:34:47 +08:00
|
|
|
${PACKAGE_VERSION})
|
2009-09-17 05:59:05 +08:00
|
|
|
message(STATUS "Clang version: ${CLANG_VERSION}")
|
2009-08-23 13:28:29 +08:00
|
|
|
|
2010-06-26 01:33:46 +08:00
|
|
|
string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" CLANG_VERSION_MAJOR
|
|
|
|
${CLANG_VERSION})
|
|
|
|
string(REGEX REPLACE "[0-9]+\\.([0-9]+)(\\.[0-9]+)?" "\\1" CLANG_VERSION_MINOR
|
|
|
|
${CLANG_VERSION})
|
|
|
|
if (${CLANG_VERSION} MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+")
|
|
|
|
set(CLANG_HAS_VERSION_PATCHLEVEL 1)
|
|
|
|
string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" CLANG_VERSION_PATCHLEVEL
|
|
|
|
${CLANG_VERSION})
|
|
|
|
else()
|
|
|
|
set(CLANG_HAS_VERSION_PATCHLEVEL 0)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Configure the Version.inc file.
|
|
|
|
configure_file(
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include/clang/Basic/Version.inc.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/include/clang/Basic/Version.inc)
|
|
|
|
|
2009-09-18 22:47:57 +08:00
|
|
|
# Add appropriate flags for GCC
|
2011-05-11 21:53:30 +08:00
|
|
|
if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
|
2015-08-19 00:15:44 +08:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual")
|
|
|
|
if (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")
|
|
|
|
endif ()
|
2013-04-22 22:51:21 +08:00
|
|
|
|
|
|
|
# Enable -pedantic for Clang even if it's not enabled for LLVM.
|
|
|
|
if (NOT LLVM_ENABLE_PEDANTIC)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wno-long-long")
|
|
|
|
endif ()
|
2013-03-02 08:49:47 +08:00
|
|
|
|
|
|
|
check_cxx_compiler_flag("-Werror -Wnested-anon-types" CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG)
|
|
|
|
if( CXX_SUPPORTS_NO_NESTED_ANON_TYPES_FLAG )
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-nested-anon-types" )
|
|
|
|
endif()
|
2009-09-18 22:47:57 +08:00
|
|
|
endif ()
|
|
|
|
|
2014-11-13 08:35:23 +08:00
|
|
|
# Determine HOST_LINK_VERSION on Darwin.
|
|
|
|
set(HOST_LINK_VERSION)
|
|
|
|
if (APPLE)
|
|
|
|
set(LD_V_OUTPUT)
|
|
|
|
execute_process(
|
|
|
|
COMMAND sh -c "${CMAKE_LINKER} -v 2>&1 | head -1"
|
|
|
|
RESULT_VARIABLE HAD_ERROR
|
|
|
|
OUTPUT_VARIABLE LD_V_OUTPUT
|
|
|
|
)
|
|
|
|
if (NOT HAD_ERROR)
|
2014-12-04 09:59:58 +08:00
|
|
|
if ("${LD_V_OUTPUT}" MATCHES ".*ld64-([0-9.]+).*")
|
|
|
|
string(REGEX REPLACE ".*ld64-([0-9.]+).*" "\\1" HOST_LINK_VERSION ${LD_V_OUTPUT})
|
|
|
|
elseif ("${LD_V_OUTPUT}" MATCHES "[^0-9]*([0-9.]+).*")
|
|
|
|
string(REGEX REPLACE "[^0-9]*([0-9.]+).*" "\\1" HOST_LINK_VERSION ${LD_V_OUTPUT})
|
2014-11-13 08:35:23 +08:00
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "${CMAKE_LINKER} failed with status ${HAD_ERROR}")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2011-02-04 06:48:20 +08:00
|
|
|
configure_file(
|
|
|
|
${CLANG_SOURCE_DIR}/include/clang/Config/config.h.cmake
|
|
|
|
${CLANG_BINARY_DIR}/include/clang/Config/config.h)
|
|
|
|
|
2014-01-23 23:33:35 +08:00
|
|
|
include(CMakeParseArguments)
|
2011-02-21 06:06:32 +08:00
|
|
|
|
|
|
|
function(clang_tablegen)
|
|
|
|
# Syntax:
|
|
|
|
# clang_tablegen output-file [tablegen-arg ...] SOURCE source-file
|
|
|
|
# [[TARGET cmake-target-name] [DEPENDS extra-dependency ...]]
|
|
|
|
#
|
|
|
|
# Generates a custom command for invoking tblgen as
|
|
|
|
#
|
|
|
|
# tblgen source-file -o=output-file tablegen-arg ...
|
|
|
|
#
|
|
|
|
# and, if cmake-target-name is provided, creates a custom target for
|
|
|
|
# executing the custom command depending on output-file. It is
|
|
|
|
# possible to list more files to depend after DEPENDS.
|
|
|
|
|
2014-02-23 20:53:45 +08:00
|
|
|
cmake_parse_arguments(CTG "" "SOURCE;TARGET" "" ${ARGN})
|
2011-02-21 06:06:32 +08:00
|
|
|
|
|
|
|
if( NOT CTG_SOURCE )
|
|
|
|
message(FATAL_ERROR "SOURCE source-file required by clang_tablegen")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set( LLVM_TARGET_DEFINITIONS ${CTG_SOURCE} )
|
2014-01-23 23:33:35 +08:00
|
|
|
tablegen(CLANG ${CTG_UNPARSED_ARGUMENTS})
|
2011-02-21 06:06:32 +08:00
|
|
|
|
2014-02-23 21:08:07 +08:00
|
|
|
if(CTG_TARGET)
|
|
|
|
add_public_tablegen_target(${CTG_TARGET})
|
2011-02-21 06:06:44 +08:00
|
|
|
set_target_properties( ${CTG_TARGET} PROPERTIES FOLDER "Clang tablegenning")
|
2014-02-21 15:59:59 +08:00
|
|
|
set_property(GLOBAL APPEND PROPERTY CLANG_TABLEGEN_TARGETS ${CTG_TARGET})
|
2011-02-21 06:06:32 +08:00
|
|
|
endif()
|
|
|
|
endfunction(clang_tablegen)
|
|
|
|
|
2015-06-13 00:33:38 +08:00
|
|
|
macro(set_clang_windows_version_resource_properties name)
|
|
|
|
if(DEFINED windows_resource_file)
|
|
|
|
set_windows_version_resource_properties(${name} ${windows_resource_file}
|
|
|
|
VERSION_MAJOR ${CLANG_VERSION_MAJOR}
|
|
|
|
VERSION_MINOR ${CLANG_VERSION_MINOR}
|
|
|
|
VERSION_PATCHLEVEL ${CLANG_VERSION_PATCHLEVEL}
|
|
|
|
VERSION_STRING "${CLANG_VERSION} (${BACKEND_PACKAGE_STRING})"
|
|
|
|
PRODUCT_NAME "clang")
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
2015-10-21 02:12:12 +08:00
|
|
|
macro(add_clang_subdirectory name)
|
|
|
|
add_llvm_subdirectory(CLANG TOOL ${name})
|
|
|
|
endmacro()
|
|
|
|
|
2008-10-26 08:56:18 +08:00
|
|
|
macro(add_clang_library name)
|
2014-02-10 17:05:28 +08:00
|
|
|
cmake_parse_arguments(ARG
|
2015-11-12 08:46:57 +08:00
|
|
|
"SHARED"
|
2014-02-10 17:05:28 +08:00
|
|
|
""
|
|
|
|
"ADDITIONAL_HEADERS"
|
|
|
|
${ARGN})
|
|
|
|
set(srcs)
|
2009-03-26 04:34:07 +08:00
|
|
|
if(MSVC_IDE OR XCODE)
|
2012-10-24 05:54:03 +08:00
|
|
|
# Add public headers
|
|
|
|
file(RELATIVE_PATH lib_path
|
|
|
|
${CLANG_SOURCE_DIR}/lib/
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}
|
|
|
|
)
|
|
|
|
if(NOT lib_path MATCHES "^[.][.]")
|
|
|
|
file( GLOB_RECURSE headers
|
|
|
|
${CLANG_SOURCE_DIR}/include/clang/${lib_path}/*.h
|
|
|
|
${CLANG_SOURCE_DIR}/include/clang/${lib_path}/*.def
|
|
|
|
)
|
|
|
|
set_source_files_properties(${headers} PROPERTIES HEADER_FILE_ONLY ON)
|
|
|
|
|
|
|
|
file( GLOB_RECURSE tds
|
|
|
|
${CLANG_SOURCE_DIR}/include/clang/${lib_path}/*.td
|
|
|
|
)
|
|
|
|
source_group("TableGen descriptions" FILES ${tds})
|
|
|
|
set_source_files_properties(${tds}} PROPERTIES HEADER_FILE_ONLY ON)
|
|
|
|
|
2014-02-10 17:05:28 +08:00
|
|
|
if(headers OR tds)
|
2015-08-21 17:37:53 +08:00
|
|
|
set(srcs ${headers} ${tds})
|
2014-02-10 17:05:28 +08:00
|
|
|
endif()
|
2012-10-24 05:54:03 +08:00
|
|
|
endif()
|
2009-03-26 04:34:07 +08:00
|
|
|
endif(MSVC_IDE OR XCODE)
|
2014-02-10 17:05:28 +08:00
|
|
|
if(srcs OR ARG_ADDITIONAL_HEADERS)
|
|
|
|
set(srcs
|
|
|
|
ADDITIONAL_HEADERS
|
|
|
|
${srcs}
|
|
|
|
${ARG_ADDITIONAL_HEADERS} # It may contain unparsed unknown args.
|
|
|
|
)
|
2013-11-06 16:37:50 +08:00
|
|
|
endif()
|
2015-11-12 08:46:57 +08:00
|
|
|
if(ARG_SHARED)
|
|
|
|
set(ARG_ENABLE_SHARED SHARED)
|
|
|
|
endif()
|
|
|
|
llvm_add_library(${name} ${ARG_ENABLE_SHARED} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
|
2011-03-30 04:51:00 +08:00
|
|
|
|
2014-02-13 19:24:45 +08:00
|
|
|
if(TARGET ${name})
|
2014-02-26 14:53:16 +08:00
|
|
|
target_link_libraries(${name} ${cmake_2_8_12_INTERFACE} ${LLVM_COMMON_LIBS})
|
2014-02-13 19:24:45 +08:00
|
|
|
|
|
|
|
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "libclang")
|
|
|
|
install(TARGETS ${name}
|
2015-11-12 08:46:57 +08:00
|
|
|
COMPONENT ${name}
|
2015-05-30 02:36:20 +08:00
|
|
|
EXPORT ClangTargets
|
2014-02-13 19:24:45 +08:00
|
|
|
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
|
|
|
|
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
|
|
|
|
RUNTIME DESTINATION bin)
|
2015-11-12 08:46:57 +08:00
|
|
|
|
|
|
|
if (${ARG_SHARED} AND NOT CMAKE_CONFIGURATION_TYPES)
|
|
|
|
add_custom_target(install-${name}
|
|
|
|
DEPENDS ${name}
|
|
|
|
COMMAND "${CMAKE_COMMAND}"
|
|
|
|
-DCMAKE_INSTALL_COMPONENT=${name}
|
|
|
|
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
|
|
|
|
endif()
|
2014-02-13 19:24:45 +08:00
|
|
|
endif()
|
2014-11-06 07:14:59 +08:00
|
|
|
set_property(GLOBAL APPEND PROPERTY CLANG_EXPORTS ${name})
|
2014-02-13 19:24:45 +08:00
|
|
|
else()
|
|
|
|
# Add empty "phony" target
|
|
|
|
add_custom_target(${name})
|
2013-08-24 08:22:23 +08:00
|
|
|
endif()
|
|
|
|
|
2011-02-21 06:06:44 +08:00
|
|
|
set_target_properties(${name} PROPERTIES FOLDER "Clang libraries")
|
2015-06-13 00:33:38 +08:00
|
|
|
set_clang_windows_version_resource_properties(${name})
|
2008-10-26 08:56:18 +08:00
|
|
|
endmacro(add_clang_library)
|
|
|
|
|
|
|
|
macro(add_clang_executable name)
|
2011-01-04 01:00:02 +08:00
|
|
|
add_llvm_executable( ${name} ${ARGN} )
|
2011-02-21 06:06:44 +08:00
|
|
|
set_target_properties(${name} PROPERTIES FOLDER "Clang executables")
|
2015-06-13 00:33:38 +08:00
|
|
|
set_clang_windows_version_resource_properties(${name})
|
2008-10-26 08:56:18 +08:00
|
|
|
endmacro(add_clang_executable)
|
|
|
|
|
2015-09-19 05:15:54 +08:00
|
|
|
macro(add_clang_symlink name dest)
|
|
|
|
add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE)
|
|
|
|
# Always generate install targets
|
|
|
|
llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE)
|
|
|
|
endmacro()
|
|
|
|
|
2014-01-26 20:34:48 +08:00
|
|
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
|
|
|
|
2011-03-18 03:03:04 +08:00
|
|
|
include_directories(BEFORE
|
2009-03-17 07:06:59 +08:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/include
|
2011-03-18 03:03:04 +08:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
2008-10-26 08:56:18 +08:00
|
|
|
)
|
|
|
|
|
2013-08-24 08:22:23 +08:00
|
|
|
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
|
2014-02-10 18:51:09 +08:00
|
|
|
install(DIRECTORY include/clang include/clang-c
|
2013-08-24 08:22:23 +08:00
|
|
|
DESTINATION include
|
|
|
|
FILES_MATCHING
|
|
|
|
PATTERN "*.def"
|
|
|
|
PATTERN "*.h"
|
|
|
|
PATTERN "config.h" EXCLUDE
|
|
|
|
PATTERN ".svn" EXCLUDE
|
|
|
|
)
|
|
|
|
|
2014-02-10 18:51:09 +08:00
|
|
|
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/clang
|
2013-08-24 08:22:23 +08:00
|
|
|
DESTINATION include
|
|
|
|
FILES_MATCHING
|
|
|
|
PATTERN "CMakeFiles" EXCLUDE
|
|
|
|
PATTERN "*.inc"
|
2015-03-24 04:43:21 +08:00
|
|
|
PATTERN "*.h"
|
2013-08-24 08:22:23 +08:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2015-11-13 09:46:18 +08:00
|
|
|
if(INTERNAL_INSTALL_PREFIX)
|
|
|
|
set(LIBCLANG_HEADERS_INSTALL_DESTINATION "${INTERNAL_INSTALL_PREFIX}/include")
|
|
|
|
else()
|
|
|
|
set(LIBCLANG_HEADERS_INSTALL_DESTINATION include)
|
|
|
|
endif()
|
|
|
|
|
2013-08-24 08:22:23 +08:00
|
|
|
install(DIRECTORY include/clang-c
|
2015-11-13 09:46:18 +08:00
|
|
|
COMPONENT libclang-headers
|
|
|
|
DESTINATION "${LIBCLANG_HEADERS_INSTALL_DESTINATION}"
|
2009-10-28 03:59:34 +08:00
|
|
|
FILES_MATCHING
|
|
|
|
PATTERN "*.h"
|
2008-11-12 02:39:10 +08:00
|
|
|
PATTERN ".svn" EXCLUDE
|
|
|
|
)
|
|
|
|
|
2015-11-13 09:46:18 +08:00
|
|
|
if (NOT CMAKE_CONFIGURATION_TYPES) # don't add this for IDE's.
|
|
|
|
add_custom_target(install-libclang-headers
|
|
|
|
DEPENDS
|
|
|
|
COMMAND "${CMAKE_COMMAND}"
|
|
|
|
-DCMAKE_INSTALL_COMPONENT=libclang-headers
|
|
|
|
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
|
|
|
|
endif()
|
|
|
|
|
2012-02-14 23:54:49 +08:00
|
|
|
add_definitions( -D_GNU_SOURCE )
|
2008-10-26 08:56:18 +08:00
|
|
|
|
2013-08-22 23:50:02 +08:00
|
|
|
option(CLANG_ENABLE_ARCMT "Build ARCMT." ON)
|
2014-07-15 07:28:38 +08:00
|
|
|
if (CLANG_ENABLE_ARCMT)
|
|
|
|
set(ENABLE_CLANG_ARCMT "1")
|
|
|
|
else()
|
|
|
|
set(ENABLE_CLANG_ARCMT "0")
|
|
|
|
endif()
|
|
|
|
|
2013-08-22 23:50:02 +08:00
|
|
|
option(CLANG_ENABLE_STATIC_ANALYZER "Build static analyzer." ON)
|
2014-07-15 07:28:38 +08:00
|
|
|
if (CLANG_ENABLE_STATIC_ANALYZER)
|
|
|
|
set(ENABLE_CLANG_STATIC_ANALYZER "1")
|
|
|
|
else()
|
|
|
|
set(ENABLE_CLANG_STATIC_ANALYZER "0")
|
|
|
|
endif()
|
2013-05-30 05:09:18 +08:00
|
|
|
|
2013-08-22 23:50:02 +08:00
|
|
|
if (NOT CLANG_ENABLE_STATIC_ANALYZER AND CLANG_ENABLE_ARCMT)
|
|
|
|
message(FATAL_ERROR "Cannot disable static analyzer while enabling ARCMT")
|
|
|
|
endif()
|
|
|
|
|
2013-05-30 05:09:18 +08:00
|
|
|
if(CLANG_ENABLE_ARCMT)
|
|
|
|
add_definitions(-DCLANG_ENABLE_ARCMT)
|
2014-07-17 00:48:33 +08:00
|
|
|
add_definitions(-DCLANG_ENABLE_OBJC_REWRITER)
|
2013-05-30 05:09:18 +08:00
|
|
|
endif()
|
|
|
|
if(CLANG_ENABLE_STATIC_ANALYZER)
|
|
|
|
add_definitions(-DCLANG_ENABLE_STATIC_ANALYZER)
|
|
|
|
endif()
|
2012-12-14 00:24:59 +08:00
|
|
|
|
2011-02-26 03:24:02 +08:00
|
|
|
# Clang version information
|
|
|
|
set(CLANG_EXECUTABLE_VERSION
|
|
|
|
"${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}" CACHE STRING
|
|
|
|
"Version number that will be placed into the clang executable, in the form XX.YY")
|
|
|
|
set(LIBCLANG_LIBRARY_VERSION
|
|
|
|
"${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}" CACHE STRING
|
|
|
|
"Version number that will be placed into the libclang library , in the form XX.YY")
|
|
|
|
mark_as_advanced(CLANG_EXECUTABLE_VERSION LIBCLANG_LIBRARY_VERSION)
|
|
|
|
|
2015-10-05 10:04:49 +08:00
|
|
|
option(CLANG_INCLUDE_TESTS
|
|
|
|
"Generate build targets for the Clang unit tests."
|
|
|
|
${LLVM_INCLUDE_TESTS})
|
|
|
|
|
2011-10-06 21:03:08 +08:00
|
|
|
add_subdirectory(utils/TableGen)
|
2011-02-26 03:24:02 +08:00
|
|
|
|
2009-03-17 07:06:59 +08:00
|
|
|
add_subdirectory(include)
|
2014-02-21 15:59:59 +08:00
|
|
|
|
|
|
|
# All targets below may depend on all tablegen'd files.
|
|
|
|
get_property(CLANG_TABLEGEN_TARGETS GLOBAL PROPERTY CLANG_TABLEGEN_TARGETS)
|
|
|
|
list(APPEND LLVM_COMMON_DEPENDS ${CLANG_TABLEGEN_TARGETS})
|
|
|
|
|
2008-10-26 08:56:18 +08:00
|
|
|
add_subdirectory(lib)
|
2009-03-24 10:52:57 +08:00
|
|
|
add_subdirectory(tools)
|
2010-12-16 11:28:42 +08:00
|
|
|
add_subdirectory(runtime)
|
2008-10-26 08:56:18 +08:00
|
|
|
|
2012-07-27 14:17:48 +08:00
|
|
|
option(CLANG_BUILD_EXAMPLES "Build CLANG example programs by default." OFF)
|
2014-01-08 19:55:49 +08:00
|
|
|
if (CLANG_BUILD_EXAMPLES)
|
|
|
|
set(ENABLE_CLANG_EXAMPLES "1")
|
|
|
|
else()
|
|
|
|
set(ENABLE_CLANG_EXAMPLES "0")
|
|
|
|
endif()
|
2012-07-27 14:17:48 +08:00
|
|
|
add_subdirectory(examples)
|
|
|
|
|
2013-02-08 09:42:37 +08:00
|
|
|
if( CLANG_INCLUDE_TESTS )
|
2013-12-20 00:05:44 +08:00
|
|
|
if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include/gtest/gtest.h)
|
|
|
|
add_subdirectory(unittests)
|
|
|
|
list(APPEND CLANG_TEST_DEPS ClangUnitTests)
|
|
|
|
list(APPEND CLANG_TEST_PARAMS
|
|
|
|
clang_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/test/Unit/lit.site.cfg
|
|
|
|
)
|
|
|
|
endif()
|
2013-08-20 15:09:54 +08:00
|
|
|
add_subdirectory(test)
|
2014-01-26 20:34:38 +08:00
|
|
|
|
|
|
|
if(CLANG_BUILT_STANDALONE)
|
|
|
|
# Add a global check rule now that all subdirectories have been traversed
|
|
|
|
# and we know the total set of lit testsuites.
|
|
|
|
get_property(LLVM_LIT_TESTSUITES GLOBAL PROPERTY LLVM_LIT_TESTSUITES)
|
|
|
|
get_property(LLVM_LIT_PARAMS GLOBAL PROPERTY LLVM_LIT_PARAMS)
|
|
|
|
get_property(LLVM_LIT_DEPENDS GLOBAL PROPERTY LLVM_LIT_DEPENDS)
|
|
|
|
get_property(LLVM_LIT_EXTRA_ARGS GLOBAL PROPERTY LLVM_LIT_EXTRA_ARGS)
|
|
|
|
add_lit_target(check-all
|
|
|
|
"Running all regression tests"
|
|
|
|
${LLVM_LIT_TESTSUITES}
|
|
|
|
PARAMS ${LLVM_LIT_PARAMS}
|
|
|
|
DEPENDS ${LLVM_LIT_DEPENDS}
|
|
|
|
ARGS ${LLVM_LIT_EXTRA_ARGS}
|
|
|
|
)
|
|
|
|
endif()
|
2015-12-16 09:02:44 +08:00
|
|
|
add_subdirectory(utils/perf-training)
|
2011-02-15 15:54:28 +08:00
|
|
|
endif()
|
2011-02-16 11:07:15 +08:00
|
|
|
|
2013-08-29 04:29:40 +08:00
|
|
|
option(CLANG_INCLUDE_DOCS "Generate build targets for the Clang docs."
|
|
|
|
${LLVM_INCLUDE_DOCS})
|
|
|
|
if( CLANG_INCLUDE_DOCS )
|
|
|
|
add_subdirectory(docs)
|
|
|
|
endif()
|
|
|
|
|
2013-08-27 12:40:12 +08:00
|
|
|
set(CLANG_ORDER_FILE "" CACHE FILEPATH
|
|
|
|
"Order file to use when compiling clang in order to improve startup time.")
|
2014-11-06 07:14:59 +08:00
|
|
|
|
2015-10-10 10:37:30 +08:00
|
|
|
if (CLANG_BUILT_STANDALONE OR CMAKE_VERSION VERSION_EQUAL 3 OR
|
|
|
|
CMAKE_VERSION VERSION_GREATER 3)
|
2014-11-06 07:51:45 +08:00
|
|
|
# Generate a list of CMake library targets so that other CMake projects can
|
|
|
|
# link against them. LLVM calls its version of this file LLVMExports.cmake, but
|
|
|
|
# the usual CMake convention seems to be ${Project}Targets.cmake.
|
|
|
|
set(CLANG_INSTALL_PACKAGE_DIR share/clang/cmake)
|
|
|
|
set(clang_cmake_builddir "${CMAKE_BINARY_DIR}/${CLANG_INSTALL_PACKAGE_DIR}")
|
|
|
|
get_property(CLANG_EXPORTS GLOBAL PROPERTY CLANG_EXPORTS)
|
|
|
|
export(TARGETS ${CLANG_EXPORTS} FILE ${clang_cmake_builddir}/ClangTargets.cmake)
|
|
|
|
|
|
|
|
# Install a <prefix>/share/clang/cmake/ClangConfig.cmake file so that
|
|
|
|
# find_package(Clang) works. Install the target list with it.
|
2015-05-30 06:58:05 +08:00
|
|
|
install(EXPORT ClangTargets DESTINATION ${CLANG_INSTALL_PACKAGE_DIR})
|
2015-05-30 02:36:20 +08:00
|
|
|
|
2014-11-06 07:51:45 +08:00
|
|
|
install(FILES
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/ClangConfig.cmake
|
|
|
|
DESTINATION share/clang/cmake)
|
|
|
|
|
|
|
|
# Also copy ClangConfig.cmake to the build directory so that dependent projects
|
|
|
|
# can build against a build directory of Clang more easily.
|
|
|
|
configure_file(
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/ClangConfig.cmake
|
|
|
|
${CLANG_BINARY_DIR}/share/clang/cmake/ClangConfig.cmake
|
|
|
|
COPYONLY)
|
|
|
|
endif ()
|
2015-08-06 01:38:12 +08:00
|
|
|
|
|
|
|
if (CLANG_ENABLE_BOOTSTRAP)
|
|
|
|
include(ExternalProject)
|
|
|
|
|
2015-08-21 04:12:18 +08:00
|
|
|
if(CMAKE_VERSION VERSION_GREATER 3.1.0)
|
|
|
|
set(cmake_3_1_EXCLUDE_FROM_ALL EXCLUDE_FROM_ALL 1)
|
|
|
|
endif()
|
|
|
|
|
2015-08-21 04:12:20 +08:00
|
|
|
if(CMAKE_VERSION VERSION_GREATER 3.3.20150708)
|
2015-08-06 01:38:12 +08:00
|
|
|
set(cmake_3_4_USES_TERMINAL_OPTIONS
|
|
|
|
USES_TERMINAL_CONFIGURE 1
|
|
|
|
USES_TERMINAL_BUILD 1
|
|
|
|
USES_TERMINAL_INSTALL 1
|
|
|
|
)
|
2015-08-06 04:46:39 +08:00
|
|
|
set(cmake_3_4_USES_TERMINAL USES_TERMINAL 1)
|
2015-08-06 01:38:12 +08:00
|
|
|
endif()
|
2015-12-17 04:17:07 +08:00
|
|
|
|
|
|
|
if(NOT CLANG_STAGE)
|
|
|
|
set(CLANG_STAGE stage1)
|
|
|
|
message(STATUS "Setting current clang stage to: ${CLANG_STAGE}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
string(REGEX MATCH "stage([0-9]*)" MATCHED_STAGE "${CLANG_STAGE}")
|
|
|
|
if(MATCHED_STAGE)
|
|
|
|
math(EXPR STAGE_NUM "${MATCHED_STAGE} + 1")
|
|
|
|
set(NEXT_CLANG_STAGE stage${STAGE_NUM})
|
|
|
|
else()
|
|
|
|
set(NEXT_CLANG_STAGE bootstrap)
|
|
|
|
endif()
|
|
|
|
message(STATUS "Setting next clang stage to: ${NEXT_CLANG_STAGE}")
|
2015-08-06 01:38:12 +08:00
|
|
|
|
2015-12-17 04:17:07 +08:00
|
|
|
|
|
|
|
set(STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-stamps/)
|
|
|
|
set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-bins/)
|
2015-08-06 01:38:12 +08:00
|
|
|
|
2015-09-12 04:42:57 +08:00
|
|
|
# If on Darwin we need to make bootstrap depend on LTO and pass
|
|
|
|
# DARWIN_LTO_LIBRARY so that -flto will work using the just-built compiler
|
|
|
|
if(APPLE)
|
|
|
|
set(LTO_DEP LTO llvm-ar llvm-ranlib)
|
2015-10-10 01:45:44 +08:00
|
|
|
set(LTO_LIBRARY -DDARWIN_LTO_LIBRARY=${LLVM_SHLIB_OUTPUT_INTDIR}/libLTO.dylib)
|
2015-10-02 08:56:53 +08:00
|
|
|
set(LTO_AR -DCMAKE_AR=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ar)
|
|
|
|
set(LTO_RANLIB -DCMAKE_RANLIB=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ranlib)
|
2015-09-12 04:42:57 +08:00
|
|
|
endif()
|
|
|
|
|
2015-12-17 04:17:07 +08:00
|
|
|
add_custom_target(${NEXT_CLANG_STAGE}-clear
|
|
|
|
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-cleared
|
2015-08-06 01:38:12 +08:00
|
|
|
)
|
|
|
|
add_custom_command(
|
2015-12-17 04:17:07 +08:00
|
|
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NEXT_CLANG_STAGE}-cleared
|
2015-09-12 04:42:57 +08:00
|
|
|
DEPENDS clang ${LTO_DEP}
|
2015-08-06 01:38:12 +08:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E remove_directory ${BINARY_DIR}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${BINARY_DIR}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E remove_directory ${STAMP_DIR}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${STAMP_DIR}
|
2015-12-17 04:17:07 +08:00
|
|
|
COMMENT "Clobberring ${NEXT_CLANG_STAGE} build and stamp directories"
|
2015-08-06 01:38:12 +08:00
|
|
|
)
|
|
|
|
|
2015-11-10 06:43:10 +08:00
|
|
|
if(CMAKE_VERBOSE_MAKEFILE)
|
|
|
|
set(verbose -DCMAKE_VERBOSE_MAKEFILE=On)
|
|
|
|
endif()
|
|
|
|
|
2015-11-21 06:09:06 +08:00
|
|
|
set(BOOTSTRAP_DEFAULT_PASSTHROUGH
|
|
|
|
PACKAGE_VERSION
|
|
|
|
LLVM_VERSION_MAJOR
|
|
|
|
LLVM_VERSION_MINOR
|
|
|
|
LLVM_VERSION_PATCH
|
|
|
|
LLVM_VERSION_SUFFIX
|
|
|
|
CLANG_REPOSITORY_STRING
|
|
|
|
CMAKE_MAKE_PROGRAM)
|
|
|
|
|
2015-12-17 02:49:12 +08:00
|
|
|
if(TARGET compiler-rt)
|
|
|
|
set(RUNTIME_DEP compiler-rt)
|
|
|
|
endif()
|
|
|
|
|
2015-11-21 06:09:06 +08:00
|
|
|
# Find all variables that start with BOOTSTRAP_ and populate a variable with
|
|
|
|
# them.
|
|
|
|
get_cmake_property(variableNames VARIABLES)
|
2015-11-24 07:34:13 +08:00
|
|
|
foreach(variableName ${variableNames})
|
|
|
|
if(variableName MATCHES "^BOOTSTRAP_")
|
|
|
|
string(SUBSTRING ${variableName} 10 -1 varName)
|
|
|
|
string(REPLACE ";" "\;" value "${${variableName}}")
|
2015-11-21 06:09:06 +08:00
|
|
|
list(APPEND PASSTHROUGH_VARIABLES
|
|
|
|
-D${varName}=${value})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
# Populate the passthrough variables
|
2015-11-24 07:34:13 +08:00
|
|
|
foreach(variableName ${CLANG_BOOTSTRAP_PASSTHROUGH} ${BOOTSTRAP_DEFAULT_PASSTHROUGH})
|
|
|
|
if(${variableName})
|
|
|
|
string(REPLACE ";" "\;" value ${${variableName}})
|
2015-11-21 06:09:06 +08:00
|
|
|
list(APPEND PASSTHROUGH_VARIABLES
|
2015-11-24 07:34:13 +08:00
|
|
|
-D${variableName}=${value})
|
2015-11-21 06:09:06 +08:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
2015-12-17 04:17:07 +08:00
|
|
|
ExternalProject_Add(${NEXT_CLANG_STAGE}
|
2015-12-17 02:49:12 +08:00
|
|
|
DEPENDS clang ${LTO_DEP} ${RUNTIME_DEP}
|
2015-12-17 04:17:07 +08:00
|
|
|
PREFIX ${NEXT_CLANG_STAGE}
|
2015-08-06 01:38:12 +08:00
|
|
|
SOURCE_DIR ${CMAKE_SOURCE_DIR}
|
|
|
|
STAMP_DIR ${STAMP_DIR}
|
|
|
|
BINARY_DIR ${BINARY_DIR}
|
2015-08-21 04:12:18 +08:00
|
|
|
${cmake_3_1_EXCLUDE_FROM_ALL}
|
2015-08-06 01:38:12 +08:00
|
|
|
CMAKE_ARGS
|
|
|
|
# We shouldn't need to set this here, but INSTALL_DIR doesn't
|
|
|
|
# seem to work, so instead I'm passing this through
|
|
|
|
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
|
|
|
|
${CLANG_BOOTSTRAP_CMAKE_ARGS}
|
2015-11-21 06:09:06 +08:00
|
|
|
${PASSTHROUGH_VARIABLES}
|
2015-10-02 08:56:53 +08:00
|
|
|
-DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++
|
|
|
|
-DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
|
|
|
|
-DCMAKE_ASM_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
|
2015-12-17 04:17:07 +08:00
|
|
|
-DCLANG_STAGE=${NEXT_CLANG_STAGE}
|
2015-11-10 06:43:10 +08:00
|
|
|
${LTO_LIBRARY} ${LTO_AR} ${LTO_RANLIB} ${verbose}
|
2015-08-06 01:38:12 +08:00
|
|
|
INSTALL_COMMAND ""
|
|
|
|
STEP_TARGETS configure build
|
|
|
|
${cmake_3_4_USES_TERMINAL_OPTIONS}
|
|
|
|
)
|
|
|
|
|
|
|
|
# exclude really-install from main target
|
2015-12-17 04:17:07 +08:00
|
|
|
set_target_properties(${NEXT_CLANG_STAGE} PROPERTIES _EP_really-install_EXCLUDE_FROM_MAIN On)
|
|
|
|
ExternalProject_Add_Step(${NEXT_CLANG_STAGE} really-install
|
2015-08-06 01:38:12 +08:00
|
|
|
COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target install
|
2015-12-17 04:17:07 +08:00
|
|
|
COMMENT "Performing install step for '${NEXT_CLANG_STAGE}'"
|
2015-08-06 01:38:12 +08:00
|
|
|
DEPENDEES build
|
2015-08-06 04:46:39 +08:00
|
|
|
${cmake_3_4_USES_TERMINAL}
|
2015-08-06 01:38:12 +08:00
|
|
|
)
|
2015-12-17 04:17:07 +08:00
|
|
|
ExternalProject_Add_StepTargets(${NEXT_CLANG_STAGE} really-install)
|
|
|
|
add_custom_target(${NEXT_CLANG_STAGE}-install DEPENDS ${NEXT_CLANG_STAGE}-really-install)
|
2015-08-06 01:38:12 +08:00
|
|
|
|
2015-12-17 02:45:53 +08:00
|
|
|
if(NOT CLANG_BOOTSTRAP_TARGETS)
|
|
|
|
set(CLANG_BOOTSTRAP_TARGETS check-llvm check-clang check-all)
|
|
|
|
endif()
|
|
|
|
foreach(target ${CLANG_BOOTSTRAP_TARGETS})
|
2015-08-06 01:38:12 +08:00
|
|
|
# exclude from main target
|
2015-12-17 04:17:07 +08:00
|
|
|
set_target_properties(${NEXT_CLANG_STAGE} PROPERTIES _EP_${target}_EXCLUDE_FROM_MAIN On)
|
2015-08-06 01:38:12 +08:00
|
|
|
|
2015-12-17 04:17:07 +08:00
|
|
|
ExternalProject_Add_Step(${NEXT_CLANG_STAGE} ${target}
|
2015-08-06 01:38:12 +08:00
|
|
|
COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target ${target}
|
2015-12-17 04:17:07 +08:00
|
|
|
COMMENT "Performing ${target} for '${NEXT_CLANG_STAGE}'"
|
2015-08-06 01:38:12 +08:00
|
|
|
DEPENDEES configure
|
2015-08-06 04:46:39 +08:00
|
|
|
${cmake_3_4_USES_TERMINAL}
|
2015-08-06 01:38:12 +08:00
|
|
|
)
|
2015-12-17 04:17:07 +08:00
|
|
|
|
|
|
|
if(target MATCHES "^stage[0-9]*")
|
|
|
|
add_custom_target(${target} DEPENDS ${NEXT_CLANG_STAGE}-${target})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
ExternalProject_Add_StepTargets(${NEXT_CLANG_STAGE} ${target})
|
2015-08-06 01:38:12 +08:00
|
|
|
endforeach()
|
|
|
|
endif()
|