Skip to content

Commit d701d53

Browse files
authored
Merge pull request #3371 from gottesmm/cmake_also_provide_absolute_paths_for_shared_libs_and_executables
[cmake] Also provide absolute paths for shared libraries/executables …
2 parents e5d3ccf + 95b6595 commit d701d53

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

cmake/modules/SwiftSharedCMakeConfig.cmake

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ function(escape_llvm_path_for_xcode path outvar)
4040
set(${outvar} "${path}" PARENT_SCOPE)
4141
endfunction()
4242

43+
function(get_imported_library_prefix outvar target prefix)
44+
string(FIND "${target}" "${prefix}" ALREADY_HAS_PREFIX)
45+
if (ALREADY_HAS_PREFIX)
46+
set(${outvar} "" PARENT_SCOPE)
47+
else()
48+
set(${outvar} "${prefix}" PARENT_SCOPE)
49+
endif()
50+
endfunction()
51+
4352
# What this function does is go through each of the passed in imported targets
4453
# from LLVM/Clang and changes them to use the appropriate fully expanded paths.
4554
#
@@ -52,14 +61,29 @@ function(fix_imported_target_locations_for_xcode targets)
5261

5362
get_target_property(TARGET_TYPE ${t} TYPE)
5463

55-
# We only want to do this for static libraries for now.
56-
if (NOT ${TARGET_TYPE} STREQUAL "STATIC_LIBRARY")
64+
if (NOT "${TARGET_TYPE}" STREQUAL "STATIC_LIBRARY" AND
65+
NOT "${TARGET_TYPE}" STREQUAL "SHARED_LIBRARY" AND
66+
NOT "${TARGET_TYPE}" STREQUAL "EXECUTABLE")
67+
message(FATAL_ERROR "Unsupported imported target type ${TARGET_TYPE}")
68+
endif()
69+
70+
# Ok, so at this point, we know that we have an executable, static library,
71+
# or shared library.
72+
#
73+
# First we handle the executables.
74+
if ("${TARGET_TYPE}" STREQUAL "EXECUTABLE")
75+
set_target_properties(${t} PROPERTIES
76+
IMPORTED_LOCATION_DEBUG "${LLVM_BINARY_OUTPUT_INTDIR}/${t}"
77+
IMPORTED_LOCATION_RELEASE "${LLVM_BINARY_OUTPUT_INTDIR}/${t}")
5778
continue()
5879
endif()
5980

81+
# Otherwise, we have libraries. Since libclang has an extra lib prefix in
82+
# its target name, we have to handle it specially.
83+
get_imported_library_prefix(PREFIX "${t}" "${CMAKE_${TARGET_TYPE}_PREFIX}")
6084
set_target_properties(${t} PROPERTIES
61-
IMPORTED_LOCATION_DEBUG "${LLVM_LIBRARY_OUTPUT_INTDIR}/lib${t}.a"
62-
IMPORTED_LOCATION_RELEASE "${LLVM_LIBRARY_OUTPUT_INTDIR}/lib${t}.a")
85+
IMPORTED_LOCATION_DEBUG "${LLVM_LIBRARY_OUTPUT_INTDIR}/${PREFIX}${t}.${CMAKE_${TARGET_TYPE}_SUFFIX}"
86+
IMPORTED_LOCATION_RELEASE "${LLVM_LIBRARY_OUTPUT_INTDIR}/${PREFIX}${t}.${CMAKE_${TARGET_TYPE}_SUFFIX}")
6387
endforeach()
6488
endfunction()
6589

@@ -119,6 +143,7 @@ macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
119143
# against a matching LLVM build configuration. However, we usually want to be
120144
# flexible and allow linking a debug Swift against optimized LLVM.
121145
set(LLVM_RUNTIME_OUTPUT_INTDIR "${LLVM_BINARY_DIR}")
146+
set(LLVM_BINARY_OUTPUT_INTDIR "${LLVM_TOOLS_BINARY_DIR}")
122147
set(LLVM_LIBRARY_OUTPUT_INTDIR "${LLVM_LIBRARY_DIR}")
123148

124149
if (XCODE)

0 commit comments

Comments
 (0)