A 2D tile-based sandbox game.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CMakeLists.txt 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. cmake_minimum_required(VERSION 3.0)
  2. project(swan)
  3. find_package(SDL2 REQUIRED)
  4. find_package(PNG)
  5. option(USE_CLANG_TIDY "Use clang-tidy for additional checks" ON)
  6. if(USE_CLANG_TIDY)
  7. set(CMAKE_CXX_CLANG_TIDY
  8. clang-tidy
  9. "--header-filter=(libswan|core.mod|src)/.*"
  10. --checks=-*,bugprone-*,cert-*,performance-*,clang-analyzer-*,-cert-dcl16-c,-cert-err58-cpp,-clang-analyzer-optin.cplusplus.VirtualCall)
  11. endif()
  12. if(CMAKE_EXPORT_COMPILE_COMMANDS)
  13. add_custom_target(compile_commands ALL
  14. BYPRODUCTS ${CMAKE_CURRENT_SOURCE_DIR}/compile_commands.json
  15. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  16. COMMAND
  17. compdb -p ${CMAKE_CURRENT_BINARY_DIR} list
  18. > ${CMAKE_CURRENT_SOURCE_DIR}/compile_commands.json)
  19. endif()
  20. add_compile_options(-std=c++2a -Wall -Wextra -Wpedantic -Wno-unused-parameter)
  21. if(CMAKE_BUILD_TYPE STREQUAL Sanitize OR CMAKE_BUILD_TYPE STREQUAL "")
  22. message(STATUS "Build mode: Sanitize")
  23. add_compile_options(-g -Og -fsanitize=address -fsanitize=undefined)
  24. add_link_options(-fsanitize=address -fsanitize=undefined)
  25. elseif(CMAKE_BUILD_TYPE STREQUAL Debug)
  26. message(STATUS "Build mode: Debug")
  27. add_compile_options(-g -O0)
  28. elseif(CMAKE_BUILD_TYPE STREQUAL Release)
  29. message(STATUS "Build mode: Release")
  30. add_compile_options(-O3 -flto)
  31. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto")
  32. else()
  33. message(FATAL_ERROR "CMAKE_BUILD_TYPE must be Debug or Release.")
  34. endif()
  35. add_subdirectory(third_party)
  36. set(libraries imgui SDL2 SDL2_image dl z)
  37. # We want to be able to use C++20 designated initializers,
  38. # but Clang doesn't support them yet.
  39. # Remove once Clang 9.1 or something comes out.
  40. add_compile_options(-Wno-c99-extensions)
  41. include_directories(
  42. ${PROJECT_SOURCE_DIR}/third_party
  43. ${SDL2_INCLUDE_DIRS})
  44. set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;${CMAKE_INSTALL_PREFIX}/lib64;${CMAKE_INSTALL_PREFIX}/swan/libswan;${CMAKE_INSTALL_PREFIX}/swan/third_party")
  45. add_subdirectory(libswan)
  46. add_subdirectory(core.mod)
  47. add_executable(swan
  48. src/main.cc)
  49. target_link_libraries(swan libswan ${libraries})
  50. add_executable(perlin-test
  51. src/perlin-test.cc)
  52. target_link_libraries(perlin-test libswan PNG::PNG ${libraries})
  53. set(assets
  54. assets/icon.png
  55. assets/music/happy-1.wav)
  56. foreach(a ${assets})
  57. configure_file("${a}" "${a}" COPYONLY)
  58. endforeach(a)
  59. install(TARGETS swan DESTINATION swan)
  60. install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/assets DESTINATION swan)
  61. add_custom_target(check DEPENDS check_libswan)