CMakeLists.txt 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. # Copyright (c) 2015-2016 The Khronos Group Inc.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # Add a SPIR-V Tools unit test. Signature:
  15. # add_spvtools_unittest(
  16. # TARGET target_name
  17. # SRCS src_file.h src_file.cpp
  18. # LIBS lib1 lib2
  19. # )
  20. if (NOT "${SPIRV_SKIP_TESTS}")
  21. if (TARGET gmock_main)
  22. message(STATUS "Found Google Mock, building tests.")
  23. else()
  24. message(STATUS "Did not find googletest, tests will not be built. "
  25. "To enable tests place googletest in '<spirv-dir>/external/googletest'.")
  26. endif()
  27. endif()
  28. function(add_spvtools_unittest)
  29. if (NOT "${SPIRV_SKIP_TESTS}" AND TARGET gmock_main)
  30. set(one_value_args TARGET PCH_FILE)
  31. set(multi_value_args SRCS LIBS ENVIRONMENT)
  32. cmake_parse_arguments(
  33. ARG "" "${one_value_args}" "${multi_value_args}" ${ARGN})
  34. set(target test_${ARG_TARGET})
  35. set(SRC_COPY ${ARG_SRCS})
  36. if (DEFINED ARG_PCH_FILE)
  37. spvtools_pch(SRC_COPY ${ARG_PCH_FILE})
  38. endif()
  39. add_executable(${target} ${SRC_COPY})
  40. spvtools_default_compile_options(${target})
  41. if(${COMPILER_IS_LIKE_GNU})
  42. target_compile_options(${target} PRIVATE -Wno-undef)
  43. # Effcee and RE2 headers exhibit shadowing.
  44. target_compile_options(${target} PRIVATE -Wno-shadow)
  45. endif()
  46. if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
  47. # Disable C4503 "decorated name length exceeded" warning,
  48. # triggered by some heavily templated types.
  49. # We don't care much about that in test code.
  50. # Important to do since we have warnings-as-errors.
  51. target_compile_options(${target} PRIVATE /wd4503)
  52. # Googletest accidentally turns off support for ::testing::Combine
  53. # in VS 2017. See https://github.com/google/googletest/issues/1352
  54. # Forcibly turn it on again.
  55. target_compile_options(${target} PRIVATE /DGTEST_HAS_COMBINE=1)
  56. endif()
  57. target_include_directories(${target} PRIVATE
  58. ${SPIRV_HEADER_INCLUDE_DIR}
  59. ${spirv-tools_SOURCE_DIR}
  60. ${spirv-tools_SOURCE_DIR}/include
  61. ${spirv-tools_SOURCE_DIR}/test
  62. ${spirv-tools_BINARY_DIR}
  63. ${gtest_SOURCE_DIR}/include
  64. ${gmock_SOURCE_DIR}/include
  65. )
  66. if (TARGET effcee)
  67. # If using Effcee for testing, then add its include directory.
  68. target_include_directories(${target} PRIVATE ${effcee_SOURCE_DIR})
  69. endif()
  70. target_link_libraries(${target} PRIVATE ${ARG_LIBS})
  71. if (TARGET effcee)
  72. target_link_libraries(${target} PRIVATE effcee)
  73. endif()
  74. target_link_libraries(${target} PRIVATE gmock_main)
  75. add_test(NAME spirv-tools-${target} COMMAND ${target})
  76. if (DEFINED ARG_ENVIRONMENT)
  77. set_tests_properties(spirv-tools-${target} PROPERTIES ENVIRONMENT ${ARG_ENVIRONMENT})
  78. endif()
  79. set_property(TARGET ${target} PROPERTY FOLDER "SPIRV-Tools tests")
  80. endif()
  81. endfunction()
  82. set(TEST_SOURCES
  83. test_fixture.h
  84. unit_spirv.h
  85. assembly_context_test.cpp
  86. assembly_format_test.cpp
  87. binary_destroy_test.cpp
  88. binary_endianness_test.cpp
  89. binary_header_get_test.cpp
  90. binary_parse_test.cpp
  91. binary_strnlen_s_test.cpp
  92. binary_to_text_test.cpp
  93. binary_to_text.literal_test.cpp
  94. comment_test.cpp
  95. diagnostic_test.cpp
  96. enum_string_mapping_test.cpp
  97. enum_set_test.cpp
  98. ext_inst.debuginfo_test.cpp
  99. ext_inst.glsl_test.cpp
  100. ext_inst.opencl_test.cpp
  101. fix_word_test.cpp
  102. generator_magic_number_test.cpp
  103. hex_float_test.cpp
  104. immediate_int_test.cpp
  105. libspirv_macros_test.cpp
  106. log_test.cpp
  107. named_id_test.cpp
  108. name_mapper_test.cpp
  109. opcode_make_test.cpp
  110. opcode_require_capabilities_test.cpp
  111. opcode_split_test.cpp
  112. opcode_table_get_test.cpp
  113. operand_capabilities_test.cpp
  114. operand_test.cpp
  115. operand_pattern_test.cpp
  116. parse_number_test.cpp
  117. preserve_numeric_ids_test.cpp
  118. software_version_test.cpp
  119. string_utils_test.cpp
  120. target_env_test.cpp
  121. text_advance_test.cpp
  122. text_destroy_test.cpp
  123. text_literal_test.cpp
  124. text_start_new_inst_test.cpp
  125. text_to_binary.annotation_test.cpp
  126. text_to_binary.barrier_test.cpp
  127. text_to_binary.constant_test.cpp
  128. text_to_binary.control_flow_test.cpp
  129. text_to_binary_test.cpp
  130. text_to_binary.debug_test.cpp
  131. text_to_binary.device_side_enqueue_test.cpp
  132. text_to_binary.extension_test.cpp
  133. text_to_binary.function_test.cpp
  134. text_to_binary.group_test.cpp
  135. text_to_binary.image_test.cpp
  136. text_to_binary.literal_test.cpp
  137. text_to_binary.memory_test.cpp
  138. text_to_binary.misc_test.cpp
  139. text_to_binary.mode_setting_test.cpp
  140. text_to_binary.pipe_storage_test.cpp
  141. text_to_binary.type_declaration_test.cpp
  142. text_to_binary.subgroup_dispatch_test.cpp
  143. text_to_binary.reserved_sampling_test.cpp
  144. text_word_get_test.cpp
  145. unit_spirv.cpp
  146. )
  147. spvtools_pch(TEST_SOURCES pch_test)
  148. add_spvtools_unittest(
  149. TARGET spirv_unit_tests
  150. SRCS ${TEST_SOURCES}
  151. LIBS ${SPIRV_TOOLS})
  152. add_spvtools_unittest(
  153. TARGET c_interface
  154. SRCS c_interface_test.cpp
  155. LIBS ${SPIRV_TOOLS})
  156. add_spvtools_unittest(
  157. TARGET c_interface_shared
  158. SRCS c_interface_test.cpp
  159. LIBS ${SPIRV_TOOLS}-shared
  160. ENVIRONMENT PATH=$<TARGET_FILE_DIR:${SPIRV_TOOLS}-shared>)
  161. add_spvtools_unittest(
  162. TARGET cpp_interface
  163. SRCS cpp_interface_test.cpp
  164. LIBS SPIRV-Tools-opt)
  165. if (${SPIRV_TIMER_ENABLED})
  166. add_spvtools_unittest(
  167. TARGET timer
  168. SRCS timer_test.cpp
  169. LIBS ${SPIRV_TOOLS})
  170. endif()
  171. add_spvtools_unittest(
  172. TARGET bit_stream
  173. SRCS bit_stream.cpp
  174. ${CMAKE_CURRENT_SOURCE_DIR}/../source/comp/bit_stream.cpp
  175. ${CMAKE_CURRENT_SOURCE_DIR}/../source/comp/bit_stream.h
  176. LIBS ${SPIRV_TOOLS})
  177. add_spvtools_unittest(
  178. TARGET huffman_codec
  179. SRCS huffman_codec.cpp
  180. ${CMAKE_CURRENT_SOURCE_DIR}/../source/comp/bit_stream.cpp
  181. ${CMAKE_CURRENT_SOURCE_DIR}/../source/comp/bit_stream.h
  182. ${CMAKE_CURRENT_SOURCE_DIR}/../source/comp/huffman_codec.h
  183. LIBS ${SPIRV_TOOLS})
  184. add_spvtools_unittest(
  185. TARGET move_to_front
  186. SRCS move_to_front_test.cpp
  187. ${CMAKE_CURRENT_SOURCE_DIR}/../source/comp/move_to_front.h
  188. ${CMAKE_CURRENT_SOURCE_DIR}/../source/comp/move_to_front.cpp
  189. LIBS ${SPIRV_TOOLS})
  190. add_subdirectory(comp)
  191. add_subdirectory(link)
  192. add_subdirectory(opt)
  193. add_subdirectory(reduce)
  194. add_subdirectory(stats)
  195. add_subdirectory(tools)
  196. add_subdirectory(util)
  197. add_subdirectory(val)