CMakeLists.txt 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  2. if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL amd64)
  3. set(OBJCOPY_TARGET "elf64-x86-64")
  4. set(OBJCOPY_ARCH "x86_64")
  5. elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL i686)
  6. set(OBJCOPY_TARGET "elf32-i386")
  7. set(OBJCOPY_ARCH "i386")
  8. else()
  9. message(AUTHOR_WARNING "This is not a platform that would support testing nbt++")
  10. return()
  11. endif()
  12. else()
  13. message(AUTHOR_WARNING "This is not a platform that would support testing nbt++")
  14. return()
  15. endif()
  16. enable_testing()
  17. find_package(CxxTest REQUIRED)
  18. include_directories(${libnbt++_SOURCE_DIR}/include)
  19. include_directories(${CXXTEST_INCLUDE_DIR})
  20. function(build_data out_var)
  21. set(result)
  22. foreach(in_f ${ARGN})
  23. set(out_f "${CMAKE_CURRENT_BINARY_DIR}/testfiles/${in_f}.obj")
  24. add_custom_command(
  25. COMMAND mkdir -p "${CMAKE_CURRENT_BINARY_DIR}/testfiles"
  26. COMMAND ${CMAKE_OBJCOPY} --prefix-symbol=_ --input-target=binary --output-target=${OBJCOPY_TARGET} "${in_f}" "${out_f}"
  27. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/testfiles/${in_f}
  28. OUTPUT ${out_f}
  29. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/testfiles/
  30. VERBATIM
  31. )
  32. SET_SOURCE_FILES_PROPERTIES(
  33. ${out_f}
  34. PROPERTIES
  35. EXTERNAL_OBJECT true
  36. GENERATED true
  37. )
  38. list(APPEND result ${out_f})
  39. endforeach()
  40. set(${out_var} "${result}" PARENT_SCOPE)
  41. endfunction()
  42. build_data(DATA_OBJECTS
  43. bigtest.nbt
  44. bigtest.zlib
  45. bigtest_corrupt.nbt
  46. bigtest_eof.nbt
  47. bigtest_uncompr
  48. errortest_eof1
  49. errortest_eof2
  50. errortest_neg_length
  51. errortest_noend
  52. littletest_uncompr
  53. toplevel_string
  54. trailing_data.zlib
  55. )
  56. add_library(NbtTestData STATIC ${DATA_OBJECTS})
  57. #Specifies that the directory containing the testfiles get copied when the target is built
  58. function(use_testfiles target)
  59. add_custom_command(TARGET ${target} POST_BUILD
  60. COMMAND ${CMAKE_COMMAND} -E
  61. copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/testfiles ${CMAKE_CURRENT_BINARY_DIR})
  62. endfunction()
  63. function(stop_warnings target)
  64. target_compile_options(${target} PRIVATE
  65. -Wno-unused-value
  66. -Wno-self-assign-overloaded
  67. )
  68. endfunction()
  69. if(NBT_USE_ZLIB)
  70. set(EXTRA_TEST_LIBS ${ZLIB_LIBRARY})
  71. endif()
  72. CXXTEST_ADD_TEST(nbttest nbttest.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nbttest.h)
  73. target_link_libraries(nbttest ${NBT_NAME})
  74. stop_warnings(nbttest)
  75. CXXTEST_ADD_TEST(endian_str_test endian_str_test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/endian_str_test.h)
  76. target_link_libraries(endian_str_test ${NBT_NAME})
  77. stop_warnings(endian_str_test)
  78. CXXTEST_ADD_TEST(read_test read_test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/read_test.h)
  79. target_link_libraries(read_test ${NBT_NAME} ${EXTRA_TEST_LIBS} NbtTestData)
  80. stop_warnings(read_test)
  81. CXXTEST_ADD_TEST(write_test write_test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/write_test.h)
  82. target_link_libraries(write_test ${NBT_NAME} ${EXTRA_TEST_LIBS} NbtTestData)
  83. stop_warnings(write_test)
  84. if(NBT_USE_ZLIB)
  85. CXXTEST_ADD_TEST(zlibstream_test zlibstream_test.cpp ${CMAKE_CURRENT_SOURCE_DIR}/zlibstream_test.h)
  86. target_link_libraries(zlibstream_test ${NBT_NAME} ${EXTRA_TEST_LIBS} NbtTestData)
  87. stop_warnings(zlibstream_test)
  88. endif()
  89. add_executable(format_test format_test.cpp)
  90. target_link_libraries(format_test ${NBT_NAME})
  91. add_test(format_test format_test)
  92. stop_warnings(format_test)