3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-06 01:24:08 +00:00

Fix how the list of linker flags `Z3_DEPENDENT_EXTRA_CXX_LINK_FLAGS`

is applied to targets. The ``LINK_FLAGS`` property of a target is
a string and not a list and so if ``Z3_DEPENDENT_EXTRA_CXX_LINK_FLAGS``
contained more than one flag the linker line would end up being
``-flag1;flag2;flag3;...`` which would not work. Now we use a new
function ``z3_append_linker_flag_list_to_target()`` to iterate through
the list and update the ``LINK_FLAGS`` property of the specified target
correctly.
This commit is contained in:
Dan Liew 2016-03-04 11:19:35 +00:00
parent a2cc6d256a
commit 29901e79e1
5 changed files with 23 additions and 7 deletions

View file

@ -337,6 +337,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
# Z3 components, library and executables
################################################################################
include(${CMAKE_SOURCE_DIR}/cmake/z3_add_component.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/z3_append_linker_flag_list_to_target.cmake)
add_subdirectory(src)
################################################################################

View file

@ -0,0 +1,17 @@
# The LINK_FLAGS property of a target in CMake is unfortunately a string and
# not a list. This function takes a list of linker flags and iterates through
# them to append them as strings to the ``LINK_FLAGS`` property of
# the specified target.
# E.g.
# z3_append_linker_flag_list_to_target(mytarget "-fopenmp" "-static")
function(z3_append_linker_flag_list_to_target target)
if (NOT (TARGET "${target}"))
message(FATAL_ERROR "Specified target \"${target}\" is not a target")
endif()
foreach(flag ${ARGN})
#message(STATUS "Appending link flag \"${flag}\" to target ${target}")
# Note that space inside the quoted string is required so that the flags
# are space separated.
set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS " ${flag}")
endforeach()
endfunction()

View file

@ -140,7 +140,7 @@ endif()
# automatically link against the libs in Z3_DEPENDENT_LIBS
target_link_libraries(libz3 INTERFACE ${Z3_DEPENDENT_LIBS})
set_property(TARGET libz3 APPEND PROPERTY LINK_FLAGS ${Z3_DEPENDENT_EXTRA_CXX_LINK_FLAGS})
z3_append_linker_flag_list_to_target(libz3 ${Z3_DEPENDENT_EXTRA_CXX_LINK_FLAGS})
# Declare which header file are the public header files of libz3
# these will automatically installed when the libz3 target is installed
@ -196,9 +196,7 @@ if (MSVC)
DEPENDS "${dll_module_exports_file}"
)
add_dependencies(libz3 libz3_extra_depends)
set_property(TARGET libz3 APPEND PROPERTY LINK_FLAGS
"/DEF:${dll_module_exports_file}"
)
z3_append_linker_flag_list_to_target(libz3 "/DEF:${dll_module_exports_file}")
endif()
################################################################################

View file

@ -41,7 +41,7 @@ target_compile_options(shell PRIVATE ${Z3_COMPONENT_CXX_FLAGS})
target_include_directories(shell PRIVATE ${Z3_COMPONENT_EXTRA_INCLUDE_DIRS})
target_link_libraries(shell PRIVATE ${Z3_DEPENDENT_LIBS})
z3_add_component_dependencies_to_target(shell ${shell_expanded_deps})
set_property(TARGET shell APPEND PROPERTY LINK_FLAGS ${Z3_DEPENDENT_EXTRA_CXX_LINK_FLAGS})
z3_append_linker_flag_list_to_target(shell ${Z3_DEPENDENT_EXTRA_CXX_LINK_FLAGS})
install(TARGETS shell
RUNTIME DESTINATION "${Z3_INSTALL_BIN_DIR}"
)

View file

@ -121,6 +121,6 @@ z3_add_gparams_register_modules_rule(${z3_test_deps})
target_compile_definitions(test-z3 PRIVATE ${Z3_COMPONENT_CXX_DEFINES})
target_compile_options(test-z3 PRIVATE ${Z3_COMPONENT_CXX_FLAGS})
target_link_libraries(test-z3 PRIVATE ${Z3_DEPENDENT_LIBS})
target_include_directories(shell PRIVATE ${Z3_COMPONENT_EXTRA_INCLUDE_DIRS})
set_property(TARGET test-z3 APPEND PROPERTY LINK_FLAGS ${Z3_DEPENDENT_EXTRA_CXX_LINK_FLAGS})
target_include_directories(test-z3 PRIVATE ${Z3_COMPONENT_EXTRA_INCLUDE_DIRS})
z3_append_linker_flag_list_to_target(test-z3 ${Z3_DEPENDENT_EXTRA_CXX_LINK_FLAGS})
z3_add_component_dependencies_to_target(test-z3 ${z3_test_expanded_deps})