CMakeLists.txt 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #
  2. # Public Domain.
  3. #
  4. cmake_minimum_required(VERSION 2.4)
  5. function(dependenciesForFile file operations output)
  6. # If it's not in the top of the file, we'll just miss it.
  7. file(STRINGS "${file}" lines LIMIT_COUNT 16)
  8. foreach(line ${lines})
  9. if("${line}" MATCHES "#include ")
  10. foreach(op ${operations})
  11. if("${line}" MATCHES "${op}.h")
  12. list(APPEND outList "${op}")
  13. endif()
  14. endforeach()
  15. endif()
  16. endforeach()
  17. set(${output} "${outList}" PARENT_SCOPE)
  18. endfunction()
  19. include_directories(
  20. "${CMAKE_BINARY_DIR}/include/"
  21. "${CMAKE_BINARY_DIR}/include_internal/"
  22. )
  23. string(REGEX REPLACE "^.*/" "" main_dir_name ${CMAKE_SOURCE_DIR})
  24. string(REPLACE ${CMAKE_SOURCE_DIR} ${main_dir_name} this_dir ${CMAKE_CURRENT_SOURCE_DIR})
  25. message("-- Tests to run for " ${this_dir})
  26. add_definitions(-g)
  27. include("${CMAKE_SOURCE_DIR}/cmake/Primitives.cmake")
  28. file(STRINGS "${CMAKE_SOURCE_DIR}/OPERATIONS" OPERATIONS)
  29. Primitives_get("${OPERATIONS}" opPrimitives)
  30. # Anything in this dir which ends with ".c" is considered a test.
  31. file(GLOB tests "*.c")
  32. foreach(test_source_fullpath ${tests})
  33. string(REGEX REPLACE "^.*/" "" test_source ${test_source_fullpath})
  34. string(REPLACE ".c" "_test" test_bin ${test_source})
  35. set(allTests "")
  36. dependenciesForFile(${test_source_fullpath} "${OPERATIONS}" depends)
  37. foreach(op ${depends})
  38. foreach(opPrim ${opPrimitives})
  39. if(${opPrim} MATCHES "^${op}_.*")
  40. string(REPLACE "${op}_" "" primitive "${opPrim}")
  41. set(testPrimBin ${test_bin}_${primitive})
  42. add_executable(${testPrimBin} ${test_source})
  43. # Replace with target_include_directories when that branch is merged.
  44. set_property(TARGET ${testPrimBin} APPEND PROPERTY COMPILE_FLAGS
  45. "-I${CMAKE_BINARY_DIR}/${op}/${primitive}")
  46. target_link_libraries(${testPrimBin} randombytes nacl)
  47. add_test(${testPrimBin} ${testPrimBin})
  48. list(APPEND allTests ${testPrimBin})
  49. endif()
  50. endforeach()
  51. endforeach()
  52. if("${depends}" STREQUAL "")
  53. add_executable(${test_bin} ${test_source})
  54. target_link_libraries(${test_bin} nacl randombytes)
  55. add_test(${test_bin} ${test_bin})
  56. list(APPEND allTests ${test_bin})
  57. endif()
  58. # Get expected output.
  59. foreach(test ${allTests})
  60. string(REPLACE "_test" "" testOut "${test}")
  61. if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${testOut}.out")
  62. set(outFile "${CMAKE_CURRENT_SOURCE_DIR}/${testOut}.out")
  63. else()
  64. string(REPLACE "_test" ".out" outFile "${CMAKE_CURRENT_SOURCE_DIR}/${test_bin}")
  65. endif()
  66. file(READ ${outFile} test_output)
  67. set_tests_properties(${test} PROPERTIES PASS_REGULAR_EXPRESSION "^${test_output}$")
  68. endforeach()
  69. endforeach()
  70. # Add an empty line after tests.
  71. message("")