CMakeLists.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. cmake_minimum_required (VERSION 2.8.8)
  2. project(GeneratorExpression)
  3. include(CTest)
  4. # This test is split into multiple parts as needed to avoid NMake command
  5. # length limits.
  6. add_custom_target(check-part1 ALL
  7. COMMAND ${CMAKE_COMMAND}
  8. -Dtest_0=$<0:nothing>
  9. -Dtest_0_with_comma=$<0:-Wl,--no-undefined>
  10. -Dtest_1=$<1:content>
  11. -Dtest_1_with_comma=$<1:-Wl,--no-undefined>
  12. -Dconfig=$<CONFIGURATION>
  13. -Dshort_config=$<CONFIG>
  14. -Dtest_and_0=$<AND:0>
  15. -Dtest_and_0_0=$<AND:0,0>
  16. -Dtest_and_0_1=$<AND:0,1>
  17. -Dtest_and_1=$<AND:1>
  18. -Dtest_and_1_0=$<AND:1,0>
  19. -Dtest_and_1_1=$<AND:1,1>
  20. # Ordinarily, the 'invalidcontent' would cause an error, but
  21. # the '0' makes the AND abort early.
  22. -Dtest_and_0_invalidcontent=$<AND:0,invalidcontent>
  23. -Dtest_config_0=$<CONFIG:$<CONFIGURATION>x>
  24. -Dtest_config_1=$<CONFIG:$<CONFIGURATION>>
  25. -Dtest_config_debug=$<CONFIG:Debug>$<CONFIG:DEBUG>$<CONFIG:DeBuG>
  26. -Dtest_config_release=$<CONFIG:Release>$<CONFIG:RELEASE>$<CONFIG:ReLeAsE>
  27. -Dtest_config_relwithdebinfo=$<CONFIG:RelWithDebInfo>$<CONFIG:RELWITHDEBINFO>$<CONFIG:relwithdebinfo>
  28. -Dtest_config_minsizerel=$<CONFIG:MinSizeRel>$<CONFIG:MINSIZEREL>$<CONFIG:minsizerel>
  29. -Dtest_not_0=$<NOT:0>
  30. -Dtest_not_1=$<NOT:1>
  31. -Dtest_or_0=$<OR:0>
  32. -Dtest_or_0_0=$<OR:0,0>
  33. -Dtest_or_0_1=$<OR:0,1>
  34. -Dtest_or_1=$<OR:1>
  35. -Dtest_or_1_0=$<OR:1,0>
  36. -Dtest_or_1_1=$<OR:1,1>
  37. -Dtest_or_1_invalidcontent=$<OR:1,invalidcontent>
  38. -Dtest_bool_notfound=$<BOOL:NOTFOUND>
  39. -Dtest_bool_foo_notfound=$<BOOL:Foo-NOTFOUND>
  40. -Dtest_bool_true=$<BOOL:True>
  41. -Dtest_bool_false=$<BOOL:False>
  42. -Dtest_bool_on=$<BOOL:On>
  43. -Dtest_bool_off=$<BOOL:Off>
  44. -Dtest_bool_no=$<BOOL:No>
  45. -Dtest_bool_n=$<BOOL:N>
  46. -Dtest_bool_empty=$<BOOL:>
  47. -Dtest_strequal_yes_yes=$<STREQUAL:Yes,Yes>
  48. -Dtest_strequal_yes_yes_cs=$<STREQUAL:Yes,yes>
  49. -Dtest_strequal_yes_no=$<STREQUAL:Yes,No>
  50. -Dtest_strequal_no_yes=$<STREQUAL:No,Yes>
  51. -Dtest_strequal_angle_r=$<STREQUAL:$<ANGLE-R>,$<ANGLE-R>>
  52. -Dtest_strequal_comma=$<STREQUAL:$<COMMA>,$<COMMA>>
  53. -Dtest_strequal_semicolon=$<STREQUAL:$<SEMICOLON>,$<SEMICOLON>>
  54. -Dtest_strequal_angle_r_comma=$<STREQUAL:$<ANGLE-R>,$<COMMA>>
  55. -Dtest_strequal_both_empty=$<STREQUAL:,>
  56. -Dtest_strequal_one_empty=$<STREQUAL:something,>
  57. -Dtest_angle_r=$<ANGLE-R>
  58. -Dtest_comma=$<COMMA>
  59. -Dtest_semicolon=$<SEMICOLON>
  60. -Dtest_colons_1=$<1::>
  61. -Dtest_colons_2=$<1:::>
  62. -Dtest_colons_3=$<1:Qt5::Core>
  63. -Dtest_colons_4=$<1:C:\\CMake>
  64. -Dtest_colons_5=$<1:C:/CMake>
  65. -P ${CMAKE_CURRENT_SOURCE_DIR}/check-part1.cmake
  66. COMMAND ${CMAKE_COMMAND} -E echo "check done (part 1 of 3)"
  67. VERBATIM
  68. )
  69. add_library(empty1 empty.cpp)
  70. target_include_directories(empty1 PUBLIC /empty1/public)
  71. target_include_directories(empty1 PRIVATE /empty1/private)
  72. add_library(empty2 empty.cpp)
  73. target_include_directories(empty2 PUBLIC /empty2/public)
  74. add_library(empty3 empty.cpp)
  75. target_include_directories(empty3 PUBLIC /empty3/public)
  76. target_include_directories(empty3 PRIVATE /empty3/private)
  77. add_library(empty4 empty.cpp)
  78. target_include_directories(empty4 PUBLIC /empty4/public)
  79. target_link_libraries(empty1 LINK_PUBLIC empty2)
  80. target_link_libraries(empty2 LINK_PUBLIC empty3 empty4)
  81. target_link_libraries(empty3 LINK_PUBLIC empty2 empty4)
  82. add_library(empty5 empty.cpp)
  83. target_include_directories(empty5 PRIVATE /empty5/private1 /empty5/private2)
  84. add_custom_target(check-part2 ALL
  85. COMMAND ${CMAKE_COMMAND}
  86. -Dtest_incomplete_1=$<
  87. -Dtest_incomplete_2=$<something
  88. -Dtest_incomplete_3=$<something:
  89. -Dtest_incomplete_4=$<something:,
  90. -Dtest_incomplete_5=$something:,>
  91. -Dtest_incomplete_6=<something:,>
  92. -Dtest_incomplete_7=$<something::
  93. -Dtest_incomplete_8=$<something:,
  94. -Dtest_incomplete_9=$<something:,,
  95. -Dtest_incomplete_10=$<something:,:
  96. -Dtest_incomplete_11=$<something,,
  97. -Dtest_incomplete_12=$<,,
  98. -Dtest_incomplete_13=$<some$<1:special>thing
  99. -Dtest_incomplete_14=$<$<ANGLE-R>
  100. -Dtest_incomplete_15=$<some$<thing
  101. -Dtest_incomplete_16=$<BOOL:something
  102. -Dtest_incomplete_17=$<1:some$thing>
  103. -Dtest_incomplete_18=$<1:some,thing
  104. -Dtest_incomplete_19=$<1:some,thing$<ANGLE-R>
  105. -Dtest_incomplete_20=$<CONFIGURATION$<ANGLE-R>
  106. -Dtest_incomplete_21=$<BOOL:something$<ANGLE-R>
  107. -Dtest_build_interface=$<BUILD_INTERFACE:build>
  108. -Dtest_install_interface=$<INSTALL_INTERFACE:install>
  109. -Dtest_target_name_1=$<TARGET_NAME:tgt,ok>
  110. -Dtest_target_name_2=$<TARGET_NAME:tgt:ok>
  111. -Dtest_target_includes1=$<TARGET_PROPERTY:empty1,INTERFACE_INCLUDE_DIRECTORIES>
  112. -Dtest_target_includes2=$<TARGET_PROPERTY:empty2,INTERFACE_INCLUDE_DIRECTORIES>
  113. -Dtest_target_includes3=$<TARGET_PROPERTY:empty3,INTERFACE_INCLUDE_DIRECTORIES>
  114. -Dtest_target_includes4=$<TARGET_PROPERTY:empty1,INCLUDE_DIRECTORIES>
  115. -Dtest_target_includes5=$<TARGET_PROPERTY:empty2,INCLUDE_DIRECTORIES>
  116. -Dtest_target_includes6=$<TARGET_PROPERTY:empty3,INCLUDE_DIRECTORIES>
  117. -Dtest_target_includes7=$<TARGET_PROPERTY:empty1,INTERFACE_INCLUDE_DIRECTORIES>
  118. -Dtest_target_includes8=$<TARGET_PROPERTY:empty5,INCLUDE_DIRECTORIES>
  119. -Dtest_arbitrary_content_comma_1=$<1:a,>
  120. -Dtest_arbitrary_content_comma_2=$<1:,a>
  121. -Dtest_arbitrary_content_comma_3=$<1:a,,>
  122. -Dtest_arbitrary_content_comma_4=$<1:,>
  123. -Dtest_arbitrary_content_comma_5=$<1:,,>
  124. -Dtest_arbitrary_content_comma_6=$<1:,,,>
  125. -Dtest_arbitrary_content_comma_7=$<1:,,a>
  126. -Dtest_arbitrary_content_comma_8=$<1:a,,b>
  127. -Dtest_arbitrary_content_comma_9=$<1:a,,b,,>
  128. -Dtest_arbitrary_content_comma_10=$<1:,,a,,b,,>
  129. -P ${CMAKE_CURRENT_SOURCE_DIR}/check-part2.cmake
  130. COMMAND ${CMAKE_COMMAND} -E echo "check done (part 2 of 3)"
  131. VERBATIM
  132. )
  133. add_library(imported1 SHARED IMPORTED)
  134. set_property(TARGET imported1 PROPERTY IMPORTED_LOCATION_RELEASE release_loc)
  135. set_property(TARGET imported1 PROPERTY IMPORTED_LOCATION_DEBUG debug_loc)
  136. set_property(TARGET imported1 PROPERTY IMPORTED_CONFIGURATIONS RELEASE DEBUG)
  137. set_property(TARGET imported1 PROPERTY INTERFACE_INCLUDE_DIRECTORIES /imported1/include)
  138. add_library(imported2 SHARED IMPORTED)
  139. set_property(TARGET imported2 PROPERTY IMPORTED_LOCATION_RELEASE release_loc)
  140. set_property(TARGET imported2 PROPERTY IMPORTED_LOCATION_DEBUG debug_loc)
  141. set_property(TARGET imported2 PROPERTY IMPORTED_CONFIGURATIONS RELEASE DEBUG)
  142. set_property(TARGET imported2 PROPERTY INTERFACE_INCLUDE_DIRECTORIES /imported2/include)
  143. add_library(imported3 SHARED IMPORTED)
  144. set_property(TARGET imported3 PROPERTY IMPORTED_LOCATION_RELEASE release_loc)
  145. set_property(TARGET imported3 PROPERTY IMPORTED_LOCATION_DEBUG debug_loc)
  146. # Both Debug and Release should not be true when this is evaluated.
  147. set_property(TARGET imported3 APPEND PROPERTY
  148. INTERFACE_INCLUDE_DIRECTORIES $<$<CONFIG:DEBUG>:$<TARGET_PROPERTY:imported1,INTERFACE_INCLUDE_DIRECTORIES>>)
  149. set_property(TARGET imported3 APPEND PROPERTY
  150. INTERFACE_INCLUDE_DIRECTORIES $<$<CONFIG:RELEASE>:$<TARGET_PROPERTY:imported2,INTERFACE_INCLUDE_DIRECTORIES>>)
  151. add_library(imported4 SHARED IMPORTED)
  152. set_property(TARGET imported4 APPEND PROPERTY
  153. INCLUDE_DIRECTORIES $<TARGET_PROPERTY:imported3,INTERFACE_INCLUDE_DIRECTORIES>)
  154. add_executable(someexe empty.cpp)
  155. add_executable(Alias::SomeExe ALIAS someexe)
  156. add_library(Alias::SomeLib ALIAS empty1)
  157. add_custom_target(check-part3 ALL
  158. COMMAND ${CMAKE_COMMAND}
  159. -Dtest_version_greater_1=$<VERSION_GREATER:1.0,1.1.1>
  160. -Dtest_version_greater_2=$<VERSION_GREATER:1.1.1,1.0>
  161. -Dtest_version_less_1=$<VERSION_LESS:1.1.1,1.0>
  162. -Dtest_version_less_2=$<VERSION_LESS:1.0,1.1.1>
  163. -Dtest_version_equal_1=$<VERSION_EQUAL:1.0.1,1.1>
  164. -Dtest_version_equal_2=$<VERSION_EQUAL:1.1,1.1>
  165. -Dconfig=$<CONFIGURATION>
  166. -Dtest_imported_debug=$<TARGET_PROPERTY:imported4,INCLUDE_DIRECTORIES>
  167. -Dtest_imported_release=$<TARGET_PROPERTY:imported4,INCLUDE_DIRECTORIES>
  168. -Dtest_imported_relwithdebinfo=$<TARGET_PROPERTY:imported4,INCLUDE_DIRECTORIES>
  169. -Dtest_imported_minsizerel=$<TARGET_PROPERTY:imported4,INCLUDE_DIRECTORIES>
  170. -Dtest_alias_file_exe=$<STREQUAL:$<TARGET_FILE:Alias::SomeExe>,$<TARGET_FILE:someexe>>
  171. -Dtest_alias_file_lib=$<STREQUAL:$<TARGET_FILE:Alias::SomeLib>,$<TARGET_FILE:empty1>>
  172. -Dtest_alias_target_name=$<STREQUAL:$<TARGET_PROPERTY:Alias::SomeLib,NAME>,$<TARGET_PROPERTY:empty1,NAME>>
  173. -Dtest_early_termination_1=$<$<1:>:
  174. -Dtest_early_termination_2=$<$<1:>:,
  175. -Dsystem_name=${CMAKE_HOST_SYSTEM_NAME}
  176. -Dtest_platform_id=$<PLATFORM_ID>
  177. -Dtest_platform_id_Linux=$<PLATFORM_ID:Linux>
  178. -Dtest_platform_id_Windows=$<PLATFORM_ID:Windows>
  179. -Dtest_platform_id_Darwin=$<PLATFORM_ID:Darwin>
  180. -Dlower_case=$<LOWER_CASE:Mi,XeD>
  181. -Dupper_case=$<UPPER_CASE:MiX,eD>
  182. -Dmake_c_identifier=$<MAKE_C_IDENTIFIER:4f,oo:+bar-$>
  183. -Dequal1=$<EQUAL:1,2>
  184. -Dequal2=$<EQUAL:1,1>
  185. -Dequal3=$<EQUAL:0x1,1>
  186. -Dequal4=$<EQUAL:0X1,2>
  187. -Dequal5=$<EQUAL:0xA,0xa>
  188. -Dequal6=$<EQUAL:0xA,10>
  189. -Dequal7=$<EQUAL:0xA,012>
  190. -Dequal8=$<EQUAL:10,012>
  191. -Dequal9=$<EQUAL:10,010>
  192. -Dequal10=$<EQUAL:10,0b1010>
  193. -Dequal11=$<EQUAL:-10,-0xa>
  194. -Dequal12=$<EQUAL:10,+0xa>
  195. -Dequal13=$<EQUAL:+10,+0Xa>
  196. -Dequal14=$<EQUAL:+10,0xa>
  197. -Dequal15=$<EQUAL:-10,-0Xa>
  198. -Dequal16=$<EQUAL:-10,-0b1010>
  199. -Dequal17=$<EQUAL:-10,+0b1010>
  200. -Dequal18=$<EQUAL:10,+0B1010>
  201. -Dequal19=$<EQUAL:10,-0B1010>
  202. -Dequal20=$<EQUAL:10,0B1010>
  203. -Dequal21=$<EQUAL:10,+012>
  204. -Dequal22=$<EQUAL:10,-012>
  205. -Dequal23=$<EQUAL:-10,-012>
  206. -P ${CMAKE_CURRENT_SOURCE_DIR}/check-part3.cmake
  207. COMMAND ${CMAKE_COMMAND} -E echo "check done (part 3 of 3)"
  208. VERBATIM
  209. )
  210. #-----------------------------------------------------------------------------
  211. # Cover test properties with generator expressions.
  212. add_executable(echo echo.c)
  213. add_executable(pwd pwd.c)
  214. add_test(NAME echo-configuration COMMAND echo $<CONFIGURATION>)
  215. set_property(TEST echo-configuration PROPERTY
  216. PASS_REGULAR_EXPRESSION "^$<CONFIGURATION>\n$")
  217. add_test(NAME echo-target-file COMMAND echo $<TARGET_FILE:echo>)
  218. set_property(TEST echo-target-file PROPERTY
  219. PASS_REGULAR_EXPRESSION "/echo${CMAKE_EXECUTABLE_SUFFIX}\n$")
  220. set_property(TEST echo-target-file PROPERTY
  221. REQUIRED_FILES "$<TARGET_FILE:echo>")
  222. add_test(NAME working-dir-arg
  223. WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/WorkingDirectory/$<CONFIGURATION>"
  224. COMMAND pwd)
  225. set_property(TEST working-dir-arg PROPERTY
  226. PASS_REGULAR_EXPRESSION "WorkingDirectory/$<CONFIGURATION>\n$")
  227. foreach(c ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE})
  228. file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/WorkingDirectory/${c}")
  229. endforeach()
  230. add_test(echo-old-style echo "\$<CONFIGURATION>")
  231. set_property(TEST echo-old-style PROPERTY
  232. PASS_REGULAR_EXPRESSION "^\\$<CONFIGURATION>\n$")