CMakeLists.txt 17 KB

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