Skip to content

build: introduce and use swift_target_link_search_directories #6354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ endfunction()
function(_add_variant_link_flags)
set(oneValueArgs SDK ARCH BUILD_TYPE ENABLE_ASSERTIONS ANALYZE_CODE_COVERAGE
DEPLOYMENT_VERSION_OSX DEPLOYMENT_VERSION_IOS DEPLOYMENT_VERSION_TVOS DEPLOYMENT_VERSION_WATCHOS
RESULT_VAR_NAME ENABLE_LTO LTO_OBJECT_NAME)
RESULT_VAR_NAME ENABLE_LTO LTO_OBJECT_NAME LIBRARY_SEARCH_DIRECTORIES)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better if this were a multi-value argument rather than a single value argument.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@llvm-beanz thats an out parameter, which is the variable that gets the list. Im not sure what you are suggesting here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I misunderstood something here. It actually looks to me like you're using it as both an in and out parameter. That is confusing and really gross, but that is how the other options work, so I guess it is okay.

cmake_parse_arguments(LFLAGS
""
"${oneValueArgs}"
Expand All @@ -310,6 +310,7 @@ function(_add_variant_link_flags)
endif()

set(result ${${LFLAGS_RESULT_VAR_NAME}})
set(library_search_directories ${${LFLAGS_LIBRARY_SEARCH_DIRECTORIES}})

_add_variant_c_compile_link_flags(
SDK "${LFLAGS_SDK}"
Expand Down Expand Up @@ -337,8 +338,9 @@ function(_add_variant_link_flags)
elseif("${LFLAGS_SDK}" STREQUAL "ANDROID")
list(APPEND result
"-ldl"
"-L${SWIFT_ANDROID_PREBUILT_PATH}/lib/gcc/arm-linux-androideabi/${SWIFT_ANDROID_NDK_GCC_VERSION}.x"
"${SWIFT_ANDROID_NDK_PATH}/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so")
list(APPEND library_search_directories
"${SWIFT_ANDROID_PREBUILT_PATH}/lib/gcc/arm-linux-androideabi/${SWIFT_ANDROID_NDK_GCC_VERSION}.x")
else()
list(APPEND result "-lobjc")

Expand All @@ -357,13 +359,14 @@ function(_add_variant_link_flags)
endif()

if(NOT "${SWIFT_${LFLAGS_SDK}_ICU_UC}" STREQUAL "")
list(APPEND result "-L${SWIFT_${sdk}_ICU_UC}")
list(APPEND library_search_directories "${SWIFT_${sdk}_ICU_UC}")
endif()
if(NOT "${SWIFT_${LFLAGS_SDK}_ICU_I18N}" STREQUAL "")
list(APPEND result "-L${SWIFT_${sdk}_ICU_I18N}")
list(APPEND library_search_directories "${SWIFT_${sdk}_ICU_I18N}")
endif()

set("${LFLAGS_RESULT_VAR_NAME}" "${result}" PARENT_SCOPE)
set("${LFLAGS_LIBRARY_SEARCH_DIRECTORIES}" "${library_search_directories}" PARENT_SCOPE)
endfunction()

# Look up extra flags for a module that matches a regexp.
Expand Down Expand Up @@ -460,6 +463,14 @@ function(_add_swift_lipo_target)
endif()
endfunction()

function(swift_target_link_search_directories target directories)
set(STLD_FLAGS "")
foreach(directory ${directories})
set(STLD_FLAGS " ${CMAKE_LIBRARY_PATH_FLAG}${directory}")
endforeach()
set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS ${STLD_FLAGS})
endfunction()

# Add a single variant of a new Swift library.
#
# Usage:
Expand Down Expand Up @@ -988,6 +999,10 @@ function(_add_swift_library_single target name)
# Don't set PROPERTY COMPILE_FLAGS or LINK_FLAGS directly.
set(c_compile_flags ${SWIFTLIB_SINGLE_C_COMPILE_FLAGS})
set(link_flags ${SWIFTLIB_SINGLE_LINK_FLAGS})
set(library_search_directories
"${SWIFTLIB_DIR}/${SWIFTLIB_SINGLE_SUBDIR}"
"${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/../lib/swift/${SWIFTLIB_SINGLE_SUBDIR}"
"${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/../lib/swift/${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_LIB_SUBDIR}")

# Add variant-specific flags.
if(SWIFTLIB_SINGLE_TARGET_LIBRARY)
Expand Down Expand Up @@ -1029,6 +1044,7 @@ function(_add_swift_library_single target name)
DEPLOYMENT_VERSION_TVOS "${SWIFTLIB_DEPLOYMENT_VERSION_TVOS}"
DEPLOYMENT_VERSION_WATCHOS "${SWIFTLIB_DEPLOYMENT_VERSION_WATCHOS}"
RESULT_VAR_NAME link_flags
LIBRARY_SEARCH_DIRECTORIES library_search_directories
)

