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.
This commit is contained in:
Saleem Abdulrasool
2024-01-04 15:24:47 -08:00
parent 32f0f77276
commit 8b51fc28d0
2 changed files with 9 additions and 7 deletions

View File

@@ -78,6 +78,10 @@ add_compile_definitions(CMARK_USE_CMAKE_HEADERS)
option(CMARK_FUZZ_QUADRATIC "Build quadratic fuzzing harness" OFF)
if(CMARK_LIB_FUZZER)
add_compile_options($<$<COMPILE_LANGUAGE:C>:-fsanitize-coverage=trace-pc-guard>)
endif()
if(CMARK_FUZZ_QUADRATIC)
# FIXME(compnerd) why do we enable debug information?
add_compile_options($<$<COMPILE_LANGUAGE:C>:-g>)

View File

@@ -178,12 +178,10 @@ CONFIGURE_FILE(
${CMAKE_CURRENT_BINARY_DIR}/config.h)
if(CMARK_LIB_FUZZER)
set(FUZZ_HARNESS "cmark-fuzz")
add_executable(${FUZZ_HARNESS} ../test/cmark-fuzz.c ${LIBRARY_SOURCES})
target_link_libraries(${FUZZ_HARNESS} "${CMAKE_LIB_FUZZER_PATH}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-coverage=trace-pc-guard")
add_executable(cmark-fuzz ../test/cmark-fuzz.c ${LIBRARY_SOURCES})
target_link_libraries(cmark-fuzz "${CMAKE_LIB_FUZZER_PATH}")
# cmark is written in C but the libFuzzer runtime is written in C++ which
# needs to link against the C++ runtime. Explicitly link it into cmark-fuzz
set_target_properties(${FUZZ_HARNESS} PROPERTIES LINK_FLAGS "-lstdc++")
# needs to link against the C++ runtime.
set_target_properties(cmark-fuzz PROPERTIES
LINKER_LANGUAGE CXX)
endif()