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.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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" OFF)
  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. # Ninja runs commands with buffered stdio so the compiler won't show colors by default,
  13. # but Ninja will strip out color codes if Ninja's stdout isn't a tty so unconditionally
  14. # enabling color diagnostics is safe
  15. if(CMAKE_GENERATOR STREQUAL "Ninja")
  16. add_compile_options(-fdiagnostics-color=always)
  17. endif()
  18. add_compile_options(-std=c++2a -Wall -Wextra -Wpedantic -Wno-unused-parameter)
  19. if(CMAKE_BUILD_TYPE STREQUAL Sanitize OR CMAKE_BUILD_TYPE STREQUAL "")
  20. message(STATUS "Build mode: Sanitize")
  21. add_compile_options(-g -Og -fsanitize=address -fsanitize=undefined)
  22. add_link_options(-fsanitize=address -fsanitize=undefined)
  23. elseif(CMAKE_BUILD_TYPE STREQUAL Debug)
  24. message(STATUS "Build mode: Debug")
  25. add_compile_options(-g -Og)
  26. elseif(CMAKE_BUILD_TYPE STREQUAL DebugRelease)
  27. message(STATUS "Build mode: DebugRelease")
  28. add_compile_options(-O3 -flto -DNDEBUG -g)
  29. elseif(CMAKE_BUILD_TYPE STREQUAL Release)
  30. message(STATUS "Build mode: Release")
  31. add_compile_options(-O3 -flto -DNDEBUG)
  32. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto")
  33. else()
  34. message(FATAL_ERROR "CMAKE_BUILD_TYPE must be Debug or Release.")
  35. endif()
  36. add_subdirectory(third_party)
  37. set(libraries imgui fmt cpptoml msgpack SDL2 SDL2_image dl z)
  38. # We want to be able to use C++20 designated initializers,
  39. # but Clang doesn't support them yet.
  40. # Remove once Clang 9.1 or something comes out.
  41. add_compile_options(-Wno-c99-extensions)
  42. include_directories(
  43. ${PROJECT_SOURCE_DIR}/third_party
  44. ${SDL2_INCLUDE_DIRS})
  45. set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;${CMAKE_INSTALL_PREFIX}/lib64;${CMAKE_INSTALL_PREFIX}/swan/libswan;${CMAKE_INSTALL_PREFIX}/swan/third_party")
  46. add_subdirectory(libswan)
  47. add_subdirectory(core.mod)
  48. add_executable(swan
  49. src/main.cc)
  50. target_link_libraries(swan libswan ${libraries})
  51. add_executable(perlin-test EXCLUDE_FROM_ALL
  52. src/perlin-test.cc)
  53. target_link_libraries(perlin-test libswan PNG::PNG ${libraries})
  54. set(assets
  55. assets/icon.png
  56. assets/music/happy-1.wav)
  57. foreach(a ${assets})
  58. configure_file("${a}" "${a}" COPYONLY)
  59. endforeach(a)
  60. install(TARGETS swan DESTINATION swan)
  61. install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/assets DESTINATION swan)
  62. add_custom_target(check DEPENDS check_libswan)