2011-12-18 16:27:59 +08:00
|
|
|
# If we are not building as a part of LLVM, build lld as a standalone project,
|
|
|
|
# using LLVM as an external library.
|
|
|
|
|
2014-02-26 14:27:59 +08:00
|
|
|
cmake_minimum_required(VERSION 2.8)
|
2012-03-08 08:18:30 +08:00
|
|
|
|
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-12-18 16:27:59 +08:00
|
|
|
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
|
|
|
project(lld)
|
|
|
|
|
|
|
|
set(LLD_PATH_TO_LLVM_SOURCE "" CACHE PATH
|
|
|
|
"Path to LLVM source code. Not necessary if using an installed LLVM.")
|
|
|
|
set(LLD_PATH_TO_LLVM_BUILD "" CACHE PATH
|
|
|
|
"Path to the directory where LLVM was built or installed.")
|
|
|
|
|
|
|
|
if (LLD_PATH_TO_LLVM_SOURCE)
|
|
|
|
if (NOT EXISTS "${LLD_PATH_TO_LLVM_SOURCE}/cmake/config-ix.cmake")
|
|
|
|
message(FATAL_ERROR "Please set LLD_PATH_TO_LLVM_SOURCE to the root "
|
|
|
|
"directory of LLVM source code.")
|
|
|
|
else()
|
|
|
|
get_filename_component(LLVM_MAIN_SRC_DIR ${LLD_PATH_TO_LLVM_SOURCE}
|
|
|
|
ABSOLUTE)
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${LLVM_MAIN_SRC_DIR}/cmake/modules")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${LLD_PATH_TO_LLVM_BUILD}/share/llvm/cmake")
|
|
|
|
|
|
|
|
get_filename_component(PATH_TO_LLVM_BUILD ${LLD_PATH_TO_LLVM_BUILD}
|
|
|
|
ABSOLUTE)
|
|
|
|
|
2013-08-24 08:24:15 +08:00
|
|
|
option(LLVM_INSTALL_TOOLCHAIN_ONLY
|
|
|
|
"Only include toolchain files in the 'install' target." OFF)
|
|
|
|
|
2011-12-18 16:27:59 +08:00
|
|
|
include(AddLLVM)
|
2012-12-11 07:52:34 +08:00
|
|
|
include(TableGen)
|
2011-12-18 16:27:59 +08:00
|
|
|
include("${LLD_PATH_TO_LLVM_BUILD}/share/llvm/cmake/LLVMConfig.cmake")
|
|
|
|
include(HandleLLVMOptions)
|
|
|
|
|
|
|
|
set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
|
|
|
|
|
|
|
|
set(LLVM_MAIN_INCLUDE_DIR "${LLVM_MAIN_SRC_DIR}/include")
|
|
|
|
set(LLVM_BINARY_DIR ${CMAKE_BINARY_DIR})
|
|
|
|
|
|
|
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
|
|
|
include_directories("${PATH_TO_LLVM_BUILD}/include"
|
|
|
|
"${LLVM_MAIN_INCLUDE_DIR}")
|
2014-12-29 20:11:30 +08:00
|
|
|
link_directories("${PATH_TO_LLVM_BUILD}/lib${LLVM_LIBDIR_SUFFIX}")
|
2011-12-18 16:27:59 +08:00
|
|
|
|
2013-08-24 02:18:13 +08:00
|
|
|
if (EXISTS "${LLD_PATH_TO_LLVM_BUILD}/bin/llvm-config${CMAKE_EXECUTABLE_SUFFIX}")
|
|
|
|
set (PATH_TO_LLVM_CONFIG "${LLD_PATH_TO_LLVM_BUILD}/bin/llvm-config${CMAKE_EXECUTABLE_SUFFIX}")
|
|
|
|
elseif (EXISTS "${LLD_PATH_TO_LLVM_BUILD}/bin/Debug/llvm-config${CMAKE_EXECUTABLE_SUFFIX}")
|
2012-12-11 07:52:34 +08:00
|
|
|
# FIXME: This is an utter hack.
|
2013-08-24 02:18:13 +08:00
|
|
|
set (PATH_TO_LLVM_CONFIG "${LLD_PATH_TO_LLVM_BUILD}/bin/Debug/llvm-config${CMAKE_EXECUTABLE_SUFFIX}")
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Please set LLD_PATH_TO_LLVM_BUILD to a directory containing a LLVM build.")
|
2012-12-11 07:52:34 +08:00
|
|
|
endif()
|
|
|
|
|
2013-08-24 02:18:13 +08:00
|
|
|
exec_program("${PATH_TO_LLVM_CONFIG} --bindir" OUTPUT_VARIABLE LLVM_BINARY_DIR)
|
|
|
|
set(LLVM_TABLEGEN_EXE "${LLVM_BINARY_DIR}/llvm-tblgen${CMAKE_EXECUTABLE_SUFFIX}")
|
|
|
|
|
2011-12-18 16:27:59 +08:00
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
2014-12-29 20:11:30 +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-12-18 16:27:59 +08:00
|
|
|
|
|
|
|
set(LLD_BUILT_STANDALONE 1)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(LLD_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
set(LLD_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
|
2014-10-08 11:47:51 +08:00
|
|
|
# Compute the LLD version from the LLVM version.
|
|
|
|
string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" LLD_VERSION
|
|
|
|
${PACKAGE_VERSION})
|
|
|
|
message(STATUS "LLD version: ${LLD_VERSION}")
|
|
|
|
|
|
|
|
string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" LLD_VERSION_MAJOR
|
|
|
|
${LLD_VERSION})
|
|
|
|
string(REGEX REPLACE "[0-9]+\\.([0-9]+)(\\.[0-9]+)?" "\\1" LLD_VERSION_MINOR
|
|
|
|
${LLD_VERSION})
|
|
|
|
|
|
|
|
# Determine LLD revision and repository.
|
|
|
|
# TODO: Figure out a way to get the revision and the repository on windows.
|
|
|
|
if ( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" )
|
|
|
|
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/utils/GetSourceVersion ${LLD_SOURCE_DIR}
|
|
|
|
OUTPUT_VARIABLE LLD_REVISION)
|
|
|
|
|
|
|
|
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/utils/GetRepositoryPath ${LLD_SOURCE_DIR}
|
|
|
|
OUTPUT_VARIABLE LLD_REPOSITORY)
|
|
|
|
if ( LLD_REPOSITORY )
|
|
|
|
# Replace newline characters with spaces
|
|
|
|
string(REGEX REPLACE "(\r?\n)+" " " LLD_REPOSITORY ${LLD_REPOSITORY})
|
|
|
|
# Remove leading spaces
|
|
|
|
STRING(REGEX REPLACE "^[ \t\r\n]+" "" LLD_REPOSITORY "${LLD_REPOSITORY}" )
|
|
|
|
# Remove trailing spaces
|
|
|
|
string(REGEX REPLACE "(\ )+$" "" LLD_REPOSITORY ${LLD_REPOSITORY})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if ( LLD_REVISION )
|
|
|
|
# Replace newline characters with spaces
|
|
|
|
string(REGEX REPLACE "(\r?\n)+" " " LLD_REVISION ${LLD_REVISION})
|
|
|
|
# Remove leading spaces
|
|
|
|
STRING(REGEX REPLACE "^[ \t\r\n]+" "" LLD_REVISION "${LLD_REVISION}" )
|
|
|
|
# Remove trailing spaces
|
|
|
|
string(REGEX REPLACE "(\ )+$" "" LLD_REVISION ${LLD_REVISION})
|
|
|
|
endif()
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
# Configure the Version.inc file.
|
|
|
|
configure_file(
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include/lld/Config/Version.inc.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/include/lld/Config/Version.inc)
|
|
|
|
|
|
|
|
|
2011-12-18 16:27:59 +08:00
|
|
|
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
|
|
|
|
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()
|
|
|
|
|
2013-04-06 08:56:40 +08:00
|
|
|
list (APPEND CMAKE_MODULE_PATH "${LLD_SOURCE_DIR}/cmake/modules")
|
|
|
|
|
|
|
|
option(LLD_USE_VTUNE
|
|
|
|
"Enable VTune user task tracking."
|
|
|
|
OFF)
|
|
|
|
if (LLD_USE_VTUNE)
|
|
|
|
find_package(VTune)
|
|
|
|
if (VTUNE_FOUND)
|
|
|
|
include_directories(${VTune_INCLUDE_DIRS})
|
|
|
|
list(APPEND LLVM_COMMON_LIBS ${VTune_LIBRARIES})
|
|
|
|
add_definitions(-DLLD_HAS_VTUNE)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2013-01-05 12:16:52 +08:00
|
|
|
# lld requires c++11 to build. Make sure that we have a compiler and standard
|
|
|
|
# library combination that can do that.
|
2013-11-12 23:14:33 +08:00
|
|
|
if (NOT MSVC)
|
2013-01-05 12:16:52 +08:00
|
|
|
# gcc and clang require the -std=c++0x or -std=c++11 flag.
|
2013-05-15 03:53:41 +08:00
|
|
|
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang" AND
|
2014-03-01 11:18:56 +08:00
|
|
|
NOT ("${CMAKE_CXX_FLAGS}" MATCHES ".*-std=(c|gnu)\\+\\+(0x|11|1y).*"))
|
2013-05-15 03:53:41 +08:00
|
|
|
message(FATAL_ERROR
|
|
|
|
"lld requires c++11. Clang and gcc require -std=c++0x or -std=c++11 to "
|
|
|
|
"enter this mode. Please set CMAKE_CXX_FLAGS accordingly.")
|
2012-04-19 05:55:06 +08:00
|
|
|
endif()
|
2013-11-12 23:14:33 +08:00
|
|
|
elseif (MSVC_VERSION LESS 1700)
|
2013-01-05 12:16:52 +08:00
|
|
|
message(FATAL_ERROR "The selected compiler does not support c++11 which is "
|
|
|
|
"required to build lld.")
|
2012-03-08 08:18:30 +08:00
|
|
|
endif()
|
|
|
|
|
2014-12-03 01:57:54 +08:00
|
|
|
if (MSVC)
|
|
|
|
add_definitions(-wd4530) # Suppress 'warning C4530: C++ exception handler used, but unwind semantics are not enabled.'
|
|
|
|
endif()
|
|
|
|
|
2011-12-18 16:27:59 +08:00
|
|
|
macro(add_lld_library name)
|
|
|
|
llvm_process_sources(srcs ${ARGN})
|
|
|
|
if (MSVC_IDE OR XCODE)
|
|
|
|
string(REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
list(GET split_path -1 dir)
|
|
|
|
file(GLOB_RECURSE headers
|
|
|
|
../../include/lld${dir}/*.h)
|
|
|
|
set(srcs ${srcs} ${headers})
|
|
|
|
endif()
|
|
|
|
if (MODULE)
|
|
|
|
set(libkind MODULE)
|
|
|
|
elseif (SHARED_LIBRARY)
|
|
|
|
set(libkind SHARED)
|
|
|
|
else()
|
|
|
|
set(libkind)
|
|
|
|
endif()
|
|
|
|
add_library(${name} ${libkind} ${srcs})
|
2014-01-28 18:45:37 +08:00
|
|
|
llvm_update_compile_flags(${name} ${srcs})
|
2011-12-18 16:27:59 +08:00
|
|
|
if (LLVM_COMMON_DEPENDS)
|
|
|
|
add_dependencies(${name} ${LLVM_COMMON_DEPENDS})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
target_link_libraries(${name} ${LLVM_USED_LIBS})
|
|
|
|
llvm_config(${name} ${LLVM_LINK_COMPONENTS})
|
|
|
|
target_link_libraries(${name} ${LLVM_COMMON_LIBS})
|
|
|
|
|
2013-08-24 08:24:15 +08:00
|
|
|
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
|
|
|
|
install(TARGETS ${name}
|
|
|
|
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
|
|
|
|
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
|
|
|
|
endif()
|
2011-12-18 16:27:59 +08:00
|
|
|
set_target_properties(${name} PROPERTIES FOLDER "lld libraries")
|
|
|
|
endmacro(add_lld_library)
|
|
|
|
|
|
|
|
macro(add_lld_executable name)
|
|
|
|
add_llvm_executable(${name} ${ARGN})
|
|
|
|
set_target_properties(${name} PROPERTIES FOLDER "lld executables")
|
|
|
|
endmacro(add_lld_executable)
|
|
|
|
|
|
|
|
include_directories(BEFORE
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/include
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
|
|
)
|
|
|
|
|
2013-08-24 08:24:15 +08:00
|
|
|
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
|
|
|
|
install(DIRECTORY include/
|
|
|
|
DESTINATION include
|
|
|
|
FILES_MATCHING
|
|
|
|
PATTERN "*.h"
|
|
|
|
PATTERN ".svn" EXCLUDE
|
|
|
|
)
|
|
|
|
endif()
|
2011-12-18 16:27:59 +08:00
|
|
|
|
|
|
|
add_subdirectory(lib)
|
|
|
|
add_subdirectory(tools)
|
2013-03-01 08:03:36 +08:00
|
|
|
add_subdirectory(utils)
|
2011-12-18 16:27:59 +08:00
|
|
|
|
|
|
|
add_subdirectory(test)
|
2012-12-19 08:51:07 +08:00
|
|
|
|
|
|
|
if (LLVM_INCLUDE_TESTS AND NOT LLD_BUILT_STANDALONE)
|
|
|
|
add_subdirectory(unittests)
|
|
|
|
endif()
|
2014-04-19 05:59:05 +08:00
|
|
|
|
|
|
|
add_subdirectory(docs)
|