[llvm] r366514 - [cmake] Convert the NATIVE llvm build process to be project agnostic
Nathan Lanza via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 18 17:10:06 PDT 2019
Author: lanza
Date: Thu Jul 18 17:10:06 2019
New Revision: 366514
URL: http://llvm.org/viewvc/llvm-project?rev=366514&view=rev
Log:
[cmake] Convert the NATIVE llvm build process to be project agnostic
lldb recently added a tablegen tool. In order to properly cross compile
lldb standalone there needs to be a mechanism to generate the native
lldb build, analgous to what's done for the NATIVE llvm build. Thus,
we can simply modify this setup to allow for any project to be used.
Modified:
llvm/trunk/CMakeLists.txt
llvm/trunk/cmake/modules/CrossCompile.cmake
Modified: llvm/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/CMakeLists.txt?rev=366514&r1=366513&r2=366514&view=diff
==============================================================================
--- llvm/trunk/CMakeLists.txt (original)
+++ llvm/trunk/CMakeLists.txt Thu Jul 18 17:10:06 2019
@@ -846,6 +846,7 @@ include_directories( ${LLVM_INCLUDE_DIR}
# when crosscompiling import the executable targets from a file
if(LLVM_USE_HOST_TOOLS)
include(CrossCompile)
+ llvm_create_cross_target(LLVM NATIVE "" Release)
endif(LLVM_USE_HOST_TOOLS)
if(LLVM_TARGET_IS_CROSSCOMPILE_HOST)
# Dummy use to avoid CMake Warning: Manually-specified variables were not used
Modified: llvm/trunk/cmake/modules/CrossCompile.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/CrossCompile.cmake?rev=366514&r1=366513&r2=366514&view=diff
==============================================================================
--- llvm/trunk/cmake/modules/CrossCompile.cmake (original)
+++ llvm/trunk/cmake/modules/CrossCompile.cmake Thu Jul 18 17:10:06 2019
@@ -1,12 +1,15 @@
include(LLVMExternalProjectUtils)
-function(llvm_create_cross_target_internal target_name toolchain buildtype)
- if(NOT DEFINED LLVM_${target_name}_BUILD)
- set(LLVM_${target_name}_BUILD "${CMAKE_BINARY_DIR}/${target_name}")
- set(LLVM_${target_name}_BUILD ${LLVM_${target_name}_BUILD} PARENT_SCOPE)
- message(STATUS "Setting native build dir to " ${LLVM_${target_name}_BUILD})
- endif(NOT DEFINED LLVM_${target_name}_BUILD)
+function(llvm_create_cross_target project_name target_name toolchain buildtype)
+
+ if(NOT DEFINED ${project_name}_${target_name}_BUILD)
+ set(${project_name}_${target_name}_BUILD
+ "${CMAKE_BINARY_DIR}/${target_name}")
+ set(${project_name}_${target_name}_BUILD
+ ${${project_name}_${target_name}_BUILD} PARENT_SCOPE)
+ message(STATUS "Setting native build dir to " ${${project_name}_${target_name}_BUILD})
+ endif(NOT DEFINED ${project_name}_${target_name}_BUILD)
if (EXISTS ${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake)
set(CROSS_TOOLCHAIN_FLAGS_INIT
@@ -20,6 +23,10 @@ function(llvm_create_cross_target_intern
set(CROSS_TOOLCHAIN_FLAGS_${target_name} ${CROSS_TOOLCHAIN_FLAGS_INIT}
CACHE STRING "Toolchain configuration for ${target_name}")
+ # project specific version of the flags up above
+ set(CROSS_TOOLCHAIN_FLAGS_${project_name}_${target_name} ""
+ CACHE STRING "Toolchain configuration for ${Pproject_name}_${target_name}")
+
if (buildtype)
set(build_type_flags "-DCMAKE_BUILD_TYPE=${buildtype}")
endif()
@@ -31,12 +38,12 @@ function(llvm_create_cross_target_intern
set(external_clang_dir "-DLLVM_EXTERNAL_CLANG_SOURCE_DIR=${LLVM_EXTERNAL_CLANG_SOURCE_DIR}")
endif()
- add_custom_command(OUTPUT ${LLVM_${target_name}_BUILD}
- COMMAND ${CMAKE_COMMAND} -E make_directory ${LLVM_${target_name}_BUILD}
- COMMENT "Creating ${LLVM_${target_name}_BUILD}...")
+ add_custom_command(OUTPUT ${${project_name}_${target_name}_BUILD}
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${${project_name}_${target_name}_BUILD}
+ COMMENT "Creating ${${project_name}_${target_name}_BUILD}...")
- add_custom_target(CREATE_LLVM_${target_name}
- DEPENDS ${LLVM_${target_name}_BUILD})
+ add_custom_target(CREATE_${project_name}_${target_name}
+ DEPENDS ${${project_name}_${target_name}_BUILD})
# Escape semicolons in the targets list so that cmake doesn't expand
# them to spaces.
@@ -50,10 +57,11 @@ function(llvm_create_cross_target_intern
string(REPLACE ";" "$<SEMICOLON>" llvm_external_projects_arg
"${LLVM_EXTERNAL_PROJECTS}")
- add_custom_command(OUTPUT ${LLVM_${target_name}_BUILD}/CMakeCache.txt
+ add_custom_command(OUTPUT ${${project_name}_${target_name}_BUILD}/CMakeCache.txt
COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}"
-DCMAKE_MAKE_PROGRAM="${CMAKE_MAKE_PROGRAM}"
${CROSS_TOOLCHAIN_FLAGS_${target_name}} ${CMAKE_SOURCE_DIR}
+ ${CROSS_TOOLCHAIN_FLAGS_${project_name}_${target_name}}
-DLLVM_TARGET_IS_CROSSCOMPILE_HOST=TRUE
-DLLVM_TARGETS_TO_BUILD="${targets_to_build_arg}"
-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="${experimental_targets_to_build_arg}"
@@ -63,19 +71,16 @@ function(llvm_create_cross_target_intern
-DLLVM_EXTERNAL_PROJECTS="${llvm_external_projects_arg}"
-DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN="${LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN}"
${build_type_flags} ${linker_flag} ${external_clang_dir}
- WORKING_DIRECTORY ${LLVM_${target_name}_BUILD}
- DEPENDS CREATE_LLVM_${target_name}
- COMMENT "Configuring ${target_name} LLVM...")
+ ${ARGN}
+ WORKING_DIRECTORY ${${project_name}_${target_name}_BUILD}
+ DEPENDS CREATE_${project_name}_${target_name}
+ COMMENT "Configuring ${target_name} ${project_name}...")
- add_custom_target(CONFIGURE_LLVM_${target_name}
- DEPENDS ${LLVM_${target_name}_BUILD}/CMakeCache.txt)
+ add_custom_target(CONFIGURE_${project_name}_${target_name}
+ DEPENDS ${${project_name}_${target_name}_BUILD}/CMakeCache.txt)
endfunction()
-function(llvm_create_cross_target target_name sysroot)
- llvm_create_cross_target_internal(${target_name} ${sysroot} ${CMAKE_BUILD_TYPE})
-endfunction()
-
# Sets up a native build for a tool, used e.g. for cross-compilation and
# LLVM_OPTIMIZED_TABLEGEN. Always builds in Release.
# - target: The target to build natively
@@ -85,20 +90,18 @@ function(build_native_tool target output
cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN})
if(CMAKE_CONFIGURATION_TYPES)
- set(output_path "${LLVM_NATIVE_BUILD}/Release/bin/${target}")
+ set(output_path "${${CMAKE_PROJECT_NAME}_NATIVE_BUILD}/Release/bin/${target}")
else()
- set(output_path "${LLVM_NATIVE_BUILD}/bin/${target}")
+ set(output_path "${${CMAKE_PROJECT_NAME}_NATIVE_BUILD}/bin/${target}")
endif()
- llvm_ExternalProject_BuildCmd(build_cmd ${target} ${LLVM_NATIVE_BUILD}
+ llvm_ExternalProject_BuildCmd(build_cmd ${target} ${${CMAKE_PROJECT_NAME}_NATIVE_BUILD}
CONFIGURATION Release)
add_custom_command(OUTPUT "${output_path}"
COMMAND ${build_cmd}
- DEPENDS CONFIGURE_LLVM_NATIVE ${ARG_DEPENDS}
- WORKING_DIRECTORY "${LLVM_NATIVE_BUILD}"
+ DEPENDS CONFIGURE_${CMAKE_PROJECT_NAME}_NATIVE ${ARG_DEPENDS}
+ WORKING_DIRECTORY "${${CMAKE_PROJECT_NAME}_NATIVE_BUILD}"
COMMENT "Building native ${target}..."
USES_TERMINAL)
set(${output_path_var} "${output_path}" PARENT_SCOPE)
endfunction()
-
-llvm_create_cross_target_internal(NATIVE "" Release)
More information about the llvm-commits
mailing list