Skip to content

Commit a27c5c2

Browse files
authored
Merge pull request #16418 from gottesmm/pr-b23c7eeda516c09fc5dd67c889c7adc1efef3e2a
[cmake] Cleanup the cmake used for adding new fuzzer host tools.
2 parents f421ec6 + 5e53730 commit a27c5c2

File tree

2 files changed

+13
-32
lines changed

2 files changed

+13
-32
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,37 +2316,18 @@ function(add_swift_host_tool executable)
23162316
endif()
23172317
endfunction()
23182318

2319-
macro(add_swift_fuzz_tool executable)
2320-
cmake_parse_arguments(
2321-
ADDSWIFTHOSTTOOL # prefix
2322-
"" # options
2323-
"" # single-value args
2324-
"SWIFT_COMPONENT" # multi-value args
2325-
${ARGN})
2326-
2327-
# Create the executable rule.
2328-
add_swift_executable(${executable} ${ADDSWIFTHOSTTOOL_UNPARSED_ARGUMENTS})
2329-
2330-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=fuzzer")
2331-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=fuzzer")
2332-
set(LINK_FLAGS "${LINK_FLAGS} -fsanitize=fuzzer")
2333-
2334-
# And then create the install rule if we are asked to.
2335-
if (ADDSWIFTHOSTTOOL_SWIFT_COMPONENT)
2336-
swift_install_in_component(${ADDSWIFTHOSTTOOL_SWIFT_COMPONENT}
2337-
TARGETS ${executable}
2338-
RUNTIME DESTINATION bin)
2339-
2340-
swift_is_installing_component(${ADDSWIFTHOSTTOOL_SWIFT_COMPONENT}
2341-
is_installing)
2342-
2343-
if(NOT is_installing)
2344-
set_property(GLOBAL APPEND PROPERTY SWIFT_BUILDTREE_EXPORTS ${executable})
2345-
else()
2346-
set_property(GLOBAL APPEND PROPERTY SWIFT_EXPORTS ${executable})
2347-
endif()
2348-
endif()
2349-
endmacro()
2319+
# This declares a swift host tool that links with libfuzzer.
2320+
function(add_swift_fuzzer_host_tool executable)
2321+
# First create our target. We do not actually parse the argument since we do
2322+
# not care about the arguments, we just pass them all through to
2323+
# add_swift_host_tool.
2324+
add_swift_host_tool(${executable} ${ARGN})
2325+
2326+
# Then make sure that we pass the -fsanitize=fuzzer flag both on the cflags
2327+
# and cxx flags line.
2328+
target_compile_options(${executable} PRIVATE "-fsanitize=fuzzer")
2329+
target_link_libraries(${executable} PRIVATE "-fsanitize=fuzzer")
2330+
endfunction()
23502331

23512332
macro(add_swift_tool_symlink name dest component)
23522333
add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE)

tools/swift-demangle-fuzzer/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
add_swift_fuzz_tool(swift-demangle-fuzzer
1+
add_swift_fuzzer_host_tool(swift-demangle-fuzzer
22
swift-demangle-fuzzer.cpp
33
LINK_LIBRARIES swiftDemangling
44
LLVM_COMPONENT_DEPENDS support

0 commit comments

Comments
 (0)