1 function(llvm_create_cross_target_internal target_name toolchain buildtype) 2 3 if(NOT DEFINED LLVM_${target_name}_BUILD) 4 set(LLVM_${target_name}_BUILD "${CMAKE_BINARY_DIR}/${target_name}") 5 set(LLVM_${target_name}_BUILD ${LLVM_${target_name}_BUILD} PARENT_SCOPE) 6 message(STATUS "Setting native build dir to " ${LLVM_${target_name}_BUILD}) 7 endif(NOT DEFINED LLVM_${target_name}_BUILD) 8 9 if (EXISTS ${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake) 10 set(CROSS_TOOLCHAIN_FLAGS_${target_name} 11 -DCMAKE_TOOLCHAIN_FILE=\"${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake\" 12 CACHE STRING "Toolchain file for ${target_name}") 13 endif() 14 15 add_custom_command(OUTPUT ${LLVM_${target_name}_BUILD} 16 COMMAND ${CMAKE_COMMAND} -E make_directory ${LLVM_${target_name}_BUILD} 17 COMMENT "Creating ${LLVM_${target_name}_BUILD}...") 18 19 add_custom_command(OUTPUT ${LLVM_${target_name}_BUILD}/CMakeCache.txt 20 COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" 21 ${CROSS_TOOLCHAIN_FLAGS_${target_name}} ${CMAKE_SOURCE_DIR} 22 -DLLVM_TARGET_IS_CROSSCOMPILE_HOST=TRUE 23 WORKING_DIRECTORY ${LLVM_${target_name}_BUILD} 24 DEPENDS ${LLVM_${target_name}_BUILD} 25 COMMENT "Configuring ${target_name} LLVM...") 26 27 add_custom_target(CONFIGURE_LLVM_${target_name} 28 DEPENDS ${LLVM_${target_name}_BUILD}/CMakeCache.txt) 29 30 set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES 31 ${LLVM_${target_name}_BUILD}) 32 33 if(NOT IS_DIRECTORY ${LLVM_${target_name}_BUILD}) 34 35 36 message(STATUS "Configuring ${target_name} build...") 37 execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory 38 ${LLVM_${target_name}_BUILD} ) 39 40 message(STATUS "Configuring ${target_name} targets...") 41 if (buildtype) 42 set(build_type_flags "-DCMAKE_BUILD_TYPE=${buildtype}") 43 endif() 44 if (LLVM_EXTERNAL_CLANG_SOURCE_DIR) 45 # Propagate LLVM_EXTERNAL_CLANG_SOURCE_DIR so that clang-tblgen can be built 46 set(external_clang_dir "-DLLVM_EXTERNAL_CLANG_SOURCE_DIR=${LLVM_EXTERNAL_CLANG_SOURCE_DIR}") 47 endif() 48 execute_process(COMMAND ${CMAKE_COMMAND} ${build_type_flags} 49 -G "${CMAKE_GENERATOR}" -DLLVM_TARGETS_TO_BUILD=${LLVM_TARGETS_TO_BUILD} 50 ${CROSS_TOOLCHAIN_FLAGS_${target_name}} ${CMAKE_SOURCE_DIR} 51 -DLLVM_TARGET_IS_CROSSCOMPILE_HOST=TRUE 52 ${external_clang_dir} 53 WORKING_DIRECTORY ${LLVM_${target_name}_BUILD} ) 54 endif(NOT IS_DIRECTORY ${LLVM_${target_name}_BUILD}) 55 56 endfunction() 57 58 function(llvm_create_cross_target target_name sysroot) 59 llvm_create_cross_target_internal(${target_name} ${sysroot} ${CMAKE_BUILD_TYPE}) 60 endfunction() 61 62 llvm_create_cross_target_internal(NATIVE "" Release) 63