Skip to content

Commit dafad1d

Browse files
committed
exclude clang-foramt by default, turns out it doesn't work (or needs some setup) /Arek
1 parent 44f3ed7 commit dafad1d

1 file changed

Lines changed: 64 additions & 44 deletions

File tree

cmake/modules/HCT.cmake

Lines changed: 64 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,43 @@ mark_as_advanced(HLSL_DISABLE_SOURCE_GENERATION)
44

55
add_custom_target(HCTGen)
66

7-
find_program(CLANG_FORMAT_EXE NAMES clang-format)
7+
option(DXC_WITH_CLANG_FORMAT "Request build with Clang-Format" OFF)
88

9-
if (NOT CLANG_FORMAT_EXE)
9+
if(DXC_WITH_CLANG_FORMAT)
10+
find_program(CLANG_FORMAT_EXE NAMES clang-format)
11+
else()
12+
unset(CLANG_FORMAT_EXE)
13+
unset(CACHE{CLANG_FORMAT_EXE})
14+
endif()
15+
16+
if(NOT CLANG_FORMAT_EXE)
1017
message(WARNING "Clang-format is not available. Generating included sources is not supported.")
11-
if (HLSL_COPY_GENERATED_SOURCES)
18+
19+
if(HLSL_COPY_GENERATED_SOURCES)
1220
message(FATAL_ERROR "Generating sources requires clang-format")
13-
endif ()
14-
endif ()
21+
endif()
22+
endif()
1523

16-
if (WIN32 AND NOT DEFINED HLSL_AUTOCRLF)
24+
if(WIN32 AND NOT DEFINED HLSL_AUTOCRLF)
1725
find_program(git_executable NAMES git git.exe git.cmd)
1826
execute_process(COMMAND ${git_executable} config --get core.autocrlf
19-
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
20-
TIMEOUT 5
21-
RESULT_VARIABLE result
22-
OUTPUT_VARIABLE output
23-
OUTPUT_STRIP_TRAILING_WHITESPACE)
24-
if( result EQUAL 0 )
27+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
28+
TIMEOUT 5
29+
RESULT_VARIABLE result
30+
OUTPUT_VARIABLE output
31+
OUTPUT_STRIP_TRAILING_WHITESPACE)
32+
33+
if(result EQUAL 0)
2534
# This is a little counterintuitive... Because the repo's gitattributes set
2635
# text=auto, autocrlf behavior will be enabled for autocrlf true or false.
2736
# For reasons unknown to me, autocrlf=input overrides the gitattributes, so
2837
# that is the case we need special handling for.
2938
set(val On)
30-
if (output STREQUAL "input")
39+
40+
if(output STREQUAL "input")
3141
set(val Off)
3242
endif()
43+
3344
set(HLSL_AUTOCRLF ${val} CACHE BOOL "Is core.autocrlf enabled in this clone")
3445
message(STATUS "Git checkout autocrlf: ${HLSL_AUTOCRLF}")
3546
endif()
@@ -42,50 +53,56 @@ function(add_hlsl_hctgen mode)
4253
""
4354
${ARGN})
4455

45-
if (NOT ARG_OUTPUT)
56+
if(NOT ARG_OUTPUT)
4657
message(FATAL_ERROR "add_hlsl_hctgen requires OUTPUT argument")
4758
endif()
4859

49-
if (HLSL_DISABLE_SOURCE_GENERATION AND NOT ARG_BUILD_DIR)
60+
if(HLSL_DISABLE_SOURCE_GENERATION AND NOT ARG_BUILD_DIR)
5061
return()
5162
endif()
52-
63+
5364
set(temp_output ${CMAKE_CURRENT_BINARY_DIR}/tmp/${ARG_OUTPUT})
5465
set(full_output ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_OUTPUT})
55-
if (ARG_BUILD_DIR)
66+
67+
if(ARG_BUILD_DIR)
5668
set(full_output ${CMAKE_CURRENT_BINARY_DIR}/${ARG_OUTPUT})
5769
endif()
70+
5871
set(hctgen ${LLVM_SOURCE_DIR}/utils/hct/hctgen.py)
5972
set(hctdb ${LLVM_SOURCE_DIR}/utils/hct/hctdb.py)
6073
set(hctdb_helper ${LLVM_SOURCE_DIR}/utils/hct/hctdb_instrhelp.py)
6174
set(output ${full_output})
6275
set(hct_dependencies ${LLVM_SOURCE_DIR}/utils/hct/gen_intrin_main.txt
63-
${hctgen}
64-
${hctdb}
65-
${hctdb_helper})
76+
${hctgen}
77+
${hctdb}
78+
${hctdb_helper})
6679

