2015-11-11 17:14:03 +01:00
|
|
|
include(ExternalProject)
|
|
|
|
|
|
|
|
# llvm_ExternalProject_BuildCmd(out_var target)
|
|
|
|
# Utility function for constructing command lines for external project targets
|
2016-04-09 00:46:04 +02:00
|
|
|
function(llvm_ExternalProject_BuildCmd out_var target bin_dir)
|
2016-09-06 22:27:07 +02:00
|
|
|
cmake_parse_arguments(ARG "" "CONFIGURATION" "" ${ARGN})
|
|
|
|
if(NOT ARG_CONFIGURATION)
|
|
|
|
set(ARG_CONFIGURATION "$<CONFIGURATION>")
|
|
|
|
endif()
|
2015-11-11 17:14:03 +01:00
|
|
|
if (CMAKE_GENERATOR MATCHES "Make")
|
|
|
|
# Use special command for Makefiles to support parallelism.
|
2016-09-06 22:27:07 +02:00
|
|
|
set(${out_var} "$(MAKE)" "-C" "${bin_dir}" "${target}" PARENT_SCOPE)
|
2015-11-11 17:14:03 +01:00
|
|
|
else()
|
2016-04-09 00:46:04 +02:00
|
|
|
set(${out_var} ${CMAKE_COMMAND} --build ${bin_dir} --target ${target}
|
2016-09-06 22:27:07 +02:00
|
|
|
--config ${ARG_CONFIGURATION} PARENT_SCOPE)
|
2015-11-11 17:14:03 +01:00
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# llvm_ExternalProject_Add(name source_dir ...
|
|
|
|
# USE_TOOLCHAIN
|
|
|
|
# Use just-built tools (see TOOLCHAIN_TOOLS)
|
|
|
|
# EXCLUDE_FROM_ALL
|
|
|
|
# Exclude this project from the all target
|
|
|
|
# NO_INSTALL
|
|
|
|
# Don't generate install targets for this project
|
2016-06-24 00:07:21 +02:00
|
|
|
# ALWAYS_CLEAN
|
|
|
|
# Always clean the sub-project before building
|
2015-11-11 17:14:03 +01:00
|
|
|
# CMAKE_ARGS arguments...
|
|
|
|
# Optional cmake arguments to pass when configuring the project
|
|
|
|
# TOOLCHAIN_TOOLS targets...
|
|
|
|
# Targets for toolchain tools (defaults to clang;lld)
|
|
|
|
# DEPENDS targets...
|
|
|
|
# Targets that this project depends on
|
|
|
|
# EXTRA_TARGETS targets...
|
|
|
|
# Extra targets in the subproject to generate targets for
|
2016-06-24 00:07:21 +02:00
|
|
|
# PASSTHROUGH_PREFIXES prefix...
|
|
|
|
# Extra variable prefixes (name is always included) to pass down
|
2015-11-11 17:14:03 +01:00
|
|
|
# )
|
|
|
|
function(llvm_ExternalProject_Add name source_dir)
|
2016-06-24 00:07:21 +02:00
|
|
|
cmake_parse_arguments(ARG
|
|
|
|
"USE_TOOLCHAIN;EXCLUDE_FROM_ALL;NO_INSTALL;ALWAYS_CLEAN"
|
2015-11-11 17:14:03 +01:00
|
|
|
"SOURCE_DIR"
|
2016-06-24 00:07:21 +02:00
|
|
|
"CMAKE_ARGS;TOOLCHAIN_TOOLS;RUNTIME_LIBRARIES;DEPENDS;EXTRA_TARGETS;PASSTHROUGH_PREFIXES"
|
|
|
|
${ARGN})
|
2015-11-11 17:14:03 +01:00
|
|
|
canonicalize_tool_name(${name} nameCanon)
|
|
|
|
if(NOT ARG_TOOLCHAIN_TOOLS)
|
|
|
|
set(ARG_TOOLCHAIN_TOOLS clang lld)
|
2016-12-13 00:15:10 +01:00
|
|
|
if(NOT APPLE AND NOT WIN32)
|
|
|
|
list(APPEND ARG_TOOLCHAIN_TOOLS llvm-ar llvm-ranlib)
|
|
|
|
endif()
|
2015-11-11 17:14:03 +01:00
|
|
|
endif()
|
|
|
|
foreach(tool ${ARG_TOOLCHAIN_TOOLS})
|
|
|
|
if(TARGET ${tool})
|
|
|
|
list(APPEND TOOLCHAIN_TOOLS ${tool})
|
|
|
|
list(APPEND TOOLCHAIN_BINS $<TARGET_FILE:${tool}>)
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
if(NOT ARG_RUNTIME_LIBRARIES)
|
|
|
|
set(ARG_RUNTIME_LIBRARIES compiler-rt libcxx)
|
|
|
|
endif()
|
|
|
|
foreach(lib ${ARG_RUNTIME_LIBRARIES})
|
|
|
|
if(TARGET ${lib})
|
|
|
|
list(APPEND RUNTIME_LIBRARIES ${lib})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
2016-06-24 00:07:21 +02:00
|
|
|
if(ARG_ALWAYS_CLEAN)
|
|
|
|
set(always_clean clean)
|
|
|
|
endif()
|
|
|
|
|
2015-11-11 17:14:03 +01:00
|
|
|
list(FIND TOOLCHAIN_TOOLS clang FOUND_CLANG)
|
|
|
|
if(FOUND_CLANG GREATER -1)
|
|
|
|
set(CLANG_IN_TOOLCHAIN On)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(RUNTIME_LIBRARIES AND CLANG_IN_TOOLCHAIN)
|
|
|
|
list(APPEND TOOLCHAIN_BINS ${RUNTIME_LIBRARIES})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(STAMP_DIR ${CMAKE_CURRENT_BINARY_DIR}/${name}-stamps/)
|
|
|
|
set(BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${name}-bins/)
|
|
|
|
|
|
|
|
add_custom_target(${name}-clear
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E remove_directory ${BINARY_DIR}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E remove_directory ${STAMP_DIR}
|
|
|
|
COMMENT "Clobbering ${name} build and stamp directories"
|
2016-06-09 00:19:25 +02:00
|
|
|
USES_TERMINAL
|
2015-11-11 17:14:03 +01:00
|
|
|
)
|
|
|
|
|
2016-06-24 00:07:21 +02:00
|
|
|
# Find all variables that start with a prefix and propagate them through
|
2015-11-11 17:14:03 +01:00
|
|
|
get_cmake_property(variableNames VARIABLES)
|
2016-06-24 00:07:21 +02:00
|
|
|
|
|
|
|
list(APPEND ARG_PASSTHROUGH_PREFIXES ${nameCanon})
|
|
|
|
foreach(prefix ${ARG_PASSTHROUGH_PREFIXES})
|
|
|
|
foreach(variableName ${variableNames})
|
|
|
|
if(variableName MATCHES "^${prefix}")
|
2017-12-05 01:15:18 +01:00
|
|
|
string(REPLACE ";" "|" value "${${variableName}}")
|
2016-06-24 00:07:21 +02:00
|
|
|
list(APPEND PASSTHROUGH_VARIABLES
|
|
|
|
-D${variableName}=${value})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2015-11-11 17:14:03 +01:00
|
|
|
endforeach()
|
|
|
|
|
|
|
|
if(ARG_USE_TOOLCHAIN)
|
|
|
|
if(CLANG_IN_TOOLCHAIN)
|
|
|
|
set(compiler_args -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
|
|
|
|
-DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++)
|
|
|
|
endif()
|
2016-12-13 00:15:10 +01:00
|
|
|
if(llvm-ar IN_LIST TOOLCHAIN_TOOLS)
|
|
|
|
list(APPEND compiler_args -DCMAKE_AR=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ar)
|
|
|
|
endif()
|
|
|
|
if(llvm-ranlib IN_LIST TOOLCHAIN_TOOLS)
|
|
|
|
list(APPEND compiler_args -DCMAKE_RANLIB=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-ranlib)
|
|
|
|
endif()
|
2015-11-11 17:14:03 +01:00
|
|
|
list(APPEND ARG_DEPENDS ${TOOLCHAIN_TOOLS})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${name}-clobber-stamp
|
|
|
|
DEPENDS ${ARG_DEPENDS}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E touch ${BINARY_DIR}/CMakeCache.txt
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E touch ${STAMP_DIR}/${name}-mkdir
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/${name}-clobber-stamp
|
|
|
|
COMMENT "Clobbering bootstrap build and stamp directories"
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_target(${name}-clobber
|
|
|
|
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${name}-clobber-stamp)
|
|
|
|
|
|
|
|
if(ARG_EXCLUDE_FROM_ALL)
|
2016-06-10 00:41:36 +02:00
|
|
|
set(exclude EXCLUDE_FROM_ALL 1)
|
2015-11-11 17:14:03 +01:00
|
|
|
endif()
|
|
|
|
|
2017-12-08 20:42:47 +01:00
|
|
|
if(CMAKE_SYSROOT)
|
|
|
|
set(sysroot_arg -DCMAKE_SYSROOT=${CMAKE_SYSROOT})
|
|
|
|
endif()
|
|
|
|
|
2015-11-11 17:14:03 +01:00
|
|
|
ExternalProject_Add(${name}
|
2016-08-18 23:41:21 +02:00
|
|
|
DEPENDS ${ARG_DEPENDS} llvm-config
|
2015-11-11 17:14:03 +01:00
|
|
|
${name}-clobber
|
|
|
|
PREFIX ${CMAKE_BINARY_DIR}/projects/${name}
|
|
|
|
SOURCE_DIR ${source_dir}
|
|
|
|
STAMP_DIR ${STAMP_DIR}
|
|
|
|
BINARY_DIR ${BINARY_DIR}
|
|
|
|
${exclude}
|
|
|
|
CMAKE_ARGS ${${nameCanon}_CMAKE_ARGS}
|
|
|
|
${compiler_args}
|
|
|
|
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
|
2017-12-08 20:42:47 +01:00
|
|
|
${sysroot_arg}
|
2016-06-24 00:07:21 +02:00
|
|
|
-DLLVM_BINARY_DIR=${PROJECT_BINARY_DIR}
|
|
|
|
-DLLVM_CONFIG_PATH=$<TARGET_FILE:llvm-config>
|
|
|
|
-DLLVM_ENABLE_WERROR=${LLVM_ENABLE_WERROR}
|
2017-11-27 23:50:48 +01:00
|
|
|
-DLLVM_HOST_TRIPLE=${LLVM_HOST_TRIPLE}
|
2016-06-24 00:07:21 +02:00
|
|
|
-DPACKAGE_VERSION=${PACKAGE_VERSION}
|
|
|
|
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
|
|
|
|
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
|
2017-07-21 01:46:46 +02:00
|
|
|
-DCMAKE_EXPORT_COMPILE_COMMANDS=1
|
2015-11-11 17:14:03 +01:00
|
|
|
${ARG_CMAKE_ARGS}
|
|
|
|
${PASSTHROUGH_VARIABLES}
|
|
|
|
INSTALL_COMMAND ""
|
|
|
|
STEP_TARGETS configure build
|
2016-06-10 00:41:36 +02:00
|
|
|
BUILD_ALWAYS 1
|
|
|
|
USES_TERMINAL_CONFIGURE 1
|
|
|
|
USES_TERMINAL_BUILD 1
|
|
|
|
USES_TERMINAL_INSTALL 1
|
2017-12-05 01:15:18 +01:00
|
|
|
LIST_SEPARATOR |
|
2015-11-11 17:14:03 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
if(ARG_USE_TOOLCHAIN)
|
|
|
|
set(force_deps DEPENDS ${TOOLCHAIN_BINS})
|
|
|
|
endif()
|
|
|
|
|
2016-04-09 00:46:04 +02:00
|
|
|
llvm_ExternalProject_BuildCmd(run_clean clean ${BINARY_DIR})
|
2015-11-11 17:14:03 +01:00
|
|
|
ExternalProject_Add_Step(${name} clean
|
|
|
|
COMMAND ${run_clean}
|
|
|
|
COMMENT "Cleaning ${name}..."
|
|
|
|
DEPENDEES configure
|
|
|
|
${force_deps}
|
|
|
|
WORKING_DIRECTORY ${BINARY_DIR}
|
2016-06-24 00:07:21 +02:00
|
|
|
EXCLUDE_FROM_MAIN 1
|
2016-06-10 00:41:36 +02:00
|
|
|
USES_TERMINAL 1
|
2015-11-11 17:14:03 +01:00
|
|
|
)
|
|
|
|
ExternalProject_Add_StepTargets(${name} clean)
|
|
|
|
|
|
|
|
if(ARG_USE_TOOLCHAIN)
|
|
|
|
add_dependencies(${name}-clean ${name}-clobber)
|
|
|
|
set_target_properties(${name}-clean PROPERTIES
|
|
|
|
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/${name}-clobber-stamp)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT ARG_NO_INSTALL)
|
|
|
|
install(CODE "execute_process\(COMMAND \${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=\${CMAKE_INSTALL_PREFIX} -P ${BINARY_DIR}/cmake_install.cmake \)"
|
|
|
|
COMPONENT ${name})
|
|
|
|
|
2017-11-30 22:48:26 +01:00
|
|
|
add_llvm_install_targets(install-${name}
|
|
|
|
DEPENDS ${name}
|
|
|
|
COMPONENT ${name})
|
2015-11-11 17:14:03 +01:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Add top-level targets
|
|
|
|
foreach(target ${ARG_EXTRA_TARGETS})
|
2017-07-12 01:41:15 +02:00
|
|
|
string(REPLACE ":" ";" target_list ${target})
|
|
|
|
list(GET target_list 0 target)
|
|
|
|
list(LENGTH target_list target_list_len)
|
|
|
|
if(${target_list_len} GREATER 1)
|
|
|
|
list(GET target_list 1 target_name)
|
|
|
|
else()
|
|
|
|
set(target_name "${target}")
|
|
|
|
endif()
|
2016-04-09 00:46:04 +02:00
|
|
|
llvm_ExternalProject_BuildCmd(build_runtime_cmd ${target} ${BINARY_DIR})
|
2017-07-12 01:41:15 +02:00
|
|
|
add_custom_target(${target_name}
|
2015-11-11 17:14:03 +01:00
|
|
|
COMMAND ${build_runtime_cmd}
|
|
|
|
DEPENDS ${name}-configure
|
|
|
|
WORKING_DIRECTORY ${BINARY_DIR}
|
|
|
|
VERBATIM
|
2016-06-09 00:19:25 +02:00
|
|
|
USES_TERMINAL)
|
2015-11-11 17:14:03 +01:00
|
|
|
endforeach()
|
|
|
|
endfunction()
|