llvm.org GIT mirror llvm / 901166c
Enabling LLVM & Clang to be cross-compiled using CMake from a single configuration command line The basic idea is similar to the existing cross compilation support. A directory must be configured to build host versions of tablegen tools and llvm-config. This directory can be user provided (and configured), or it can be created during the build. During a build the native build directory will be configured and built to supply the tablegen tools used during the build. A user could also explicitly provide the tablegen executables to run on the CMake command line. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217105 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Bieneman 5 years ago
5 changed file(s) with 105 addition(s) and 34 deletion(s). Raw diff Collapse all Expand all
469469
470470 include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})
471471
472 # when crosscompiling import the executable targets from a file
473 if(CMAKE_CROSSCOMPILING)
474 include(CrossCompile)
475 endif(CMAKE_CROSSCOMPILING)
476
472477 if( ${CMAKE_SYSTEM_NAME} MATCHES FreeBSD )
473478 # On FreeBSD, /usr/local/* is not used by default. In order to build LLVM
474479 # with libxml2, iconv.h, etc., we must add /usr/local paths.
0 if(NOT DEFINED LLVM_NATIVE_BUILD)
1 set(LLVM_NATIVE_BUILD "${CMAKE_BINARY_DIR}/native")
2 message(STATUS "Setting native build dir to ${LLVM_NATIVE_BUILD}")
3 endif(NOT DEFINED LLVM_NATIVE_BUILD)
4
5 add_custom_command(OUTPUT ${LLVM_NATIVE_BUILD}
6 COMMAND ${CMAKE_COMMAND} -E make_directory ${LLVM_NATIVE_BUILD}
7 COMMENT "Creating ${LLVM_NATIVE_BUILD}...")
8
9 add_custom_command(OUTPUT ${LLVM_NATIVE_BUILD}/CMakeCache.txt
10 COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" ${CMAKE_SOURCE_DIR}
11 WORKING_DIRECTORY ${LLVM_NATIVE_BUILD}
12 DEPENDS ${LLVM_NATIVE_BUILD}
13 COMMENT "Configuring native LLVM...")
14
15 add_custom_target(ConfigureNativeLLVM DEPENDS ${LLVM_NATIVE_BUILD}/CMakeCache.txt)
16
17 set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${LLVM_NATIVE_BUILD})
18
19 if(NOT IS_DIRECTORY ${LLVM_NATIVE_BUILD})
20 if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
21 set(HOST_SYSROOT_FLAGS -DCMAKE_OSX_SYSROOT=macosx)
22 endif(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
23
24 message(STATUS "Configuring native build...")
25 execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory
26 ${LLVM_NATIVE_BUILD} )
27
28 message(STATUS "Configuring native targets...")
29 execute_process(COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Release
30 -G "${CMAKE_GENERATOR}" -DLLVM_TARGETS_TO_BUILD=${LLVM_TARGETS_TO_BUILD} ${HOST_SYSROOT_FLAGS} ${CMAKE_SOURCE_DIR}
31 WORKING_DIRECTORY ${LLVM_NATIVE_BUILD} )
32 endif(NOT IS_DIRECTORY ${LLVM_NATIVE_BUILD})
6969 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} ${target} PARENT_SCOPE)
7070 endfunction()
7171
72 if(CMAKE_CROSSCOMPILING)
73 set(CX_NATIVE_TG_DIR "${CMAKE_BINARY_DIR}/native")
74
75 add_custom_command(OUTPUT ${CX_NATIVE_TG_DIR}
76 COMMAND ${CMAKE_COMMAND} -E make_directory ${CX_NATIVE_TG_DIR}
77 COMMENT "Creating ${CX_NATIVE_TG_DIR}...")
78
79 # Forward a subset of configure options to discover additional tablegen modules.
80 get_cmake_property(_variableNames CACHE_VARIABLES)
81 foreach (_variableName ${_variableNames})
82 if (_variableName MATCHES "^(LLVM_EXTERNAL_.*_SOURCE_DIR)$")
83 list(APPEND CX_CMAKE_ARGUMENTS "-D${_variableName}=\"${${_variableName}}\"")
84 endif ()
85 endforeach()
86
87 add_custom_command(OUTPUT ${CX_NATIVE_TG_DIR}/CMakeCache.txt
88 # TODO: Clear the old CMakeCache.txt somehow without breaking restat.
89 COMMAND ${CMAKE_COMMAND} -UMAKE_TOOLCHAIN_FILE -DCMAKE_BUILD_TYPE=Release
90 -DLLVM_BUILD_POLLY=OFF ${CX_CMAKE_ARGUMENTS}
91 -G "${CMAKE_GENERATOR}" ${CMAKE_SOURCE_DIR}
92 WORKING_DIRECTORY ${CX_NATIVE_TG_DIR}
93 DEPENDS ${CX_NATIVE_TG_DIR}
94 COMMENT "Configuring native TableGen...")
95
96 add_custom_target(ConfigureNativeTableGen DEPENDS ${CX_NATIVE_TG_DIR}/CMakeCache.txt)
97
98 set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CX_NATIVE_TG_DIR})
99 endif()
100
10172 macro(add_tablegen target project)
10273 set(${target}_OLD_LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS})
10374 set(LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS} TableGen)
12192
12293 if(CMAKE_CROSSCOMPILING)
12394 if( ${${project}_TABLEGEN} STREQUAL "${target}" )
124 set(${project}_TABLEGEN_EXE "${CX_NATIVE_TG_DIR}/bin/${target}")
95 set(${project}_TABLEGEN_EXE "${LLVM_NATIVE_BUILD}/bin/${target}")
12596 set(${project}_TABLEGEN_EXE ${${project}_TABLEGEN_EXE} PARENT_SCOPE)
12697
12798 add_custom_command(OUTPUT ${${project}_TABLEGEN_EXE}
128 COMMAND ${CMAKE_BUILD_TOOL} ${target}
129 DEPENDS ${CX_NATIVE_TG_DIR}/CMakeCache.txt
130 WORKING_DIRECTORY ${CX_NATIVE_TG_DIR}
99 COMMAND ${CMAKE_COMMAND} --build . --target ${target} --config $
100 DEPENDS ${LLVM_NATIVE_BUILD}/CMakeCache.txt
101 WORKING_DIRECTORY ${LLVM_NATIVE_BUILD}
131102 COMMENT "Building native TableGen...")
132103 add_custom_target(${project}NativeTableGen DEPENDS ${${project}_TABLEGEN_EXE})
133 add_dependencies(${project}NativeTableGen ConfigureNativeTableGen)
104 add_dependencies(${project}NativeTableGen ConfigureNativeLLVM)
134105
135106 add_dependencies(${target} ${project}NativeTableGen)
136107 endif()
0 # Toolchain config for iOS.
1 #
2 # Usage:
3 # mkdir build; cd build
4 # cmake ..; make
5 # mkdir ios; cd ios
6 # cmake -DLLVM_IOS_TOOLCHAIN_DIR=/path/to/ios/ndk \
7 # -DCMAKE_TOOLCHAIN_FILE=../../cmake/platforms/iOS.cmake ../..
8 # make
9
10 SET(CMAKE_SYSTEM_NAME Darwin)
11 SET(CMAKE_SYSTEM_VERSION 13)
12 SET(CMAKE_CXX_COMPILER_WORKS True)
13 SET(CMAKE_C_COMPILER_WORKS True)
14 SET(DARWIN_TARGET_OS_NAME ios)
15
16 IF(NOT DEFINED ENV{SDKROOT})
17 MESSAGE(FATAL_ERROR "SDKROOT env var must be set: " $ENV{SDKROOT})
18 ENDIF()
19
20 IF(NOT CMAKE_C_COMPILER)
21 execute_process(COMMAND xcrun -sdk iphoneos -find clang
22 OUTPUT_VARIABLE CMAKE_C_COMPILER
23 ERROR_QUIET
24 OUTPUT_STRIP_TRAILING_WHITESPACE)
25 message(STATUS "Using c compiler ${CMAKE_C_COMPILER}")
26 ENDIF()
27
28 IF(NOT CMAKE_CXX_COMPILER)
29 execute_process(COMMAND xcrun -sdk iphoneos -find clang++
30 OUTPUT_VARIABLE CMAKE_CXX_COMPILER
31 ERROR_QUIET
32 OUTPUT_STRIP_TRAILING_WHITESPACE)
33 message(STATUS "Using c compiler ${CMAKE_CXX_COMPILER}")
34 ENDIF()
35
36 IF (NOT DEFINED IOS_MIN_TARGET)
37 execute_process(COMMAND xcodebuild -sdk iphoneos -version SDKVersion
38 OUTPUT_VARIABLE IOS_MIN_TARGET
39 ERROR_QUIET
40 OUTPUT_STRIP_TRAILING_WHITESPACE)
41 ENDIF()
42
43 SET(IOS_COMMON_FLAGS "-isysroot $ENV{SDKROOT} -mios-version-min=${IOS_MIN_TARGET}")
44 SET(CMAKE_C_FLAGS "${IOS_COMMON_FLAGS}" CACHE STRING "toolchain_cflags" FORCE)
45 SET(CMAKE_CXX_FLAGS "${IOS_COMMON_FLAGS}" CACHE STRING "toolchain_cxxflags" FORCE)
46 SET(CMAKE_LINK_FLAGS "${IOS_COMMON_FLAGS}" CACHE STRING "toolchain_linkflags" FORCE)
3232
3333 # Add the dependency on the generation step.
3434 add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/llvm-config.cpp ${BUILDVARIABLES_OBJPATH})
35
36 if(CMAKE_CROSSCOMPILING)
37 set(${project}_LLVM_CONFIG_EXE "${LLVM_NATIVE_BUILD}/bin/llvm-config")
38 set(${project}_LLVM_CONFIG_EXE ${${project}_LLVM_CONFIG_EXE} PARENT_SCOPE)
39
40 add_custom_command(OUTPUT "${${project}_LLVM_CONFIG_EXE}"
41 COMMAND ${CMAKE_COMMAND} --build . --target llvm-config --config $
42 DEPENDS ${LLVM_NATIVE_BUILD}/CMakeCache.txt
43 WORKING_DIRECTORY ${LLVM_NATIVE_BUILD}
44 COMMENT "Building native llvm-config...")
45 add_custom_target(${project}NativeLLVMConfig DEPENDS ${${project}_LLVM_CONFIG_EXE})
46 add_dependencies(${project}NativeLLVMConfig ConfigureNativeLLVM)
47
48 add_dependencies(llvm-config ${project}NativeLLVMConfig)
49 endif(CMAKE_CROSSCOMPILING)