6780
get_filename_component(output_extension ${full_output} LAST_EXT)
6881

69-
if (CLANG_FORMAT_EXE AND output_extension MATCHES "\.h|\.cpp|\.inl")
82+
if(CLANG_FORMAT_EXE AND output_extension MATCHES "\.h|\.cpp|\.inl")
7083
set(format_cmd COMMAND ${CLANG_FORMAT_EXE} -i ${temp_output})
71-
endif ()
84+
endif()
7285

7386
set(copy_sources Off)
87+
7488
if(ARG_BUILD_DIR OR HLSL_COPY_GENERATED_SOURCES)
7589
set(copy_sources On)
7690
endif()
7791

7892
if(ARG_CODE_TAG)
7993
set(input_flag --input ${full_output})
80-
if (UNIX)
94+
95+
if(UNIX)
8196
execute_process(COMMAND file ${full_output} OUTPUT_VARIABLE output)
82-
if (output MATCHES ".*, with CRLF line terminators")
97+
98+
if(output MATCHES ".*, with CRLF line terminators")
8399
set(force_lf "--force-crlf")
84100
endif()
85101
endif()
86102

87103
list(APPEND hct_dependencies ${full_output})
88-
if (HLSL_COPY_GENERATED_SOURCES)
104+
105+
if(HLSL_COPY_GENERATED_SOURCES)
89106
# The generation command both depends on and produces the final output if
90107
# source copying is enabled for CODE_TAG sources. That means we need to
91108
# create an extra temporary to key the copy step on.
@@ -98,40 +115,43 @@ function(add_hlsl_hctgen mode)
98115
# file, and define the verification command
99116
if(NOT copy_sources)
100117
set(output ${temp_output})
101-
if (CLANG_FORMAT_EXE) # Only verify sources if clang-format is available.
118+
119+
if(CLANG_FORMAT_EXE) # Only verify sources if clang-format is available.
102120
set(verification COMMAND ${CMAKE_COMMAND} -E compare_files ${temp_output} ${full_output})
103121
endif()
104122
endif()
123+
105124
if(WIN32 AND NOT HLSL_AUTOCRLF)
106125
set(force_lf "--force-lf")
107126
endif()
108127

109128
add_custom_command(OUTPUT ${temp_output}
110-
COMMAND ${Python3_EXECUTABLE}
111-
${hctgen} ${force_lf}
112-
${mode} --output ${temp_output} ${input_flag}
113-
${format_cmd}
114-
COMMENT "Building ${ARG_OUTPUT}..."
115-
DEPENDS ${hct_dependencies}
116-
)
129+
COMMAND ${Python3_EXECUTABLE}
130+
${hctgen} ${force_lf}
131+
${mode} --output ${temp_output} ${input_flag}
132+
${format_cmd}
133+
COMMENT "Building ${ARG_OUTPUT}..."
134+
DEPENDS ${hct_dependencies}
135+
)
136+
117137
if(copy_sources)
118138
add_custom_command(OUTPUT ${output}
119-
COMMAND ${CMAKE_COMMAND} -E copy_if_different
120-
${temp_output} ${full_output}
121-
${second_copy}
122-
DEPENDS ${temp_output}
123-
COMMENT "Updating ${ARG_OUTPUT}..."
124-
)
139+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
140+
${temp_output} ${full_output}
141+
${second_copy}
142+
DEPENDS ${temp_output}
143+
COMMENT "Updating ${ARG_OUTPUT}..."
144+
)
125145
endif()
126146

127147
add_custom_command(OUTPUT ${temp_output}.stamp
128-
COMMAND ${verification}
129-
COMMAND ${CMAKE_COMMAND} -E touch ${temp_output}.stamp
130-
DEPENDS ${output}
131-
COMMENT "Verifying clang-format results...")
148+
COMMAND ${verification}
149+
COMMAND ${CMAKE_COMMAND} -E touch ${temp_output}.stamp
150+
DEPENDS ${output}
151+
COMMENT "Verifying clang-format results...")
132152

133153
add_custom_target(${mode}
134-
DEPENDS ${temp_output}.stamp)
154+
DEPENDS ${temp_output}.stamp)
135155

136156
add_dependencies(HCTGen ${mode})
137157
endfunction()

0 commit comments

Comments
 (0)