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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. if(CMAKE_EXPORT_COMPILE_COMMANDS)
  19. add_custom_target(compile_commands ALL
  20. BYPRODUCTS ${CMAKE_CURRENT_SOURCE_DIR}/compile_commands.json
  21. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  22. COMMAND
  23. compdb -p ${CMAKE_CURRENT_BINARY_DIR} list
  24. > ${CMAKE_CURRENT_SOURCE_DIR}/compile_commands.json)
  25. endif()
  26. add_compile_options(-std=c++2a -Wall -Wextra -Wpedantic -Wno-unused-parameter)
  27. if(CMAKE_BUILD_TYPE STREQUAL Sanitize OR CMAKE_BUILD_TYPE STREQUAL "")
  28. message(STATUS "Build mode: Sanitize")
  29. add_compile_options(-g -Og -fsanitize=address -fsanitize=undefined)
  30. add_link_options(-fsanitize=address -fsanitize=undefined)
  31. elseif(CMAKE_BUILD_TYPE STREQUAL Debug)
  32. message(STATUS "Build mode: Debug")
  33. add_compile_options(-g -Og)
  34. elseif(CMAKE_BUILD_TYPE STREQUAL DebugRelease)
  35. message(STATUS "Build mode: DebugRelease")
  36. add_compile_options(-O3 -flto -DNDEBUG -g)
  37. elseif(CMAKE_BUILD_TYPE STREQUAL Release)
  38. message(STATUS "Build mode: Release")
  39. add_compile_options(-O3 -flto -DNDEBUG)
  40. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto")
  41. else()
  42. message(FATAL_ERROR "CMAKE_BUILD_TYPE must be Debug or Release.")
  43. endif()
  44. add_subdirectory(third_party)
  45. set(libraries imgui fmt cpptoml msgpack SDL2 SDL2_image dl z)
  46. # We want to be able to use C++20 designated initializers,
  47. # but Clang doesn't support them yet.
  48. # Remove once Clang 9.1 or something comes out.
  49. add_compile_options(-Wno-c99-extensions)
  50. include_directories(
  51. ${PROJECT_SOURCE_DIR}/third_party
  52. ${SDL2_INCLUDE_DIRS})
  53. set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;${CMAKE_INSTALL_PREFIX}/lib64;${CMAKE_INSTALL_PREFIX}/swan/libswan;${CMAKE_INSTALL_PREFIX}/swan/third_party")
  54. add_subdirectory(libswan)
  55. add_subdirectory(core.mod)
  56. add_executable(swan
  57. src/main.cc)
  58. target_link_libraries(swan libswan ${libraries})
  59. add_executable(perlin-test EXCLUDE_FROM_ALL
  60. src/perlin-test.cc)
  61. target_link_libraries(perlin-test libswan PNG::PNG ${libraries})
  62. set(assets
  63. assets/icon.png
  64. assets/music/happy-1.wav)
  65. foreach(a ${assets})
  66. configure_file("${a}" "${a}" COPYONLY)
  67. endforeach(a)
  68. install(TARGETS swan DESTINATION swan)
  69. install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/assets DESTINATION swan)
  70. add_custom_target(check DEPENDS check_libswan)