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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. set(libraries
  20. third-party imgui fmt cpptoml msgpack
  21. SDL2::SDL2 SDL2_image dl z)
  22. if(CMAKE_BUILD_TYPE STREQUAL Sanitize OR CMAKE_BUILD_TYPE STREQUAL "")
  23. message(STATUS "Build mode: Sanitize")
  24. add_compile_options(-g -Og -fsanitize=address -fsanitize=undefined)
  25. add_link_options(-fsanitize=address -fsanitize=undefined)
  26. elseif(CMAKE_BUILD_TYPE STREQUAL Debug)
  27. message(STATUS "Build mode: Debug")
  28. add_compile_options(-g -Og)
  29. elseif(CMAKE_BUILD_TYPE STREQUAL Optimize)
  30. message(STATUS "Build mode: Optimize")
  31. add_compile_options(-O3 -DNDEBUG -g)
  32. elseif(CMAKE_BUILD_TYPE STREQUAL Tracy)
  33. message(STATUS "Build mode: Tracy")
  34. add_compile_options(-O3 -flto -DNDEBUG -g -DTRACY_ENABLE -DTRACY_ON_DEMAND)
  35. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto")
  36. list(APPEND libraries tracy)
  37. elseif(CMAKE_BUILD_TYPE STREQUAL Release)
  38. message(STATUS "Build mode: Release")
  39. add_compile_options(-O3 -flto -DNDEBUG -g)
  40. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto")
  41. else()
  42. message(FATAL_ERROR "CMAKE_BUILD_TYPE must be Sanitize, Debug, DebugRelease, Tracy or Release.")
  43. endif()
  44. # We want to be able to use C++20 designated initializers,
  45. # but Clang doesn't support them yet.
  46. # Remove once Clang 9.1 or something comes out.
  47. add_compile_options(-Wno-c99-extensions)
  48. set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;${CMAKE_INSTALL_PREFIX}/lib64;${CMAKE_INSTALL_PREFIX}/swan/libswan;${CMAKE_INSTALL_PREFIX}/swan/third-party")
  49. add_subdirectory(third-party)
  50. add_subdirectory(tracy-tools)
  51. add_subdirectory(libswan)
  52. add_subdirectory(core.mod)
  53. add_executable(swan
  54. src/main.cc)
  55. target_link_libraries(swan libswan ${libraries})
  56. add_executable(perlin-test EXCLUDE_FROM_ALL
  57. src/perlin-test.cc)
  58. target_link_libraries(perlin-test libswan PNG::PNG ${libraries})
  59. add_executable(lighting-test EXCLUDE_FROM_ALL
  60. src/lighting-test.cc)
  61. target_link_libraries(lighting-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)