272c7a95b830a1896321b75940b14cbad71415d3
[platform/upstream/cmake.git] / Tests / ExportImport / Import / A / CMakeLists.txt
1 # Prepare imported targets that the exported project itself imported.
2 add_library(SubDirLinkAImported IMPORTED INTERFACE)
3 target_compile_definitions(SubDirLinkAImported INTERFACE DEF_SubDirLinkAImportedForImport)
4 add_library(SubDirLinkBImported IMPORTED INTERFACE)
5 target_compile_definitions(SubDirLinkBImported INTERFACE DEF_SubDirLinkBImportedForImport)
6
7 # Import targets from the exported build tree.
8 include(${Import_BINARY_DIR}/../Export/ExportBuildTree.cmake)
9
10 # Import targets from the exported install tree.
11 include(${CMAKE_INSTALL_PREFIX}/lib/exp/exp.cmake)
12
13 # Import two exports, where the Depends one depends on an exported target from the Required one:
14 include(${CMAKE_INSTALL_PREFIX}/lib/cmake/testLibRequired/testLibRequiredTargets.cmake)
15 include(${CMAKE_INSTALL_PREFIX}/lib/cmake/testLibDepends/testLibDependsTargets.cmake)
16
17 # Try referencing an executable imported from the install tree.
18 add_custom_command(
19   OUTPUT ${Import_BINARY_DIR}/exp_generated.c
20   COMMAND exp_testExe1 ${Import_BINARY_DIR}/exp_generated.c
21   DEPENDS exp_testExe1
22   )
23 add_custom_command(
24   OUTPUT ${Import_BINARY_DIR}/exp_generated3.c
25   COMMAND exp_testExe3 ${Import_BINARY_DIR}/exp_generated3.c
26   DEPENDS exp_testExe3
27   )
28 add_custom_command(
29   OUTPUT ${Import_BINARY_DIR}/exp_generated4.c
30   COMMAND exp_testExe4 ${Import_BINARY_DIR}/exp_generated4.c
31   DEPENDS exp_testExe4
32   )
33
34 add_executable(imp_testExe1
35   imp_testExe1.c
36   ${Import_BINARY_DIR}/exp_generated.c
37   ${Import_BINARY_DIR}/exp_generated3.c
38   ${Import_BINARY_DIR}/exp_generated4.c
39   )
40
41 function(checkForProperty _TARGET _PROP _EXPECTED)
42   get_target_property(EXPORTED_PROPERTY ${_TARGET} "${_PROP}")
43   if (NOT EXPORTED_PROPERTY STREQUAL "${_EXPECTED}")
44     message(SEND_ERROR "${_TARGET} was expected to export \"${_PROP}\" with value \"${_EXPECTED}\" but got \"${EXPORTED_PROPERTY}\"")
45   endif()
46 endfunction()
47
48 checkForProperty(bld_testLib3 "EXPORTED_PROPERTY1"  "EXPORTING_TESTLIB3")
49 checkForProperty(exp_testLib3 "EXPORTED_PROPERTY1"  "EXPORTING_TESTLIB3")
50 checkForProperty(bld_testLib4 "EXPORTED_PROPERTY2"  "EXPORTING_TESTLIB4_1")
51 checkForProperty(exp_testLib4 "EXPORTED_PROPERTY2"  "EXPORTING_TESTLIB4_1")
52 checkForProperty(bld_testLib4 "EXPORTED_PROPERTY3"  "EXPORTING_TESTLIB4_2")
53 checkForProperty(exp_testLib4 "EXPORTED_PROPERTY3"  "EXPORTING_TESTLIB4_2")
54 checkForProperty(bld_testLibDeprecation "DEPRECATION"  "Deprecated version. Please use latest version")
55 checkForProperty(exp_testLibDeprecation "DEPRECATION"  "Deprecated version. Please use latest version")
56
57 # Try linking to a deprecated library
58 target_link_libraries(imp_testExe1 exp_testLibDeprecation)
59
60
61 # Try linking to a library imported from the install tree.
62 target_link_libraries(imp_testExe1
63   exp_testLib2
64   exp_testLib3
65   exp_testLib4
66   exp_testLib5
67   exp_testLib6
68   exp_testLib7
69   exp_testLibCycleA
70   exp_testLibPerConfigDest
71   exp_testStaticLibWithPlugin
72   )
73
74 add_library(imp_testInterfaceInclude1 STATIC imp_testInterfaceInclude1.c)
75 target_include_directories(imp_testInterfaceInclude1 SYSTEM PRIVATE testInterfaceIncludeSystem)
76 target_link_libraries(imp_testInterfaceInclude1 PRIVATE exp_testInterfaceIncludeUser)
77
78 add_executable(imp_UseSharedLibWithHelper1 ../../../InterfaceLinkLibrariesDirect/UseSharedLibWithHelper.c)
79 target_link_libraries(imp_UseSharedLibWithHelper1 PRIVATE exp_testSharedLibWithHelper testSharedLibHelperExclude)
80
81 # Try building a plugin to an executable imported from the install tree.
82 add_library(imp_mod1 MODULE imp_mod1.c)
83 target_link_libraries(imp_mod1 exp_testExe2)
84
85 add_library(imp_ExePlugin1 MODULE ../../../InterfaceLinkLibrariesDirect/ExePlugin.c)
86 target_link_libraries(imp_ExePlugin1 PRIVATE exp_testExeWithPluginHelper testExePluginHelperExclude)
87
88 # Try referencing an executable imported from the build tree.
89 add_custom_command(
90   OUTPUT ${Import_BINARY_DIR}/bld_generated.c
91   COMMAND bld_testExe1 ${Import_BINARY_DIR}/bld_generated.c
92   DEPENDS bld_testExe1
93   )
94 add_custom_command(
95   OUTPUT ${Import_BINARY_DIR}/bld_generated3.c
96   COMMAND bld_testExe3 ${Import_BINARY_DIR}/bld_generated3.c
97   DEPENDS bld_testExe3
98   )
99 add_custom_command(
100   OUTPUT ${Import_BINARY_DIR}/bld_generated4.c
101   COMMAND bld_testExe4 ${Import_BINARY_DIR}/bld_generated4.c
102   DEPENDS bld_testExe4
103   )
104
105 add_executable(imp_testExe1b
106   imp_testExe1.c
107   ${Import_BINARY_DIR}/bld_generated.c
108   ${Import_BINARY_DIR}/bld_generated3.c
109   ${Import_BINARY_DIR}/bld_generated4.c
110   )
111
112 # Try linking to a library imported from the build tree.
113 target_link_libraries(imp_testExe1b
114   bld_testLib2
115   bld_testLib3
116   bld_testLib4
117   bld_testLib5
118   bld_testLib6
119   bld_testLib7
120   bld_testLibCycleA
121   bld_testLibPerConfigDest
122   bld_testStaticLibWithPlugin
123   )
124
125 add_library(imp_testInterfaceInclude1b STATIC imp_testInterfaceInclude1.c)
126 target_include_directories(imp_testInterfaceInclude1b SYSTEM PRIVATE testInterfaceIncludeSystem)
127 target_link_libraries(imp_testInterfaceInclude1b PRIVATE bld_testInterfaceIncludeUser)
128
129 add_custom_target(check_testLib1_genex ALL
130   COMMAND ${CMAKE_COMMAND} -DtestLib1=$<TARGET_FILE:exp_testLib1>
131                            -Dprefix=${CMAKE_INSTALL_PREFIX}
132           -P ${CMAKE_CURRENT_SOURCE_DIR}/check_testLib1_genex.cmake
133   )
134
135 if(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG AND
136     "${CMAKE_C_CREATE_SHARED_MODULE}" MATCHES "SONAME_FLAG")
137   foreach(ns exp bld)
138     get_property(configs TARGET ${ns}_testLib5 PROPERTY IMPORTED_CONFIGURATIONS)
139     foreach(c ${configs})
140       string(TOUPPER "${c}" CONFIG)
141       get_property(soname TARGET ${ns}_testLib5 PROPERTY IMPORTED_NO_SONAME_${CONFIG})
142       if(soname)
143         message(SEND_ERROR "${ns}_testLib5 has IMPORTED_NO_SONAME_${CONFIG} but should:\n  ${soname}")
144       else()
145         message(STATUS "${ns}_testLib5 does not have IMPORTED_NO_SONAME_${CONFIG} as expected")
146       endif()
147     endforeach()
148
149     get_property(configs TARGET ${ns}_testLibNoSONAME PROPERTY IMPORTED_CONFIGURATIONS)
150     foreach(c ${configs})
151       string(TOUPPER "${c}" CONFIG)
152       get_property(soname TARGET ${ns}_testLibNoSONAME PROPERTY IMPORTED_NO_SONAME_${CONFIG})
153       if(soname)
154         message(STATUS "${ns}_testLibNoSONAME has IMPORTED_NO_SONAME_${CONFIG} as expected")
155       else()
156         message(SEND_ERROR "${ns}_testLibNoSONAME does not have IMPORTED_NO_SONAME_${CONFIG} but should")
157       endif()
158     endforeach()
159
160     # Parse the binary to check for SONAME if possible.
161     if("${CMAKE_EXECUTABLE_FORMAT}" MATCHES "ELF")
162       find_program(READELF_EXE readelf)
163       if(READELF_EXE)
164         add_custom_target(check_${ns}_testLib5_soname ALL COMMAND
165           ${CMAKE_COMMAND} -Dreadelf=${READELF_EXE}
166           -Dlib=$<TARGET_FILE:${ns}_testLib5>
167           -P ${CMAKE_CURRENT_SOURCE_DIR}/check_lib_soname.cmake
168           )
169         add_custom_target(check_${ns}_testLibNoSONAME_soname ALL COMMAND
170           ${CMAKE_COMMAND} -Dreadelf=${READELF_EXE}
171           -Dlib=$<TARGET_FILE:${ns}_testLibNoSONAME>
172           -P ${CMAKE_CURRENT_SOURCE_DIR}/check_lib_nosoname.cmake
173           )
174       endif()
175     endif()
176   endforeach()
177 endif()
178
179 add_executable(cmp0022OLD_test cmp0022OLD_test_vs6_1.cpp)
180 target_link_libraries(cmp0022OLD_test bld_cmp0022OLD)
181 add_executable(cmp0022NEW_test cmp0022NEW_test_vs6_1.cpp)
182 target_link_libraries(cmp0022NEW_test bld_cmp0022NEW)
183
184 add_executable(cmp0022OLD_exp_test cmp0022OLD_test_vs6_2.cpp)
185 target_link_libraries(cmp0022OLD_exp_test exp_cmp0022OLD)
186 add_executable(cmp0022NEW_exp_test cmp0022NEW_test_vs6_2.cpp)
187 target_link_libraries(cmp0022NEW_exp_test exp_cmp0022NEW)
188
189 add_executable(SubDirLink_bld SubDirLink.c)
190 target_link_libraries(SubDirLink_bld PRIVATE bld_TopDirLib bld_SubDirLinkA)
191 add_executable(SubDirLink_exp SubDirLink.c)
192 target_link_libraries(SubDirLink_exp PRIVATE exp_TopDirLib exp_SubDirLinkA)
193
194 add_executable(imp_UseSharedLibWithHelper1b ../../../InterfaceLinkLibrariesDirect/UseSharedLibWithHelper.c)
195 target_link_libraries(imp_UseSharedLibWithHelper1b PRIVATE bld_testSharedLibWithHelper testSharedLibHelperExclude)
196
197 # Try building a plugin to an executable imported from the build tree.
198 add_library(imp_mod1b MODULE imp_mod1.c)
199 target_link_libraries(imp_mod1b bld_testExe2)
200
201 add_library(imp_ExePlugin1b MODULE ../../../InterfaceLinkLibrariesDirect/ExePlugin.c)
202 target_link_libraries(imp_ExePlugin1b PRIVATE bld_testExeWithPluginHelper testExePluginHelperExclude)
203
204 # Export/CMakeLists.txt pretends the RelWithDebInfo (as well as Debug)
205 # configuration should link to debug libs.
206 foreach(c DEBUG RELWITHDEBINFO)
207   set_property(TARGET imp_testExe1 PROPERTY COMPILE_DEFINITIONS_${c} EXE_DBG)
208   set_property(TARGET imp_testExe1b PROPERTY COMPILE_DEFINITIONS_${c} EXE_DBG)
209 endforeach()
210
211 #-----------------------------------------------------------------------------
212 include(${CMAKE_INSTALL_PREFIX}/lib/expAbs/expAbs.cmake)
213
214 add_executable(imp_testExeAbs1
215   imp_testExeAbs1.c
216   )
217 target_link_libraries(imp_testExeAbs1
218   expAbs_testLibAbs1
219   )
220
221 #-----------------------------------------------------------------------------
222 # Create a custom target to generate a header for the libraries below.
223 # Drive the header generation through an indirect chain of imported
224 # target dependencies.
225
226 # testLib2tmp1.h
227 add_custom_command(
228   OUTPUT testLib2tmp1.h
229   VERBATIM COMMAND
230     ${CMAKE_COMMAND} -E echo "extern int testLib2(void);" > testLib2tmp1.h
231   )
232
233 # hdr_testLib2tmp1 needs testLib2tmp1.h
234 add_custom_target(hdr_testLib2tmp1 DEPENDS testLib2tmp1.h)
235
236 # exp_testExe2 needs hdr_testLib2tmp1
237 add_dependencies(exp_testExe2 hdr_testLib2tmp1)
238
239 # testLib2tmp.h needs exp_testExe2
240 add_custom_command(
241   OUTPUT testLib2tmp.h
242   VERBATIM COMMAND exp_testExe2
243   COMMAND ${CMAKE_COMMAND} -E copy testLib2tmp1.h testLib2tmp.h
244   )
245
246 # hdr_testLib2tmp needs testLib2tmp.h
247 add_custom_target(hdr_testLib2tmp DEPENDS testLib2tmp.h)
248
249 add_library(dep_testLib2tmp UNKNOWN IMPORTED)
250 set_property(TARGET dep_testLib2tmp PROPERTY
251   IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/testLib2tmp.h)
252
253 # dep_testLib2tmp needs hdr_testLib2tmp
254 add_dependencies(dep_testLib2tmp hdr_testLib2tmp)
255
256 # testLib2.h needs dep_testLib2tmp
257 add_custom_command(
258   OUTPUT testLib2.h
259   VERBATIM COMMAND ${CMAKE_COMMAND} -E copy testLib2tmp.h testLib2.h
260   DEPENDS dep_testLib2tmp
261   )
262
263 # hdr_testLib2 needs testLib2.h
264 add_custom_target(hdr_testLib2 DEPENDS testLib2.h)
265
266 add_library(dep_testLib2 UNKNOWN IMPORTED)
267
268 # dep_testLib2 needs hdr_testLib2
269 add_dependencies(dep_testLib2 hdr_testLib2)
270
271 # exp_testLib2 and bld_testLib2 both need dep_testLib2
272 add_dependencies(bld_testLib2 dep_testLib2)
273 add_dependencies(exp_testLib2 dep_testLib2)
274
275 #-----------------------------------------------------------------------------
276 # Create a library to be linked by another directory in this project
277 # to test transitive linking to otherwise invisible imported targets.
278 include_directories(${CMAKE_CURRENT_BINARY_DIR})
279 add_library(imp_lib1 STATIC imp_lib1.c)
280 target_link_libraries(imp_lib1 exp_testLib2)
281 add_library(imp_lib1b STATIC imp_lib1.c)
282 target_link_libraries(imp_lib1b bld_testLib2)
283
284 if(NOT CMAKE_GENERATOR STREQUAL "Xcode" OR NOT CMAKE_OSX_ARCHITECTURES MATCHES "[;$]")
285   set(bld_objlib_type OBJECT_LIBRARY)
286
287   # Create executables using objects imported from the install tree
288   add_executable(imp_testLib8_src imp_testLib8.c $<TARGET_OBJECTS:exp_testLib8>)
289   add_executable(imp_testLib8_link imp_testLib8.c)
290   target_link_libraries(imp_testLib8_link exp_testLib8)
291
292   if(NOT CMAKE_GENERATOR STREQUAL "Xcode" OR NOT XCODE_VERSION VERSION_LESS 5)
293     # Create executables using objects imported from the build tree
294     add_executable(imp_testLib8b_src imp_testLib8.c $<TARGET_OBJECTS:bld_testLib8>)
295     add_executable(imp_testLib8b_link imp_testLib8.c)
296     target_link_libraries(imp_testLib8b_link bld_testLib8)
297   endif()
298 else()
299   set(bld_objlib_type INTERFACE_LIBRARY)
300 endif()
301
302 # Create an executable that uses a library imported from the install tree
303 # that itself was built using an object library.  Verify we get the usage
304 # requirements.
305 add_executable(imp_testLib9 imp_testLib9.c)
306 target_link_libraries(imp_testLib9 exp_testLib9)
307 # Similarly for importing from the build tree.
308 add_executable(imp_testLib9b imp_testLib9.c)
309 target_link_libraries(imp_testLib9b bld_testLib9)
310
311 # Check that object libraries were transformed on export as expected.
312 foreach(vis Pub Priv Iface)
313   get_property(type TARGET exp_testLib9Obj${vis} PROPERTY TYPE)
314   if(NOT type STREQUAL INTERFACE_LIBRARY)
315     message(FATAL_ERROR "exp_testLib9Obj${vis} type is '${type}', not 'INTERFACE_LIBRARY'")
316   endif()
317   get_property(type TARGET bld_testLib9Obj${vis} PROPERTY TYPE)
318   if(NOT type STREQUAL "${bld_objlib_type}")
319     message(FATAL_ERROR "bld_testLib9Obj${vis} type is '${type}', not '${bld_objlib_type}'")
320   endif()
321 endforeach()
322
323 #-----------------------------------------------------------------------------
324 # Test that handling imported targets, including transitive dependencies,
325 # works in CheckFunctionExists (...and hopefully all other try_compile() checks
326 include(CheckFunctionExists)
327 unset(HAVE_TESTLIB1_FUNCTION CACHE)
328 set(CMAKE_REQUIRED_LIBRARIES exp_testLib2)
329 check_function_exists(testLib1 HAVE_TESTLIB1_FUNCTION)
330 if (NOT HAVE_TESTLIB1_FUNCTION)
331   message(SEND_ERROR "Using imported target testLib2 in check_function_exists() failed !")
332 endif()
333
334 #-----------------------------------------------------------------------------
335 # Test that dependent imported targets have usable
336 # INTERFACE_COMPILE_DEFINITIONS and INTERFACE_INCLUDE_DIRECTORIES
337
338 add_executable(deps_iface deps_iface.c)
339 target_link_libraries(deps_iface testLibDepends)
340
341 add_executable(deps_shared_iface deps_shared_iface.cpp)
342 target_link_libraries(deps_shared_iface testSharedLibDepends)
343 target_compile_definitions(deps_shared_iface
344   PRIVATE
345     $<$<BOOL:$<TARGET_PROPERTY:POSITION_INDEPENDENT_CODE>>:PIC_PROPERTY_IS_ON>
346     $<$<BOOL:$<TARGET_PROPERTY:CUSTOM_PROP>>:CUSTOM_PROPERTY_IS_ON>
347     $<$<STREQUAL:$<TARGET_PROPERTY:CUSTOM_STRING>,testcontent>:CUSTOM_STRING_IS_MATCH>
348 )
349
350 if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "LCC")
351   target_compile_definitions(deps_shared_iface
352     PRIVATE
353       "DO_GNU_TESTS"
354   )
355 endif()
356
357 if (APPLE OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "LCC")
358   include(CheckCXXCompilerFlag)
359   check_cxx_compiler_flag(-fPIE run_pic_test)
360 else()
361   if (CMAKE_CXX_COMPILER_ID MATCHES "PGI"
362       OR CMAKE_CXX_COMPILER_ID MATCHES "PathScale"
363       OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
364     set(run_pic_test 0)
365   else()
366     set(run_pic_test 1)
367   endif()
368 endif()
369
370 add_executable(exp_renamed_test renamed_test.cpp)
371 target_link_libraries(exp_renamed_test exp_renamed)
372
373 add_executable(bld_renamed_test renamed_test.cpp)
374 target_link_libraries(bld_renamed_test bld_renamed)
375
376 if (run_pic_test)
377   target_compile_definitions(deps_shared_iface PRIVATE CHECK_PIC_WORKS)
378 endif()
379
380 if(APPLE)
381   add_subdirectory(framework_interface)
382 endif()
383
384 #-----------------------------------------------------------------------------
385 # Test that targets imported from the build tree have their dependencies
386 # evaluated correctly. The above already tests the same for the install tree.
387
388 add_executable(deps_shared_iface2 deps_shared_iface.cpp)
389 target_link_libraries(deps_shared_iface2 bld_testSharedLibDepends bld_subdirlib)
390 if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "LCC")
391   target_compile_definitions(deps_shared_iface2
392     PRIVATE
393       "DO_GNU_TESTS"
394   )
395 endif()
396 target_compile_definitions(deps_shared_iface2
397   PRIVATE TEST_SUBDIR_LIB
398   $<$<BOOL:$<TARGET_PROPERTY:POSITION_INDEPENDENT_CODE>>:PIC_PROPERTY_IS_ON>
399   $<$<BOOL:$<TARGET_PROPERTY:CUSTOM_PROP>>:CUSTOM_PROPERTY_IS_ON>
400   $<$<STREQUAL:$<TARGET_PROPERTY:CUSTOM_STRING>,testcontent>:CUSTOM_STRING_IS_MATCH>
401 )
402
403 add_subdirectory(excludedFromAll)
404
405 add_executable(iface_test_bld iface_test.cpp)
406 target_link_libraries(iface_test_bld bld_testSharedLibDepends)
407 set_property(TARGET iface_test_bld PROPERTY NO_SYSTEM_FROM_IMPORTED 1)
408
409 set_property(TARGET bld_testSharedLibRequired APPEND PROPERTY
410     LINK_INTERFACE_LIBRARIES
411         excludedFromAll
412 )
413 get_target_property(_configs bld_testSharedLibRequired IMPORTED_CONFIGURATIONS)
414 foreach(_config ${_configs})
415     set_property(TARGET bld_testSharedLibRequired APPEND PROPERTY
416         IMPORTED_LINK_INTERFACE_LIBRARIES_${_config}
417         excludedFromAll
418     )
419 endforeach()
420 unset(_configs)
421 add_executable(iface_test_exp iface_test.cpp)
422 target_link_libraries(iface_test_exp testSharedLibDepends)
423
424 set_property(TARGET testSharedLibDepends APPEND PROPERTY
425     LINK_INTERFACE_LIBRARIES
426         excludedFromAll
427 )
428 get_target_property(_configs testSharedLibDepends IMPORTED_CONFIGURATIONS)
429 foreach(_config ${_configs})
430     set_property(TARGET testSharedLibDepends APPEND PROPERTY
431         IMPORTED_LINK_INTERFACE_LIBRARIES_${_config}
432         excludedFromAll
433     )
434 endforeach()
435 unset(_configs)
436
437 if (((CMAKE_C_COMPILER_ID STREQUAL GNU AND CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.4)
438     OR CMAKE_C_COMPILER_ID MATCHES "LCC"
439     OR (CMAKE_C_COMPILER_ID STREQUAL Clang AND NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC"))
440     AND (CMAKE_GENERATOR STREQUAL "Unix Makefiles" OR CMAKE_GENERATOR STREQUAL "Ninja"))
441   include(CheckCXXCompilerFlag)
442   check_cxx_compiler_flag(-Wunused-variable run_sys_includes_test)
443   if(run_sys_includes_test)
444     # The Bullseye wrapper appears to break the -isystem effect.
445     execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version OUTPUT_VARIABLE out ERROR_VARIABLE out)
446     if("x${out}" MATCHES "Bullseye")
447       set(run_sys_includes_test 0)
448     endif()
449   endif()
450   if (run_sys_includes_test)
451     add_executable(test_system_exp test_system.cpp)
452     target_link_libraries(test_system_exp exp_systemlib)
453     target_compile_options(test_system_exp PRIVATE -Wunused-variable -Werror=unused-variable)
454
455     unset(EXP_ERROR_VARIABLE CACHE)
456     try_compile(EXP_ERROR_VARIABLE
457       "${CMAKE_CURRENT_SOURCE_DIR}/test_system"
458       "${CMAKE_CURRENT_SOURCE_DIR}/test_system.cpp"
459       COMPILE_DEFINITIONS "-Wunused-variable -Werror=unused-variable"
460       LINK_LIBRARIES exp_systemlib
461       OUTPUT_VARIABLE OUTPUT
462       )
463     if(NOT EXP_ERROR_VARIABLE)
464       message(SEND_ERROR "EXP_ERROR_VARIABLE try_compile failed, but it was expected to succeed ${OUTPUT}.")
465     endif()
466
467     if(NOT CMAKE_CROSSCOMPILING)
468       unset(EXP_RUN_VAR CACHE)
469       unset(EXP_COMPILE_VAR CACHE)
470       try_run(EXP_RUN_VAR EXP_COMPILE_VAR
471         "${CMAKE_CURRENT_SOURCE_DIR}/test_system"
472         "${CMAKE_CURRENT_SOURCE_DIR}/test_system.cpp"
473         COMPILE_DEFINITIONS "-Wunused-variable -Werror=unused-variable"
474         LINK_LIBRARIES exp_systemlib
475         OUTPUT_VARIABLE OUTPUT
476         )
477       if(NOT EXP_COMPILE_VAR)
478         message(SEND_ERROR "try_run compile failed, but it was expected to succeed ${OUTPUT}.")
479       endif()
480     endif()
481
482     add_executable(test_system_bld test_system.cpp)
483     target_link_libraries(test_system_bld bld_systemlib)
484     target_compile_options(test_system_bld PRIVATE -Wunused-variable -Werror=unused-variable)
485
486     unset(BLD_ERROR_VARIABLE CACHE)
487     try_compile(BLD_ERROR_VARIABLE
488       "${CMAKE_CURRENT_SOURCE_DIR}/test_system"
489       "${CMAKE_CURRENT_SOURCE_DIR}/test_system.cpp"
490       COMPILE_DEFINITIONS "-Wunused-variable -Werror=unused-variable"
491       LINK_LIBRARIES bld_systemlib
492       OUTPUT_VARIABLE OUTPUT
493       )
494     if(NOT BLD_ERROR_VARIABLE)
495       message(SEND_ERROR "BLD_ERROR_VARIABLE try_compile failed, but it was expected to succeed.")
496     endif()
497
498     if(NOT CMAKE_CROSSCOMPILING)
499       unset(BLD_RUN_VAR CACHE)
500       unset(BLD_COMPILE_VAR CACHE)
501       try_run(BLD_RUN_VAR BLD_COMPILE_VAR
502         "${CMAKE_CURRENT_SOURCE_DIR}/test_system"
503         "${CMAKE_CURRENT_SOURCE_DIR}/test_system.cpp"
504         COMPILE_DEFINITIONS "-Wunused-variable -Werror=unused-variable"
505         LINK_LIBRARIES bld_systemlib
506         OUTPUT_VARIABLE OUTPUT
507         )
508       if(NOT BLD_COMPILE_VAR)
509         message(SEND_ERROR "try_run compile failed, but it was expected to succeed ${OUTPUT}.")
510       endif()
511     endif()
512   endif()
513 endif()
514
515 #---------------------------------------------------------------------------------
516 # check that imported libraries have the expected INTERFACE_LINK_OPTIONS property
517 checkForProperty(bld_testLinkOptions "INTERFACE_LINK_OPTIONS" "INTERFACE_FLAG")
518 checkForProperty(Req::testLinkOptions "INTERFACE_LINK_OPTIONS" "INTERFACE_FLAG")
519
520 #---------------------------------------------------------------------------------
521 # check that imported libraries have the expected INTERFACE_LINK_DIRECTORIES property
522 checkForProperty(bld_testLinkDirectories "INTERFACE_LINK_DIRECTORIES" "/interface/build")
523 checkForProperty(Req::testLinkDirectories "INTERFACE_LINK_DIRECTORIES" "${CMAKE_INSTALL_PREFIX}/interface/install")
524
525 #---------------------------------------------------------------------------------
526 # check that imported libraries have the expected INTERFACE_LINK_DEPENDS property
527 if(CMAKE_GENERATOR MATCHES "Make|Ninja")
528   checkForProperty(bld_testLinkDepends "INTERFACE_LINK_DEPENDS" "BUILD_LINK_DEPENDS")
529   checkForProperty(Req::testLinkDepends "INTERFACE_LINK_DEPENDS" "${CMAKE_INSTALL_PREFIX}/INSTALL_LINK_DEPENDS")
530 endif()
531
532 #------------------------------------------------------------------------------
533 # test import of CUDA language level
534 if(CMake_TEST_CUDA)
535   checkForProperty(bld_cudaInterfaceLib "INTERFACE_COMPILE_FEATURES" "cuda_std_11")
536   checkForProperty(Req::cudaInterfaceLib "INTERFACE_COMPILE_FEATURES" "cuda_std_14")
537 endif()