Skip to content

Commit 28f05ac

Browse files
author
Chris Bieneman
committed
[CMake] Fix symlink refactor for multi-configuration generators
This fix, while a bit complicated, preserves the reusability while fixing the issues reported on llvm-commits with visual studio generators. llvm-svn: 288679
1 parent 2a942c4 commit 28f05ac

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

llvm/cmake/modules/AddLLVM.cmake

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,14 +1290,34 @@ endfunction()
12901290

12911291
function(add_llvm_tool_symlink link_name target)
12921292
cmake_parse_arguments(ARG "ALWAYS_GENERATE" "OUTPUT_DIR" "" ${ARGN})
1293+
# This got a bit gross... For multi-configuration generators the target
1294+
# properties return the resolved value of the string, not the build system
1295+
# expression. To reconstruct the platform-agnostic path we have to do some
1296+
# magic. First we grab one of the types, and a type-specific path. Then from
1297+
# the type-specific path we find the last occurrence of the type in the path,
1298+
# and replace it with CMAKE_CFG_INTDIR. This allows the build step to be type
1299+
# agnostic again.
12931300
if(NOT ARG_OUTPUT_DIR)
1301+
if(CMAKE_CONFIGURATION_TYPES)
1302+
list(GET CMAKE_CONFIGURATION_TYPES 0 first_type)
1303+
string(TOUPPER ${first_type} first_type_upper)
1304+
set(first_type_suffix _${first_type_upper})
1305+
endif()
12941306
get_target_property(target_type ${target} TYPE)
12951307
if(${target_type} STREQUAL "STATIC_LIBRARY")
1296-
get_target_property(ARG_OUTPUT_DIR ${target} ARCHIVE_OUTPUT_DIRECTORY)
1308+
get_target_property(ARG_OUTPUT_DIR ${target} ARCHIVE_OUTPUT_DIRECTORY${first_type_suffix})
12971309
elseif(UNIX AND ${target_type} STREQUAL "SHARED_LIBRARY")
1298-
get_target_property(ARG_OUTPUT_DIR ${target} LIBRARY_OUTPUT_DIRECTORY)
1310+
get_target_property(ARG_OUTPUT_DIR ${target} LIBRARY_OUTPUT_DIRECTORY${first_type_suffix})
12991311
else()
1300-
get_target_property(ARG_OUTPUT_DIR ${target} RUNTIME_OUTPUT_DIRECTORY)
1312+
get_target_property(ARG_OUTPUT_DIR ${target} RUNTIME_OUTPUT_DIRECTORY${first_type_suffix})
1313+
endif()
1314+
if(CMAKE_CONFIGURATION_TYPES)
1315+
string(FIND "${ARG_OUTPUT_DIR}" "/${first_type}/" type_start REVERSE)
1316+
string(SUBSTRING "${ARG_OUTPUT_DIR}" 0 ${type_start} path_prefix)
1317+
string(SUBSTRING "${ARG_OUTPUT_DIR}" ${type_start} -1 path_suffix)
1318+
string(REPLACE "/${first_type}/" "/${CMAKE_CFG_INTDIR}/"
1319+
path_suffix ${path_suffix})
1320+
set(ARG_OUTPUT_DIR ${path_prefix}${path_suffix})
13011321
endif()
13021322
endif()
13031323

0 commit comments

Comments
 (0)