Skip to content

Commit fe29459

Browse files
committed
Added functionality to find the fuzzer_no_main dependency automatically for custom installations as well
1 parent 831e834 commit fe29459

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

src/advanced_examples/CMakeLists.txt

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
set(OPENSSL_USE_STATIC_LIBS TRUE)
22
find_package(OpenSSL REQUIRED)
3-
#include(libprotobuf-mutator)
43
add_compile_options(-O0)
54

65
add_library(explore_me_advanced
@@ -17,6 +16,36 @@ target_link_libraries(explore_me_advanced
1716
-lz
1817
)
1918

19+
20+
#
21+
# Block defining the location of the fuzzer_no_main library that is needed to compile this example
22+
#
23+
24+
# Uncomment and change to your own path if you want to specify a specific fuzzer_no_main library
25+
#set(FUZZER_NO_MAIN_PATH /usr/lib/clang/${CMAKE_C_COMPILER_VERSION}/lib/linux/libclang_rt.fuzzer_no_main-${CMAKE_SYSTEM_PROCESSOR}.a)
26+
27+
28+
# If location is not manually defined, we search for it.
29+
if (NOT DEFINED FUZZER_NO_MAIN_PATH)
30+
execute_process(COMMAND clang --print-file-name libclang_rt.fuzzer_no_main-${CMAKE_SYSTEM_PROCESSOR}.a
31+
OUTPUT_VARIABLE FUZZER_NO_MAIN_PATH
32+
OUTPUT_STRIP_TRAILING_WHITESPACE
33+
)
34+
35+
# If the first search was not successful, we check if the dependency is there, but does not contain the architecture information
36+
# in its name, as it is common if you compile the sources yourself.
37+
if(NOT ${FUZZER_NO_MAIN_PATH} MATCHES "\/")
38+
execute_process(COMMAND clang --print-file-name libclang_rt.fuzzer_no_main.a
39+
OUTPUT_VARIABLE FUZZER_NO_MAIN_PATH
40+
OUTPUT_STRIP_TRAILING_WHITESPACE
41+
)
42+
endif()
43+
endif()
44+
45+
#
46+
# End of fuzzer_no_main definition
47+
#
48+
2049
foreach(TestType IN ITEMS
2150
structured_input_checks
2251
custom_mutator_example_checks
@@ -31,7 +60,7 @@ foreach(TestType IN ITEMS
3160
)
3261

3362
target_link_libraries(${TestType}_test
34-
/usr/lib/clang/${CMAKE_C_COMPILER_VERSION}/lib/linux/libclang_rt.fuzzer_no_main-${CMAKE_SYSTEM_PROCESSOR}.a
63+
${FUZZER_NO_MAIN_PATH}
3564
explore_me_advanced
3665
GTest::gtest_main
3766
)
@@ -43,7 +72,7 @@ foreach(TestType IN ITEMS
4372
)
4473

4574
target_link_libraries(${TestType}_fuzz_test
46-
/usr/lib/clang/${CMAKE_C_COMPILER_VERSION}/lib/linux/libclang_rt.fuzzer_no_main-${CMAKE_SYSTEM_PROCESSOR}.a
75+
${FUZZER_NO_MAIN_PATH}
4776
explore_me_advanced
4877
GTest::gtest
4978
)

0 commit comments

Comments
 (0)