Fix building fuzz targets on macOS

This commit is contained in:
Jon Siwek 2020-05-15 11:23:24 -07:00
parent 48153ba12f
commit c4d41dcfbb

View file

@ -22,16 +22,26 @@ if ( NOT DEFINED ZEEK_FUZZING_ENGINE AND DEFINED ENV{LIB_FUZZING_ENGINE} )
endif () endif ()
endif () endif ()
# The bind library is handled a bit hack-ishly since it defaults to linking it
# as static library by default on Linux, but at least on one common distro,
# that static library wasn't compiled with -fPIC and so not usable in the
# shared library we're trying to build. So instead, the fuzzer executable, not
# the shared lib, links it.
string(REGEX MATCH ".*\\.a$" _have_static_bind_lib "${BIND_LIBRARY}")
macro(ADD_FUZZ_TARGET _name) macro(ADD_FUZZ_TARGET _name)
set(_fuzz_target zeek-${_name}-fuzzer) set(_fuzz_target zeek-${_name}-fuzzer)
set(_fuzz_source ${_name}-fuzzer.cc) set(_fuzz_source ${_name}-fuzzer.cc)
add_executable(${_fuzz_target} ${_fuzz_source} ${ARGN}) add_executable(${_fuzz_target} ${_fuzz_source} ${ARGN})
target_link_libraries(${_fuzz_target} target_link_libraries(${_fuzz_target} zeek_fuzzer_shared)
zeek_fuzzer_shared
${BIND_LIBRARY} if ( _have_static_bind_lib )
${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS}) target_link_libraries(${_fuzz_target} ${BIND_LIBRARY})
endif ()
target_link_libraries(${_fuzz_target} ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS})
if ( DEFINED ZEEK_FUZZING_ENGINE ) if ( DEFINED ZEEK_FUZZING_ENGINE )
target_link_libraries(${_fuzz_target} ${ZEEK_FUZZING_ENGINE}) target_link_libraries(${_fuzz_target} ${ZEEK_FUZZING_ENGINE})
@ -55,12 +65,11 @@ add_library(zeek_fuzzer_shared SHARED
set(zeek_fuzzer_shared_deps) set(zeek_fuzzer_shared_deps)
foreach(_dep ${zeekdeps} ) foreach(_dep ${zeekdeps} )
# The bind library is handled a bit hack-ishly since it defaults to if ( "${_dep}" STREQUAL "${BIND_LIBRARY}" )
# linking it as static library by default on Linux, but at least if ( NOT _have_static_bind_lib )
# on one common distro, that static library wasn't compiled with -fPIC set(zeek_fuzzer_shared_deps ${zeek_fuzzer_shared_deps} ${_dep})
# and so not usable in the shared library we're trying to build. endif ()
# So instead, the fuzzer executable, not the shared lib, links it. else ()
if ( NOT "${_dep}" STREQUAL "${BIND_LIBRARY}" )
set(zeek_fuzzer_shared_deps ${zeek_fuzzer_shared_deps} ${_dep}) set(zeek_fuzzer_shared_deps ${zeek_fuzzer_shared_deps} ${_dep})
endif () endif ()
endforeach () endforeach ()