if(SWIFT_ENABLE_GOLD_LINKER AND
Expand Down Expand Up @@ -1081,7 +1097,8 @@ function(_add_swift_library_single target name)
set_property(TARGET "${target}" APPEND_STRING PROPERTY
COMPILE_FLAGS " ${c_compile_flags}")
set_property(TARGET "${target}" APPEND_STRING PROPERTY
LINK_FLAGS " ${link_flags} -L${SWIFTLIB_DIR}/${SWIFTLIB_SINGLE_SUBDIR} -L${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/../lib/swift/${SWIFTLIB_SINGLE_SUBDIR} -L${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/../lib/swift/${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_LIB_SUBDIR}")
LINK_FLAGS " ${link_flags}")
swift_target_link_search_directories(${target} ${library_search_directories})

# Adjust the linked libraries for windows targets. On Windows, the link is
# performed against the import library, and the runtime uses the dll. Not
Expand Down Expand Up @@ -1133,8 +1150,12 @@ function(_add_swift_library_single target name)
if(target_static)
set_property(TARGET "${target_static}" APPEND_STRING PROPERTY
COMPILE_FLAGS " ${c_compile_flags}")
set_property(TARGET "${target_static}" APPEND_STRING PROPERTY
LINK_FLAGS " ${link_flags} -L${SWIFTSTATICLIB_DIR}/${SWIFTLIB_SINGLE_SUBDIR} -L${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/../lib/swift/${SWIFTLIB_SINGLE_SUBDIR} -L${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/../lib/swift/${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_LIB_SUBDIR}")
set(library_search_directories
"${SWIFTSTATICLIB_DIR}/${SWIFTLIB_SINGLE_SUBDIR}"
"${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/../lib/swift/${SWIFTLIB_SINGLE_SUBDIR}"
"${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/../lib/swift/${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_LIB_SUBDIR}")
swift_target_link_search_directories(${target_static}
${library_search_directories})
target_link_libraries("${target_static}" PRIVATE
${SWIFTLIB_SINGLE_PRIVATE_LINK_LIBRARIES})
endif()
Expand Down Expand Up @@ -1773,9 +1794,6 @@ function(_add_swift_executable_single name)
ANALYZE_CODE_COVERAGE "${SWIFT_ANALYZE_CODE_COVERAGE}"
RESULT_VAR_NAME link_flags)

list(APPEND link_flags
"-L${SWIFTLIB_DIR}/${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_LIB_SUBDIR}")

if(SWIFTEXE_SINGLE_DISABLE_ASLR)
list(APPEND link_flags "-Wl,-no_pie")
endif()
Expand Down Expand Up @@ -1839,6 +1857,8 @@ function(_add_swift_executable_single name)

set_property(TARGET ${name} APPEND_STRING PROPERTY
COMPILE_FLAGS " ${c_compile_flags}")
swift_target_link_search_directories(${name}
"${SWIFTLIB_DIR}/${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK}_LIB_SUBDIR}")
set_property(TARGET ${name} APPEND_STRING PROPERTY
LINK_FLAGS " ${link_flags}")
if (SWIFT_PARALLEL_LINK_JOBS)
Expand Down