CMakeLists.txt 5.6 KB

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