CMakeLists.txt 5.2 KB

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