Skip to content

Commit 8b51fc2

Browse files
committed
build: do not intrude upon the sanctity of the user flags
`CMAKE_C_FLAGS` should not be altered by the build configuration. Use `add_compile_options`. Hoist the flags to the global level as these are used globally. Support alternate C++ runtimes by using the C++ driver rather than the C driver and specifying the C++ runtime by name. This also fixes the bug where the C++ runtime library dependencies are missed.
1 parent 32f0f77 commit 8b51fc2

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ add_compile_definitions(CMARK_USE_CMAKE_HEADERS)
7878

7979
option(CMARK_FUZZ_QUADRATIC "Build quadratic fuzzing harness" OFF)
8080

81+
if(CMARK_LIB_FUZZER)
82+
add_compile_options($<$<COMPILE_LANGUAGE:C>:-fsanitize-coverage=trace-pc-guard>)
83+
endif()
84+
8185
if(CMARK_FUZZ_QUADRATIC)
8286
# FIXME(compnerd) why do we enable debug information?
8387
add_compile_options($<$<COMPILE_LANGUAGE:C>:-g>)

src/CMakeLists.txt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,10 @@ CONFIGURE_FILE(
178178
${CMAKE_CURRENT_BINARY_DIR}/config.h)
179179

180180
if(CMARK_LIB_FUZZER)
181-
set(FUZZ_HARNESS "cmark-fuzz")
182-
add_executable(${FUZZ_HARNESS} ../test/cmark-fuzz.c ${LIBRARY_SOURCES})
183-
target_link_libraries(${FUZZ_HARNESS} "${CMAKE_LIB_FUZZER_PATH}")
184-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-coverage=trace-pc-guard")
185-
181+
add_executable(cmark-fuzz ../test/cmark-fuzz.c ${LIBRARY_SOURCES})
182+
target_link_libraries(cmark-fuzz "${CMAKE_LIB_FUZZER_PATH}")
186183
# cmark is written in C but the libFuzzer runtime is written in C++ which
187-
# needs to link against the C++ runtime. Explicitly link it into cmark-fuzz
188-
set_target_properties(${FUZZ_HARNESS} PROPERTIES LINK_FLAGS "-lstdc++")
184+
# needs to link against the C++ runtime.
185+
set_target_properties(cmark-fuzz PROPERTIES
186+
LINKER_LANGUAGE CXX)
189187
endif()

0 commit comments

Comments
 (0)