CMakeLists.txt 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. include(GoogleTest)
  2. set(googleTest_Dir ${CMAKE_CURRENT_SOURCE_DIR}/googletest)
  3. if(EXISTS ${googleTest_Dir})
  4. set(GTestSrc ${googleTest_Dir}/googletest)
  5. set(GMockSrc ${googleTest_Dir}/googlemock)
  6. else()
  7. message(FATAL_ERROR "No googletest src dir found!")
  8. endif()
  9. set(test_SRCS
  10. StdInc.cpp
  11. main.cpp
  12. CMemoryBufferTest.cpp
  13. CVcmiTestConfig.cpp
  14. JsonComparer.cpp
  15. battle/BattleHexTest.cpp
  16. battle/CBattleInfoCallbackTest.cpp
  17. battle/CHealthTest.cpp
  18. battle/CUnitStateTest.cpp
  19. battle/CUnitStateMagicTest.cpp
  20. battle/battle_UnitTest.cpp
  21. entity/CArtifactTest.cpp
  22. entity/CCreatureTest.cpp
  23. entity/CFactionTest.cpp
  24. entity/CHeroClassTest.cpp
  25. entity/CHeroTest.cpp
  26. entity/CSkillTest.cpp
  27. erm/ERM_BM.cpp
  28. erm/ERM_BU.cpp
  29. erm/ERM_FU.cpp
  30. erm/ERM_GM_T.cpp
  31. erm/ERM_MA.cpp
  32. erm/ERM_MC.cpp
  33. erm/ERM_MF.cpp
  34. erm/ERM_TM_T.cpp
  35. erm/ERM_VR.cpp
  36. erm/ERM_UN.cpp
  37. erm/ERMPersistenceTest.cpp
  38. erm/ExamplesTest.cpp
  39. erm/interpretter/ERM_VR.cpp
  40. erm/interpretter/ERM_UN.cpp
  41. erm/interpretter/ErmRunner.cpp
  42. events/ApplyDamageTest.cpp
  43. events/EventBusTest.cpp
  44. game/CGameStateTest.cpp
  45. map/CMapEditManagerTest.cpp
  46. map/CMapFormatTest.cpp
  47. map/MapComparer.cpp
  48. netpacks/EntitiesChangedTest.cpp
  49. netpacks/NetPackFixture.cpp
  50. scripting/LuaSandboxTest.cpp
  51. scripting/LuaSpellEffectTest.cpp
  52. scripting/LuaSpellEffectAPITest.cpp
  53. scripting/PoolTest.cpp
  54. scripting/ScriptFixture.cpp
  55. spells/AbilityCasterTest.cpp
  56. spells/CSpellTest.cpp
  57. spells/TargetConditionTest.cpp
  58. spells/effects/EffectFixture.cpp
  59. spells/effects/CatapultTest.cpp
  60. spells/effects/CloneTest.cpp
  61. spells/effects/DamageTest.cpp
  62. spells/effects/DispelTest.cpp
  63. spells/effects/HealTest.cpp
  64. spells/effects/SacrificeTest.cpp
  65. spells/effects/SummonTest.cpp
  66. spells/effects/TeleportTest.cpp
  67. spells/effects/TimedTest.cpp
  68. spells/targetConditions/AbsoluteSpellConditionTest.cpp
  69. spells/targetConditions/AbsoluteLevelConditionTest.cpp
  70. spells/targetConditions/BonusConditionTest.cpp
  71. spells/targetConditions/CreatureConditionTest.cpp
  72. spells/targetConditions/ElementalConditionTest.cpp
  73. spells/targetConditions/HealthValueConditionTest.cpp
  74. spells/targetConditions/ImmunityNegationConditionTest.cpp
  75. spells/targetConditions/NormalLevelConditionTest.cpp
  76. spells/targetConditions/NormalSpellConditionTest.cpp
  77. spells/targetConditions/ReceptiveFeatureConditionTest.cpp
  78. spells/targetConditions/SpellEffectConditionTest.cpp
  79. spells/targetConditions/TargetConditionItemFixture.cpp
  80. mock/BattleFake.cpp
  81. mock/mock_IGameCallback.cpp
  82. mock/mock_MapService.cpp
  83. mock/mock_BonusBearer.cpp
  84. mock/mock_CPSICallback.cpp
  85. )
  86. set(test_HEADERS
  87. StdInc.h
  88. CVcmiTestConfig.h
  89. JsonComparer.h
  90. scripting/ScriptFixture.h
  91. erm/interpretter/ErmRunner.h
  92. map/MapComparer.h
  93. netpacks/NetPackFixture.h
  94. spells/effects/EffectFixture.h
  95. spells/targetConditions/TargetConditionItemFixture.h
  96. vcai/ResourceManagerTest.h
  97. mock/BattleFake.h
  98. mock/mock_BonusBearer.h
  99. mock/mock_IGameCallback.h
  100. mock/mock_MapService.h
  101. mock/mock_BonusBearer.h
  102. )
  103. assign_source_group(${test_SRCS} ${test_HEADERS})
  104. set(mock_HEADERS
  105. mock/mock_battle_IBattleState.h
  106. mock/mock_battle_Unit.h
  107. mock/mock_Creature.h
  108. mock/mock_CreatureService.h
  109. mock/mock_IBattleInfoCallback.h
  110. mock/mock_scripting_Context.h
  111. mock/mock_scripting_Script.h
  112. mock/mock_scripting_Service.h
  113. mock/mock_spells_Mechanics.h
  114. mock/mock_spells_Problem.h
  115. mock/mock_spells_Spell.h
  116. mock/mock_UnitEnvironment.h
  117. mock/mock_UnitInfo.h
  118. mock/mock_vstd_RNG.h
  119. mock/mock_CPSICallback.h
  120. )
  121. if(MSVC)
  122. set(gtest_force_shared_crt ON CACHE BOOL "Use shared (DLL) run-time lib even when Google Test is built as static lib." FORCE)
  123. endif()
  124. add_subdirectory_with_folder("3rdparty" googletest EXCLUDE_FROM_ALL)
  125. add_executable(vcmitest ${test_SRCS} ${test_HEADERS} ${mock_HEADERS})
  126. target_link_libraries(vcmitest PRIVATE gtest gmock vcmi ${SYSTEM_LIBS})
  127. target_include_directories(vcmitest
  128. PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
  129. PRIVATE ${GTestSrc}
  130. PRIVATE ${GTestSrc}/include
  131. PRIVATE ${GMockSrc}
  132. PRIVATE ${GMockSrc}/include
  133. )
  134. if(FALSE AND NOT ${CMAKE_VERSION} VERSION_LESS "3.10.0")
  135. # Running tests one by one using ctest not recommended due to vcmi having
  136. # slow global initialization.
  137. gtest_discover_tests(vcmitest
  138. WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/bin/")
  139. else()
  140. add_test(NAME tests
  141. COMMAND vcmitest
  142. WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/bin/")
  143. endif()
  144. vcmi_set_output_dir(vcmitest "")
  145. enable_pch(vcmitest)
  146. file (GLOB_RECURSE testdata "testdata/*.*")
  147. foreach(resource ${testdata})
  148. get_filename_component(filename ${resource} NAME)
  149. get_filename_component(dir ${resource} DIRECTORY)
  150. get_filename_component(dirname ${dir} NAME)
  151. set (output "")
  152. while(NOT ${dirname} STREQUAL testdata)
  153. get_filename_component(path_component ${dir} NAME)
  154. set (output "${path_component}/${output}")
  155. get_filename_component(dir ${dir} DIRECTORY)
  156. get_filename_component(dirname ${dir} NAME)
  157. endwhile()
  158. set(output "${CMAKE_BINARY_DIR}/bin/test/testdata/${output}/${filename}")
  159. configure_file(${resource} ${output} COPYONLY)
  160. endforeach()