From 138b7b6167ddc51f2b17f9b38bed493786758c52 Mon Sep 17 00:00:00 2001 From: Sebastian Neubauer Date: Mon, 27 Apr 2020 11:40:31 +0200 Subject: [PATCH] [CMake] Fix cross-compiling with LLVM as CMake subproject When embedding LLVM as a CMake subproject, using cross-compiling does not work at the moment. This also affects -DLLVM_OPTIMIZED_TABLEGEN=1, which uses the same CMake infrastructure. This patch replaces global CMake variables with the current version, which allows cross-compilation to work in a subproject. CMAKE_BINARY_DIR -> CMAKE_CURRENT_BINARY_DIR CMAKE_SOURCE_DIR -> CMAKE_CURRENT_SOURCE_DIR CMAKE_PROJECT_NAME -> PROJECT_NAME Differential Revision: https://reviews.llvm.org/D78913 --- cmake/modules/CrossCompile.cmake | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cmake/modules/CrossCompile.cmake b/cmake/modules/CrossCompile.cmake index 8a6e880c4e2..01cd3712484 100644 --- a/cmake/modules/CrossCompile.cmake +++ b/cmake/modules/CrossCompile.cmake @@ -6,7 +6,7 @@ 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}") + "${CMAKE_CURRENT_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}) @@ -68,7 +68,7 @@ function(llvm_create_cross_target project_name target_name toolchain buildtype) 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_${target_name}} ${CMAKE_CURRENT_SOURCE_DIR} ${CROSS_TOOLCHAIN_FLAGS_${project_name}_${target_name}} -DLLVM_TARGET_IS_CROSSCOMPILE_HOST=TRUE -DLLVM_TARGETS_TO_BUILD="${targets_to_build_arg}" @@ -99,17 +99,17 @@ function(build_native_tool target output_path_var) cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN}) if(CMAKE_CONFIGURATION_TYPES) - set(output_path "${${CMAKE_PROJECT_NAME}_NATIVE_BUILD}/Release/bin/${target}") + set(output_path "${${PROJECT_NAME}_NATIVE_BUILD}/Release/bin/${target}") else() - set(output_path "${${CMAKE_PROJECT_NAME}_NATIVE_BUILD}/bin/${target}") + set(output_path "${${PROJECT_NAME}_NATIVE_BUILD}/bin/${target}") endif() - llvm_ExternalProject_BuildCmd(build_cmd ${target} ${${CMAKE_PROJECT_NAME}_NATIVE_BUILD} + llvm_ExternalProject_BuildCmd(build_cmd ${target} ${${PROJECT_NAME}_NATIVE_BUILD} CONFIGURATION Release) add_custom_command(OUTPUT "${output_path}" COMMAND ${build_cmd} - DEPENDS CONFIGURE_${CMAKE_PROJECT_NAME}_NATIVE ${ARG_DEPENDS} - WORKING_DIRECTORY "${${CMAKE_PROJECT_NAME}_NATIVE_BUILD}" + DEPENDS CONFIGURE_${PROJECT_NAME}_NATIVE ${ARG_DEPENDS} + WORKING_DIRECTORY "${${PROJECT_NAME}_NATIVE_BUILD}" COMMENT "Building native ${target}..." USES_TERMINAL) set(${output_path_var} "${output_path}" PARENT_SCOPE)