mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-08 14:49:38 +00:00
57c29ad223
* Works better for shared libraries (sets PRIVATE instead of INTERFACE) * Fixes http://llvm.org/bugs/show_bug.cgi?id=22269 * Also, use build-target names instead of component names Differential Revision: http://reviews.llvm.org/D7074 From: Greg Fitzgerald <garious@gmail.com> llvm-svn: 226702
118 lines
3.9 KiB
CMake
118 lines
3.9 KiB
CMake
# If we are not building as a part of LLVM, build lld as a standalone project,
|
|
# using LLVM as an external library.
|
|
|
|
cmake_minimum_required(VERSION 2.8)
|
|
|
|
set(LLD_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
|
set(LLD_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
# 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)
|
|
|
|
|
|
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()
|
|
|
|
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()
|
|
|
|
# lld requires c++11 to build. Make sure that we have a compiler and standard
|
|
# library combination that can do that.
|
|
if (NOT MSVC)
|
|
# gcc and clang require the -std=c++0x or -std=c++11 flag.
|
|
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang" AND
|
|
NOT ("${CMAKE_CXX_FLAGS}" MATCHES ".*-std=(c|gnu)\\+\\+(0x|11|1y).*"))
|
|
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.")
|
|
endif()
|
|
elseif (MSVC_VERSION LESS 1700)
|
|
message(FATAL_ERROR "The selected compiler does not support c++11 which is "
|
|
"required to build lld.")
|
|
endif()
|
|
|
|
if (MSVC)
|
|
add_definitions(-wd4530) # Suppress 'warning C4530: C++ exception handler used, but unwind semantics are not enabled.'
|
|
endif()
|
|
|
|
include_directories(BEFORE
|
|
${CMAKE_CURRENT_BINARY_DIR}/include
|
|
${CMAKE_CURRENT_SOURCE_DIR}/include
|
|
)
|
|
|
|
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
|
|
install(DIRECTORY include/
|
|
DESTINATION include
|
|
FILES_MATCHING
|
|
PATTERN "*.h"
|
|
PATTERN ".svn" EXCLUDE
|
|
)
|
|
endif()
|
|
|
|
add_subdirectory(lib)
|
|
add_subdirectory(tools)
|
|
add_subdirectory(utils)
|
|
|
|
add_subdirectory(test)
|
|
|
|
if (LLVM_INCLUDE_TESTS)
|
|
add_subdirectory(unittests)
|
|
endif()
|
|
|
|
add_subdirectory(docs)
|