CMakeLists.txt 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # sources
  2. #aux_source_directory(. SOURCES)
  3. file(GLOB SOURCES test_*.c)
  4. # flags
  5. link_directories(${PROJECT_BINARY_DIR}/blosc)
  6. # targets and tests
  7. foreach(source ${SOURCES})
  8. get_filename_component(target ${source} NAME_WE)
  9. # test_nolock and test_noinit will be enabled only for Unix
  10. if(WIN32)
  11. if (target STREQUAL test_nolock OR
  12. target STREQUAL test_noinit OR
  13. target STREQUAL test_compressor)
  14. message("Skipping ${target} on Windows systems")
  15. continue()
  16. endif()
  17. endif()
  18. # test_compressor will be enabled only when LZ4 support is in
  19. if(target STREQUAL test_compressor AND DEACTIVATE_LZ4)
  20. message("Skipping ${target} on non-LZ4 builds")
  21. continue()
  22. endif()
  23. # Enable support for testing accelerated shuffles
  24. if(COMPILER_SUPPORT_SSE2)
  25. # Define a symbol so tests for SSE2 shuffle/unshuffle will be compiled in.
  26. set_property(
  27. SOURCE ${source}
  28. APPEND PROPERTY COMPILE_DEFINITIONS SHUFFLE_SSE2_ENABLED)
  29. endif(COMPILER_SUPPORT_SSE2)
  30. # if(COMPILER_SUPPORT_AVX2)
  31. # # Define a symbol so tests for AVX2 shuffle/unshuffle will be compiled in.
  32. # set_property(
  33. # SOURCE ${source}
  34. # APPEND PROPERTY COMPILE_DEFINITIONS SHUFFLE_AVX2_ENABLED)
  35. # endif(COMPILER_SUPPORT_AVX2)
  36. add_executable(${target} ${source})
  37. # Define the BLOSC_TESTING symbol so normally-hidden functions
  38. # aren't hidden from the view of the test programs.
  39. set_property(
  40. TARGET ${target}
  41. APPEND PROPERTY COMPILE_DEFINITIONS BLOSC_TESTING)
  42. # have to copy dlls for Visual Studio
  43. if(MSVC)
  44. if(MSVC_VERSION EQUAL 1500)
  45. # This is an attempt to make VS2008 work, but no luck...
  46. # https://cmake.org/pipermail/cmake/2014-October/058777.html
  47. SET(Configuration "Release")
  48. endif()
  49. add_custom_command(
  50. TARGET ${target}
  51. POST_BUILD
  52. COMMAND ${CMAKE_COMMAND}
  53. ARGS -E copy_if_different
  54. "${PROJECT_BINARY_DIR}/blosc/\$\(Configuration\)/blosc_testing.dll"
  55. "${CMAKE_CURRENT_BINARY_DIR}/\$\(Configuration\)/blosc_testing.dll")
  56. elseif(MINGW)
  57. add_custom_command(
  58. TARGET ${target}
  59. POST_BUILD
  60. COMMAND ${CMAKE_COMMAND}
  61. ARGS -E copy_if_different
  62. "${PROJECT_BINARY_DIR}/blosc/libblosc_testing.dll"
  63. "${CMAKE_CURRENT_BINARY_DIR}/libblosc_testing.dll")
  64. endif()
  65. target_link_libraries(${target} blosc_testing)
  66. add_dependencies(${target} blosc_shared_testing)
  67. # If there's a CSV file present for this test, read it to get the list
  68. # of test parameters then add a test for each parameter set.
  69. # Otherwise, this is a simple test so just add it once.
  70. get_filename_component(source_extension ${source} EXT)
  71. string(REGEX REPLACE "${source_extension}$" ".csv"
  72. test_params_file ${source})
  73. if (EXISTS "${test_params_file}")
  74. # Read the file contents into a CMake list
  75. file(READ "${test_params_file}" test_params_contents)
  76. string(REGEX REPLACE ";" "\\\\;"
  77. test_params_contents "${test_params_contents}")
  78. string(REGEX REPLACE "\n" ";"
  79. test_params_contents "${test_params_contents}")
  80. # How many parameter sets for this test?
  81. # If there's not at least one (accounting for the CSV header line),
  82. # that's probably not correct so emit an error and stop configuring.
  83. list(LENGTH test_params_contents test_params_count)
  84. if ("${test_params_count}" LESS 2)
  85. message(ERROR "Invalid test parameters file: ${test_params_file}")
  86. endif()
  87. # Remove the header line.
  88. list(REMOVE_AT test_params_contents 0)
  89. # Add a test for each parameter set in the file.
  90. foreach(test_params_raw ${test_params_contents})
  91. string(REGEX REPLACE "," " " test_params "${test_params_raw}")
  92. # Create the test name.
  93. # NOTE: The documentation for add_test says the test name "may not contain
  94. # spaces, quotes, or other characters special in CMake syntax."
  95. string(REGEX REPLACE "\"| " "_" test_name_params "${test_params}")
  96. set(test_name "${target}_${test_name_params}")
  97. separate_arguments(test_params)
  98. add_test(${test_name} ${target} ${test_params})
  99. endforeach()
  100. else()
  101. add_test(${target} ${target})
  102. endif()
  103. endforeach(source)