mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 17:15:31 +00:00
[TravisCI][CMake] Add Z3_C_EXAMPLES_FORCE_CXX_LINKER
CMake option
and propagate its value into the C API examples. This flag forces the C API examples to use the C++ compiler as the linker rather than the C compiler. This a workaround to avoid linking errors when building with UBSan.
This commit is contained in:
parent
64ee9f168d
commit
a9fcfc531b
5 changed files with 52 additions and 2 deletions
|
@ -7,6 +7,19 @@ else()
|
|||
set(EXTERNAL_PROJECT_BUILD_ALWAYS_ARG "")
|
||||
endif()
|
||||
|
||||
option(Z3_C_EXAMPLES_FORCE_CXX_LINKER
|
||||
"Force C++ linker when building C example projects" OFF)
|
||||
|
||||
if (Z3_C_EXAMPLES_FORCE_CXX_LINKER)
|
||||
# HACK: This is a workaround for UBSan.
|
||||
message(STATUS "Forcing C++ linker to be used when building example C projects")
|
||||
set(EXTERNAL_C_PROJ_USE_CXX_LINKER_ARG
|
||||
"-DFORCE_CXX_LINKER=ON"
|
||||
)
|
||||
else()
|
||||
set(EXTERNAL_C_PROJ_USE_CXX_LINKER_ARG "")
|
||||
endif()
|
||||
|
||||
################################################################################
|
||||
# Build example project using libz3's C API as an external project
|
||||
################################################################################
|
||||
|
@ -14,7 +27,9 @@ ExternalProject_Add(c_example
|
|||
DEPENDS libz3
|
||||
# Configure step
|
||||
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/c"
|
||||
CMAKE_ARGS "-DZ3_DIR=${CMAKE_BINARY_DIR}"
|
||||
CMAKE_ARGS
|
||||
"-DZ3_DIR=${CMAKE_BINARY_DIR}"
|
||||
"${EXTERNAL_C_PROJ_USE_CXX_LINKER_ARG}"
|
||||
# Build step
|
||||
${EXTERNAL_PROJECT_BUILD_ALWAYS_ARG}
|
||||
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/c_example_build_dir"
|
||||
|
@ -30,7 +45,9 @@ ExternalProject_Add(c_maxsat_example
|
|||
DEPENDS libz3
|
||||
# Configure step
|
||||
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/maxsat"
|
||||
CMAKE_ARGS "-DZ3_DIR=${CMAKE_BINARY_DIR}"
|
||||
CMAKE_ARGS
|
||||
"-DZ3_DIR=${CMAKE_BINARY_DIR}"
|
||||
"${EXTERNAL_C_PROJ_USE_CXX_LINKER_ARG}"
|
||||
# Build step
|
||||
${EXTERNAL_PROJECT_BUILD_ALWAYS_ARG}
|
||||
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/c_maxsat_example_build_dir"
|
||||
|
|
|
@ -22,6 +22,17 @@ message(STATUS "Found Z3 ${Z3_VERSION_STRING}")
|
|||
message(STATUS "Z3_DIR: ${Z3_DIR}")
|
||||
|
||||
add_executable(c_example test_capi.c)
|
||||
|
||||
option(FORCE_CXX_LINKER "Force linker with C++ linker" OFF)
|
||||
if (FORCE_CXX_LINKER)
|
||||
# This is a hack for avoiding UBSan linking errors
|
||||
message(STATUS "Forcing use of C++ linker")
|
||||
set_target_properties(c_example
|
||||
PROPERTIES
|
||||
LINKER_LANGUAGE CXX
|
||||
)
|
||||
endif()
|
||||
|
||||
target_include_directories(c_example PRIVATE ${Z3_C_INCLUDE_DIRS})
|
||||
target_link_libraries(c_example PRIVATE ${Z3_LIBRARIES})
|
||||
|
||||
|
|
|
@ -25,6 +25,16 @@ add_executable(c_maxsat_example maxsat.c)
|
|||
target_include_directories(c_maxsat_example PRIVATE ${Z3_C_INCLUDE_DIRS})
|
||||
target_link_libraries(c_maxsat_example PRIVATE ${Z3_LIBRARIES})
|
||||
|
||||
option(FORCE_CXX_LINKER "Force linker with C++ linker" OFF)
|
||||
if (FORCE_CXX_LINKER)
|
||||
# This is a hack for avoiding UBSan linking errors
|
||||
message(STATUS "Forcing use of C++ linker")
|
||||
set_target_properties(c_maxsat_example
|
||||
PROPERTIES
|
||||
LINKER_LANGUAGE CXX
|
||||
)
|
||||
endif()
|
||||
|
||||
if ("${CMAKE_SYSTEM_NAME}" MATCHES "[Ww]indows")
|
||||
# On Windows we need to copy the Z3 libraries
|
||||
# into the same directory as the executable
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue