@@ -49,41 +49,81 @@ function(get_imported_library_prefix outvar target prefix)
49
49
endif ()
50
50
endfunction ()
51
51
52
- # What this function does is go through each of the passed in imported targets
53
- # from LLVM/Clang and changes them to use the appropriate fully expanded paths.
54
- #
55
- # TODO: This function needs a better name.
56
- function (fix_imported_target_locations_for_xcode targets )
57
- foreach (t ${targets} )
58
- if (NOT TARGET ${t} )
59
- message (FATAL_ERROR "${t} is not a target?!" )
60
- endif ()
52
+ function (check_imported_target_has_imported_configuration target config )
53
+ get_target_property (IMPORTED_CONFIGS_LIST ${target} IMPORTED_CONFIGURATIONS )
54
+ if ("${IMPORTED_CONFIGS_LIST} " STREQUAL "NOTFOUND" )
55
+ message (FATAL_ERROR "No import configuration of ${target} specified?!" )
56
+ endif ()
61
57
62
- get_target_property (TARGET_TYPE ${t} TYPE )
58
+ list (FIND "${IMPORTED_CONFIGS_LIST} " "${config} " FOUND_CONFIG )
59
+ if (NOT FOUND_CONFIG )
60
+ message (FATAL_ERROR "${target} does not have imported config '${config} '?! \
61
+ Instead: ${IMPORTED_CONFIGS_LIST} " )
62
+ endif ()
63
+ endfunction ()
63
64
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 ( )
65
+ function ( fixup_imported_target_property_for_xcode target property real_build_type )
66
+ set ( FULL_PROP_NAME "${property} _ ${real_build_type} " )
67
+
68
+ # First try to lookup the value associated with the "real build type".
69
+ get_target_property ( PROP_VALUE ${target} ${FULL_PROP_NAME} )
69
70
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} " )
71
+ # If the property is unspecified, return.
72
+ if ("${PROP_VALUE} " STREQUAL "NOTFOUND" )
73
+ return ()
74
+ endif ()
75
+
76
+ # Otherwise for each cmake configuration that is not real_build_type, hardcode
77
+ # its value to be PROP_VALUE.
78
+ foreach (c ${CMAKE_CONFIGURATION_TYPES} )
79
+ if ("${c} " STREQUAL "${real_build_type} " )
78
80
continue ()
79
81
endif ()
82
+ set_target_properties (${target} PROPERTIES ${FULL_PROP_NAME} "${PROP_VALUE} " )
83
+ endforeach ()
84
+ endfunction ()
85
+
86
+ # When building with Xcode, we only support compiling against the LLVM
87
+ # configuration that was specified by build-script. This becomes a problem since
88
+ # if we compile LLVM-Release and Swift-Debug, Swift is going to look in the
89
+ # Debug, not the Release folder for LLVM's code and thus will be compiling
90
+ # against an unintended set of libraries, if those libraries exist at all.
91
+ #
92
+ # Luckily, via LLVMConfig.cmake, we know the configuration that LLVM was
93
+ # compiled in, so we can grab the imported location for that configuration and
94
+ # splat it across the other configurations as well.
95
+ function (fix_imported_targets_for_xcode imported_targets )
96
+ # This is the set of configuration specific cmake properties that are
97
+ # supported for imported targets in cmake 3.4.3. Sadly, beyond hacks, it seems
98
+ # that there is no way to dynamically query the list of set properties of a
99
+ # target.
100
+ #
101
+ # *NOTE* In fixup_imported_target_property_for_xcode, we add the _${CONFIG}
102
+ # *suffix.
103
+ set (imported_target_properties
104
+ IMPORTED_IMPLIB
105
+ IMPORTED_LINK_DEPENDENT_LIBRARIES
106
+ IMPORTED_LINK_INTERFACE_LANGUAGES
107
+ IMPORTED_LINK_INTERFACE_LIBRARIES
108
+ IMPORTED_LINK_INTERFACE_MULTIPLICITY
109
+ IMPORTED_LOCATION
110
+ IMPORTED_NO_SONAME
111
+ IMPORTED_SONAME )
112
+
113
+ foreach (target ${imported_targets} )
114
+ if (NOT TARGET ${target} )
115
+ message (FATAL_ERROR "${target} is not a target?!" )
116
+ endif ()
117
+
118
+ # First check that we actually imported the configuration that LLVM said
119
+ # that we did. This is just a sanity check.
120
+ check_imported_target_has_imported_configuration (${target} ${LLVM_BUILD_TYPE} )
80
121
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}" )
84
- set_target_properties (${t} PROPERTIES
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}" )
122
+ # Then loop through all of the imported properties and translate.
123
+ foreach (property ${imported_properties} )
124
+ fixup_imported_target_property_for_xcode (
125
+ ${target} ${property} ${LLVM_BUILD_TYPE} )
126
+ endforeach ()
87
127
endforeach ()
88
128
endfunction ()
89
129
@@ -147,7 +187,7 @@ macro(swift_common_standalone_build_config_llvm product is_cross_compiling)
147
187
set (LLVM_LIBRARY_OUTPUT_INTDIR "${LLVM_LIBRARY_DIR} " )
148
188
149
189
if (XCODE )
150
- fix_imported_target_locations_for_xcode ("${LLVM_EXPORTED_TARGETS} " )
190
+ fix_imported_targets_for_xcode ("${LLVM_EXPORTED_TARGETS} " )
151
191
endif ()
152
192
153
193
if (NOT ${is_cross_compiling} )
@@ -240,7 +280,7 @@ macro(swift_common_standalone_build_config_clang product is_cross_compiling)
240
280
set (CLANG_MAIN_INCLUDE_DIR "${CLANG_MAIN_SRC_DIR} /include" )
241
281
242
282
if (XCODE )
243
- fix_imported_target_locations_for_xcode ("${CLANG_EXPORTED_TARGETS} " )
283
+ fix_imported_targets_for_xcode ("${CLANG_EXPORTED_TARGETS} " )
244
284
endif ()
245
285
246
286
include_directories ("${CLANG_BUILD_INCLUDE_DIR} "
0 commit comments