CMakeLists.txt 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. cmake_minimum_required(VERSION 3.13)
  2. project(snake VERSION 0.1.1)
  3. set(CMAKE_CXX_STANDARD 17)
  4. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
  5. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
  6. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
  7. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/static)
  8. include_directories(${CMAKE_SOURCE_DIR}/include)
  9. set(SOURCES
  10. ${CMAKE_SOURCE_DIR}/src/Snake.cpp
  11. ${CMAKE_SOURCE_DIR}/src/Field/AField.cpp
  12. ${CMAKE_SOURCE_DIR}/src/Field/RectShapeField.cpp
  13. ${CMAKE_SOURCE_DIR}/src/App.cpp
  14. ${CMAKE_SOURCE_DIR}/src/Game.cpp
  15. )
  16. # Separated library to avoid linker error undefined reference to <sfml specific>
  17. add_library(libsnake STATIC ${SOURCES})
  18. # Program
  19. find_package(SFML 2.5 COMPONENTS system window graphics REQUIRED)
  20. add_executable(snake ${CMAKE_SOURCE_DIR}/src/main.cpp)
  21. target_link_libraries(snake libsnake)
  22. target_link_libraries(snake sfml-window sfml-graphics sfml-system) #SFML libs
  23. # Tests
  24. file(GLOB_RECURSE TEST_SOURCES ${CMAKE_SOURCE_DIR}/test/*.cpp)
  25. find_package(Catch2 3 REQUIRED)
  26. add_executable(test ${TEST_SOURCES})
  27. target_link_libraries(test PRIVATE libsnake)
  28. target_link_libraries(test PRIVATE Catch2::Catch2WithMain)