From bb9c221f2a28f90f3ca20f657424d3ff05fcbbd3 Mon Sep 17 00:00:00 2001 From: Oscar Fuentes Date: Sun, 9 Nov 2008 18:53:19 +0000 Subject: [PATCH] CMake: Support for cross-compiling. For now, requires a previously built native tblgen which is passed to cmake in the variable LLVM_TABLEGEN. See http://www.cmake.org/Wiki/CmakeMingw for a quick example on how to cross-compile with CMake. llvm-svn: 58939 --- CMakeLists.txt | 9 ++++++++- cmake/modules/AddPartiallyLinkedObject.cmake | 2 +- cmake/modules/CrossCompileLLVM.cmake | 6 ++++++ cmake/modules/TableGen.cmake | 2 +- tools/llvm-config/CMakeLists.txt | 10 +++++++++- tools/llvmc2/driver/CMakeLists.txt | 2 +- 6 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 cmake/modules/CrossCompileLLVM.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c013327720..f634503b453 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -111,10 +111,17 @@ add_subdirectory(lib/System) # Everything else depends on Support and System: set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} ${LLVM_LIBS} ) +set(LLVM_TABLEGEN "tblgen" CACHE + STRING "Native TableGen executable.") + +if( CMAKE_CROSSCOMPILING ) + include( CrossCompileLLVM ) +endif( CMAKE_CROSSCOMPILING ) + add_subdirectory(utils/TableGen) add_custom_command(OUTPUT ${llvm_builded_incs_dir}/Intrinsics.gen - COMMAND tblgen -gen-intrinsic -I ${LLVM_MAIN_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR}/llvm/Intrinsics.td -o ${llvm_builded_incs_dir}/Intrinsics.gen + COMMAND ${LLVM_TABLEGEN} -gen-intrinsic -I ${LLVM_MAIN_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR}/llvm/Intrinsics.td -o ${llvm_builded_incs_dir}/Intrinsics.gen DEPENDS tblgen COMMENT "Building intrinsics.gen...") diff --git a/cmake/modules/AddPartiallyLinkedObject.cmake b/cmake/modules/AddPartiallyLinkedObject.cmake index 4da8eac3f29..d607306dfe2 100755 --- a/cmake/modules/AddPartiallyLinkedObject.cmake +++ b/cmake/modules/AddPartiallyLinkedObject.cmake @@ -24,7 +24,7 @@ macro(add_partially_linked_object lib) DEPENDS ${lib} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/temp_lib COMMAND ar x ${CMAKE_STATIC_LIBRARY_PREFIX}${lib}${CMAKE_STATIC_LIBRARY_SUFFIX} - COMMAND ld "${LLVM_PLO_FLAGS}" -r "*${CMAKE_CXX_OUTPUT_EXTENSION}" -o ${pll} + COMMAND ${CMAKE_LINKER} "${LLVM_PLO_FLAGS}" -r "*${CMAKE_CXX_OUTPUT_EXTENSION}" -o ${pll} COMMAND rm -f *${CMAKE_CXX_OUTPUT_EXTENSION} ) target_name_of_partially_linked_object(${lib} tnplo) diff --git a/cmake/modules/CrossCompileLLVM.cmake b/cmake/modules/CrossCompileLLVM.cmake new file mode 100644 index 00000000000..0377c056142 --- /dev/null +++ b/cmake/modules/CrossCompileLLVM.cmake @@ -0,0 +1,6 @@ +# TODO: Build a native tblgen when cross-compiling, if the user +# didn't set LLVM_TABLEGEN. Then, remove this check: +if( CMAKE_CROSSCOMPILING AND ${LLVM_TABLEGEN} STREQUAL "tblgen" ) + message(FATAL_ERROR + "Set LLVM_TABLEGEN to the full route to a native tblgen executable") +endif() diff --git a/cmake/modules/TableGen.cmake b/cmake/modules/TableGen.cmake index c332ed1ac48..6d69e8ae912 100644 --- a/cmake/modules/TableGen.cmake +++ b/cmake/modules/TableGen.cmake @@ -4,7 +4,7 @@ macro(tablegen ofn) add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${ofn} - COMMAND tblgen ${ARGN} -I ${CMAKE_CURRENT_SOURCE_DIR} -I ${CMAKE_SOURCE_DIR}/lib/Target -I ${LLVM_MAIN_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${LLVM_TARGET_DEFINITIONS} -o ${ofn} + COMMAND ${LLVM_TABLEGEN} ${ARGN} -I ${CMAKE_CURRENT_SOURCE_DIR} -I ${CMAKE_SOURCE_DIR}/lib/Target -I ${LLVM_MAIN_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${LLVM_TARGET_DEFINITIONS} -o ${ofn} DEPENDS tblgen ${CMAKE_CURRENT_SOURCE_DIR}/${LLVM_TARGET_DEFINITIONS} COMMENT "Building ${ofn}..." ) diff --git a/tools/llvm-config/CMakeLists.txt b/tools/llvm-config/CMakeLists.txt index b5551bb132e..9f1f2f2d311 100644 --- a/tools/llvm-config/CMakeLists.txt +++ b/tools/llvm-config/CMakeLists.txt @@ -63,8 +63,16 @@ set(LLVM_CONFIG_IN ${CMAKE_CURRENT_BINARY_DIR}/llvm-config.in) # set(LIBDEPS_TMP LibDeps.txt.tmp) # set(FINAL_LIBDEPS FinalLibDeps.txt) +if( CMAKE_CROSSCOMPILING ) + set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) +endif() + +if( NOT NM_PATH ) + message(FATAL_ERROR "`nm' was not found") +endif() + add_custom_command(OUTPUT ${LIBDEPS_TMP} - COMMAND ${PERL_EXECUTABLE} ${LLVM_MAIN_SRC_DIR}/utils/GenLibDeps.pl -flat ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY} > ${LIBDEPS_TMP} + COMMAND ${PERL_EXECUTABLE} ${LLVM_MAIN_SRC_DIR}/utils/GenLibDeps.pl -flat ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY} ${NM_PATH} > ${LIBDEPS_TMP} COMMENT "Regenerating ${LIBDEPS_TMP}") add_custom_command(OUTPUT ${LIBDEPS} diff --git a/tools/llvmc2/driver/CMakeLists.txt b/tools/llvmc2/driver/CMakeLists.txt index 538f8974a37..6a7a2a8f011 100644 --- a/tools/llvmc2/driver/CMakeLists.txt +++ b/tools/llvmc2/driver/CMakeLists.txt @@ -3,7 +3,7 @@ set(LLVM_REQUIRES_EH 1) macro(tgen ofn) add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${ofn} - COMMAND tblgen ${ARGN} -I ${CMAKE_CURRENT_SOURCE_DIR} -I ${CMAKE_SOURCE_DIR}/lib/Target -I ${LLVM_MAIN_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/Graph.td -o ${ofn} + COMMAND ${LLVM_TABLEGEN} ${ARGN} -I ${CMAKE_CURRENT_SOURCE_DIR} -I ${CMAKE_SOURCE_DIR}/lib/Target -I ${LLVM_MAIN_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/Graph.td -o ${ofn} DEPENDS tblgen ${LLVM_MAIN_INCLUDE_DIR}/llvm/CompilerDriver/Common.td