Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
14 | pmbaty | 1 | include(AddLLVM) |
2 | include(LLVMExternalProjectUtils) |
||
3 | |||
4 | |||
5 | function(llvm_create_cross_target project_name target_name toolchain buildtype) |
||
6 | |||
7 | if(NOT DEFINED ${project_name}_${target_name}_BUILD) |
||
8 | set(${project_name}_${target_name}_BUILD |
||
9 | "${CMAKE_CURRENT_BINARY_DIR}/${target_name}") |
||
10 | set(${project_name}_${target_name}_BUILD |
||
11 | ${${project_name}_${target_name}_BUILD} PARENT_SCOPE) |
||
12 | message(STATUS "Setting native build dir to " ${${project_name}_${target_name}_BUILD}) |
||
13 | endif(NOT DEFINED ${project_name}_${target_name}_BUILD) |
||
14 | |||
15 | if (EXISTS ${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake) |
||
16 | set(CROSS_TOOLCHAIN_FLAGS_INIT |
||
17 | -DCMAKE_TOOLCHAIN_FILE=\"${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake\") |
||
18 | elseif (NOT CMAKE_CROSSCOMPILING) |
||
19 | set(CROSS_TOOLCHAIN_FLAGS_INIT |
||
20 | -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} |
||
21 | -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} |
||
22 | ) |
||
23 | endif() |
||
24 | set(CROSS_TOOLCHAIN_FLAGS_${target_name} ${CROSS_TOOLCHAIN_FLAGS_INIT} |
||
25 | CACHE STRING "Toolchain configuration for ${target_name}") |
||
26 | |||
27 | # project specific version of the flags up above |
||
28 | set(CROSS_TOOLCHAIN_FLAGS_${project_name}_${target_name} "" |
||
29 | CACHE STRING "Toolchain configuration for ${project_name}_${target_name}") |
||
30 | |||
31 | if (buildtype) |
||
32 | set(build_type_flags "-DCMAKE_BUILD_TYPE=${buildtype}") |
||
33 | endif() |
||
34 | if (LLVM_USE_LINKER AND NOT CMAKE_CROSSCOMPILING) |
||
35 | set(linker_flag "-DLLVM_USE_LINKER=${LLVM_USE_LINKER}") |
||
36 | endif() |
||
37 | if (LLVM_EXTERNAL_CLANG_SOURCE_DIR) |
||
38 | # Propagate LLVM_EXTERNAL_CLANG_SOURCE_DIR so that clang-tblgen can be built |
||
39 | set(external_clang_dir "-DLLVM_EXTERNAL_CLANG_SOURCE_DIR=${LLVM_EXTERNAL_CLANG_SOURCE_DIR}") |
||
40 | endif() |
||
41 | |||
42 | add_custom_command(OUTPUT ${${project_name}_${target_name}_BUILD} |
||
43 | COMMAND ${CMAKE_COMMAND} -E make_directory ${${project_name}_${target_name}_BUILD} |
||
44 | COMMENT "Creating ${${project_name}_${target_name}_BUILD}...") |
||
45 | |||
46 | add_custom_target(CREATE_${project_name}_${target_name} |
||
47 | DEPENDS ${${project_name}_${target_name}_BUILD}) |
||
48 | |||
49 | # Escape semicolons in the targets list so that cmake doesn't expand |
||
50 | # them to spaces. |
||
51 | string(REPLACE ";" "$<SEMICOLON>" targets_to_build_arg |
||
52 | "${LLVM_TARGETS_TO_BUILD}") |
||
53 | string(REPLACE ";" "$<SEMICOLON>" experimental_targets_to_build_arg |
||
54 | "${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD}") |
||
55 | |||
56 | string(REPLACE ";" "$<SEMICOLON>" llvm_enable_projects_arg |
||
57 | "${LLVM_ENABLE_PROJECTS}") |
||
58 | string(REPLACE ";" "$<SEMICOLON>" llvm_external_projects_arg |
||
59 | "${LLVM_EXTERNAL_PROJECTS}") |
||
60 | string(REPLACE ";" "$<SEMICOLON>" llvm_enable_runtimes_arg |
||
61 | "${LLVM_ENABLE_RUNTIMES}") |
||
62 | |||
63 | set(external_project_source_dirs) |
||
64 | foreach(project ${LLVM_EXTERNAL_PROJECTS}) |
||
65 | canonicalize_tool_name(${project} name) |
||
66 | list(APPEND external_project_source_dirs |
||
67 | "-DLLVM_EXTERNAL_${name}_SOURCE_DIR=${LLVM_EXTERNAL_${name}_SOURCE_DIR}") |
||
68 | endforeach() |
||
69 | |||
70 | add_custom_command(OUTPUT ${${project_name}_${target_name}_BUILD}/CMakeCache.txt |
||
71 | COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" |
||
72 | -DCMAKE_MAKE_PROGRAM="${CMAKE_MAKE_PROGRAM}" |
||
73 | -DCMAKE_C_COMPILER_LAUNCHER="${CMAKE_C_COMPILER_LAUNCHER}" |
||
74 | -DCMAKE_CXX_COMPILER_LAUNCHER="${CMAKE_CXX_COMPILER_LAUNCHER}" |
||
75 | ${CROSS_TOOLCHAIN_FLAGS_${target_name}} ${CMAKE_CURRENT_SOURCE_DIR} |
||
76 | ${CROSS_TOOLCHAIN_FLAGS_${project_name}_${target_name}} |
||
77 | -DLLVM_TARGET_IS_CROSSCOMPILE_HOST=TRUE |
||
78 | -DLLVM_TARGETS_TO_BUILD="${targets_to_build_arg}" |
||
79 | -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="${experimental_targets_to_build_arg}" |
||
80 | -DLLVM_DEFAULT_TARGET_TRIPLE="${LLVM_TARGET_TRIPLE}" |
||
81 | -DLLVM_TARGET_ARCH="${LLVM_TARGET_ARCH}" |
||
82 | -DLLVM_ENABLE_PROJECTS="${llvm_enable_projects_arg}" |
||
83 | -DLLVM_EXTERNAL_PROJECTS="${llvm_external_projects_arg}" |
||
84 | -DLLVM_ENABLE_RUNTIMES="${llvm_enable_runtimes_arg}" |
||
85 | ${external_project_source_dirs} |
||
86 | -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN="${LLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN}" |
||
87 | -DLLVM_INCLUDE_BENCHMARKS=OFF |
||
88 | -DLLVM_INCLUDE_TESTS=OFF |
||
89 | ${build_type_flags} ${linker_flag} ${external_clang_dir} |
||
90 | ${ARGN} |
||
91 | WORKING_DIRECTORY ${${project_name}_${target_name}_BUILD} |
||
92 | DEPENDS CREATE_${project_name}_${target_name} |
||
93 | COMMENT "Configuring ${target_name} ${project_name}...") |
||
94 | |||
95 | add_custom_target(CONFIGURE_${project_name}_${target_name} |
||
96 | DEPENDS ${${project_name}_${target_name}_BUILD}/CMakeCache.txt) |
||
97 | |||
98 | endfunction() |
||
99 | |||
100 | # Sets up a native build for a tool, used e.g. for cross-compilation and |
||
101 | # LLVM_OPTIMIZED_TABLEGEN. Always builds in Release. |
||
102 | # - target: The target to build natively |
||
103 | # - output_path_var: A variable name which receives the path to the built target |
||
104 | # - DEPENDS: Any additional dependencies for the target |
||
105 | function(build_native_tool target output_path_var) |
||
106 | cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN}) |
||
107 | |||
108 | if(CMAKE_CONFIGURATION_TYPES) |
||
109 | set(output_path "${${PROJECT_NAME}_NATIVE_BUILD}/Release/bin/${target}") |
||
110 | else() |
||
111 | set(output_path "${${PROJECT_NAME}_NATIVE_BUILD}/bin/${target}") |
||
112 | endif() |
||
113 | set(output_path ${output_path}${LLVM_HOST_EXECUTABLE_SUFFIX}) |
||
114 | |||
115 | llvm_ExternalProject_BuildCmd(build_cmd ${target} ${${PROJECT_NAME}_NATIVE_BUILD} |
||
116 | CONFIGURATION Release) |
||
117 | add_custom_command(OUTPUT "${output_path}" |
||
118 | COMMAND ${build_cmd} |
||
119 | DEPENDS CONFIGURE_${PROJECT_NAME}_NATIVE ${ARG_DEPENDS} |
||
120 | WORKING_DIRECTORY "${${PROJECT_NAME}_NATIVE_BUILD}" |
||
121 | COMMENT "Building native ${target}..." |
||
122 | USES_TERMINAL) |
||
123 | set(${output_path_var} "${output_path}" PARENT_SCOPE) |
||
124 | endfunction() |