@@ -165,30 +165,73 @@ function(_thrust_add_target_to_target_list target_name host device dialect prefi
165165endfunction ()
166166
167167function (_thrust_build_target_list_multiconfig )
168- # Find thrust and all of the required systems:
169- set (req_systems)
170- if (THRUST_MULTICONFIG_ENABLE_SYSTEM_CUDA)
171- list (APPEND req_systems CUDA)
172- endif ()
173- if (THRUST_MULTICONFIG_ENABLE_SYSTEM_CPP)
174- list (APPEND req_systems CPP)
175- endif ()
176- if (THRUST_MULTICONFIG_ENABLE_SYSTEM_TBB)
177- list (APPEND req_systems TBB)
178- endif ()
179- if (THRUST_MULTICONFIG_ENABLE_SYSTEM_OMP)
180- list (APPEND req_systems OMP)
181- endif ()
168+ # Detect supported dialects if requested -- this must happen after CUDA is
169+ # enabled, if it's going to be enabled.
170+ if (THRUST_MULTICONFIG_ENABLE_DIALECT_ALL OR
171+ THRUST_MULTICONFIG_ENABLE_DIALECT_LATEST)
172+ message (STATUS "Testing for supported language standards..." )
173+ include ("${CMAKE_CURRENT_FUNCTION_LIST_DIR} /DetectSupportedStandards.cmake" )
174+ detect_supported_standards (THRUST CXX ${THRUST_CPP_DIALECT_OPTIONS} )
175+ if (THRUST_CUDA_FOUND)
176+ detect_supported_standards (THRUST CUDA ${THRUST_CPP_DIALECT_OPTIONS} )
177+ endif ()
182178
183- find_package (Thrust REQUIRED CONFIG
184- NO_DEFAULT_PATH # Only check the explicit path in HINTS:
185- HINTS "${Thrust_SOURCE_DIR} "
186- COMPONENTS ${req_systems}
187- )
179+ # Take the union of supported standards in CXX and CUDA:
180+ set (supported_dialects)
181+ set (latest_dialect 11)
182+ foreach (standard IN LISTS THRUST_CPP_DIALECT_OPTIONS)
183+ if ((THRUST_CXX_${standard} _SUPPORTED) AND
184+ ((NOT THRUST_CUDA_FOUND) OR THRUST_CUDA_${standard} _SUPPORTED))
188185
189- # This must be called after backends are loaded but
190- # before _thrust_add_target_to_target_list.
191- thrust_build_compiler_targets ()
186+ # MSVC silently promotes C++11 to C++14 -- skip it:
187+ if ((${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC ) AND (standard EQUAL 11))
188+ continue ()
189+ endif ()
190+
191+ list (APPEND supported_dialects ${standard} )
192+ if (latest_dialect LESS standard)
193+ set (latest_dialect ${standard} )
194+ endif ()
195+ endif ()
196+ endforeach ()
197+
198+ if (THRUST_MULTICONFIG_ENABLE_DIALECT_ALL)
199+ foreach (standard IN LISTS THRUST_CPP_DIALECT_OPTIONS)
200+ if (standard IN_LIST supported_dialects)
201+ set (THRUST_MULTICONFIG_ENABLE_DIALECT_CPP${standard} ON CACHE BOOL
202+ "Generate C++${dialect} build configurations." FORCE
203+ )
204+ else ()
205+ set (THRUST_MULTICONFIG_ENABLE_DIALECT_CPP${standard} OFF CACHE BOOL
206+ "Generate C++${dialect} build configurations." FORCE
207+ )
208+ endif ()
209+ endforeach ()
210+ elseif (THRUST_MULTICONFIG_ENABLE_DIALECT_LATEST)
211+ foreach (standard IN LISTS THRUST_CPP_DIALECT_OPTIONS)
212+ if (standard EQUAL latest_dialect)
213+ set (THRUST_MULTICONFIG_ENABLE_DIALECT_CPP${standard} ON CACHE BOOL
214+ "Generate C++${dialect} build configurations." FORCE
215+ )
216+ else ()
217+ set (THRUST_MULTICONFIG_ENABLE_DIALECT_CPP${standard} OFF CACHE BOOL
218+ "Generate C++${dialect} build configurations." FORCE
219+ )
220+ endif ()
221+ endforeach ()
222+ endif ()
223+ endif ()
224+
225+ # Supported versions of MSVC do not distinguish between C++11 and C++14.
226+ # Warn the user that they may be generating a ton of redundant targets if
227+ # they explicitly requested this configuration.
228+ if ("MSVC" STREQUAL "${CMAKE_CXX_COMPILER_ID} " AND
229+ THRUST_MULTICONFIG_ENABLE_DIALECT_CPP11)
230+ message (WARNING
231+ "Supported versions of MSVC (2017+) do not distinguish between C++11 "
232+ "and C++14. The requested C++11 targets may be redundant."
233+ )
234+ endif ()
192235
193236 # Build THRUST_TARGETS
194237 foreach (host IN LISTS THRUST_HOST_SYSTEM_OPTIONS)
@@ -225,22 +268,11 @@ function(_thrust_build_target_list_multiconfig)
225268endfunction ()
226269
227270function (_thrust_build_target_list_singleconfig )
228- find_package (Thrust REQUIRED CONFIG
229- NO_DEFAULT_PATH # Only check the explicit path in HINTS:
230- HINTS "${Thrust_SOURCE_DIR} "
231- )
232- thrust_create_target (thrust FROM_OPTIONS ${THRUST_TARGET_FLAGS} )
233- thrust_debug_target (thrust "${THRUST_VERSION} " )
234-
235271 set (host ${THRUST_HOST_SYSTEM} )
236272 set (device ${THRUST_DEVICE_SYSTEM} )
237273 set (dialect ${THRUST_CPP_DIALECT} )
238274 set (prefix "thrust" ) # single config
239275
240- # This depends on the backends loaded by thrust_create_target, and must
241- # be called before _thrust_add_target_to_target_list.
242- thrust_build_compiler_targets ()
243-
244276 _thrust_add_target_to_target_list (thrust ${host} ${device} ${dialect} ${prefix} )
245277endfunction ()
246278
0 commit comments