]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lld/CMakeLists.txt
MFC r309362:
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lld / CMakeLists.txt
1 set(LLD_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
2 set(LLD_INCLUDE_DIR ${LLD_SOURCE_DIR}/include )
3 set(LLD_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
4
5 # Compute the LLD version from the LLVM version.
6 string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" LLD_VERSION
7   ${PACKAGE_VERSION})
8 message(STATUS "LLD version: ${LLD_VERSION}")
9
10 string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" LLD_VERSION_MAJOR
11   ${LLD_VERSION})
12 string(REGEX REPLACE "[0-9]+\\.([0-9]+)(\\.[0-9]+)?" "\\1" LLD_VERSION_MINOR
13   ${LLD_VERSION})
14
15 # Determine LLD revision and repository.
16 # TODO: Figure out a way to get the revision and the repository on windows.
17 if ( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" )
18   execute_process(COMMAND ${CMAKE_SOURCE_DIR}/utils/GetSourceVersion ${LLD_SOURCE_DIR}
19                   OUTPUT_VARIABLE LLD_REVISION)
20
21   execute_process(COMMAND ${CMAKE_SOURCE_DIR}/utils/GetRepositoryPath ${LLD_SOURCE_DIR}
22                   OUTPUT_VARIABLE LLD_REPOSITORY)
23   if ( LLD_REPOSITORY )
24     # Replace newline characters with spaces
25     string(REGEX REPLACE "(\r?\n)+" " " LLD_REPOSITORY ${LLD_REPOSITORY})
26     # Remove leading spaces
27     STRING(REGEX REPLACE "^[ \t\r\n]+" "" LLD_REPOSITORY "${LLD_REPOSITORY}" )
28     # Remove trailing spaces
29     string(REGEX REPLACE "(\ )+$" "" LLD_REPOSITORY ${LLD_REPOSITORY})
30   endif()
31
32   if ( LLD_REVISION )
33     # Replace newline characters with spaces
34     string(REGEX REPLACE "(\r?\n)+" " " LLD_REVISION ${LLD_REVISION})
35     # Remove leading spaces
36     STRING(REGEX REPLACE "^[ \t\r\n]+" "" LLD_REVISION "${LLD_REVISION}" )
37     # Remove trailing spaces
38     string(REGEX REPLACE "(\ )+$" "" LLD_REVISION ${LLD_REVISION})
39   endif()
40 endif ()
41
42 # Configure the Version.inc file.
43 configure_file(
44   ${CMAKE_CURRENT_SOURCE_DIR}/include/lld/Config/Version.inc.in
45   ${CMAKE_CURRENT_BINARY_DIR}/include/lld/Config/Version.inc)
46
47
48 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
49   message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite "
50 "the makefiles distributed with LLVM. Please create a directory and run cmake "
51 "from there, passing the path to this source directory as the last argument. "
52 "This process created the file `CMakeCache.txt' and the directory "
53 "`CMakeFiles'. Please delete them.")
54 endif()
55
56 list (APPEND CMAKE_MODULE_PATH "${LLD_SOURCE_DIR}/cmake/modules")
57
58 option(LLD_USE_VTUNE
59        "Enable VTune user task tracking."
60        OFF)
61 if (LLD_USE_VTUNE)
62   find_package(VTune)
63   if (VTUNE_FOUND)
64     include_directories(${VTune_INCLUDE_DIRS})
65     list(APPEND LLVM_COMMON_LIBS ${VTune_LIBRARIES})
66     add_definitions(-DLLD_HAS_VTUNE)
67   endif()
68 endif()
69
70
71 if (MSVC)
72   add_definitions(-wd4530) # Suppress 'warning C4530: C++ exception handler used, but unwind semantics are not enabled.'
73   add_definitions(-wd4062) # Suppress 'warning C4062: enumerator X in switch of enum Y is not handled' from system header.
74 endif()
75
76 include_directories(BEFORE
77   ${CMAKE_CURRENT_BINARY_DIR}/include
78   ${CMAKE_CURRENT_SOURCE_DIR}/include
79   )
80
81 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
82   install(DIRECTORY include/
83     DESTINATION include
84     FILES_MATCHING
85     PATTERN "*.h"
86     PATTERN ".svn" EXCLUDE
87     )
88 endif()
89
90 macro(add_lld_library name)
91   add_llvm_library(${name} ${ARGN})
92   set_target_properties(${name} PROPERTIES FOLDER "lld libraries")
93 endmacro(add_lld_library)
94
95
96 add_subdirectory(lib)
97 add_subdirectory(tools/lld)
98
99 if (LLVM_INCLUDE_TESTS)
100   add_subdirectory(test)
101   add_subdirectory(unittests)
102 endif()
103
104 add_subdirectory(docs)
105 add_subdirectory(COFF)
106 add_subdirectory(ELF)