forked from onnx/onnx-mlir
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
51 lines (42 loc) · 1.94 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# SPDX-License-Identifier: Apache-2.0
# We would like the VCSVersion.inc file to contain both the llvm and onnx-mlir
# git revision. This is trivial for onnx-mlir, however, we cannot guarantee
# that we will have access to the llvm source. If the source directory exists,
# we attempt to use it to get the version. Otherwise, we rely on LLVM_APPEND_VC_REV
# and VCSRevision.h.
set(version_inc "${ONNX_MLIR_BIN_ROOT}/VCSVersion.inc")
set(generate_vcs_version_script "${LLVM_CMAKE_DIR}/GenerateVersionFromVCS.cmake")
set(vcs_depends "${generate_vcs_version_script}")
find_first_existing_vc_file("${ONNX_MLIR_SRC_ROOT}" onnx_mlir_vc)
list(APPEND vcs_depends "${onnx_mlir_vc}")
list(APPEND vcs_generate_commands
COMMAND ${CMAKE_COMMAND} [[-DNAMES="LLVM\;ONNX_MLIR"]]
"-DLLVM_SOURCE_DIR=${LLVM_BUILD_MAIN_SRC_DIR}"
"-DONNX_MLIR_SOURCE_DIR=${ONNX_MLIR_SRC_ROOT}"
"-DHEADER_FILE=${version_inc}.tmp"
-P "${generate_vcs_version_script}"
)
find_first_existing_vc_file("${LLVM_BUILD_MAIN_SRC_DIR}" llvm_vc)
if (llvm_vc)
list(APPEND vcs_depends "${llvm_vc}")
elseif (LLVM_APPEND_VC_REV)
set(add_llvm_version_header_script "${CMAKE_CURRENT_SOURCE_DIR}/AddLLVMVersionHeader.cmake")
list(APPEND vcs_depends "${add_llvm_version_header_script}")
list(APPEND vcs_generate_commands
COMMAND ${CMAKE_COMMAND} "-DHEADER_FILE=${version_inc}.tmp"
-P "${add_llvm_version_header_script}"
)
endif()
list(APPEND vcs_generate_commands
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${version_inc}.tmp" "${version_inc}"
COMMAND ${CMAKE_COMMAND} -E remove "${version_inc}.tmp"
)
add_custom_command(OUTPUT "${version_inc}"
DEPENDS "${vcs_depends}"
${vcs_generate_commands}
)
set_source_files_properties("${version_inc}"
PROPERTIES GENERATED TRUE
HEADER_FILE_ONLY TRUE
)
add_custom_target(OMVersion ALL DEPENDS ${version_inc})