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 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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|libcygnet|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 -DDEBUG -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 -DDEBUG)
  29. elseif(CMAKE_BUILD_TYPE STREQUAL Optimize)
  30. message(STATUS "Build mode: Optimize")
  31. add_compile_options(-O3 -g -DDEBUG)
  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 -g -DNDEBUG)
  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/libcygnet;${CMAKE_INSTALL_PREFIX}/swan/third-party")
  49. add_library(swan-common INTERFACE)
  50. target_include_directories(swan-common
  51. INTERFACE "include")
  52. add_subdirectory(third-party)
  53. add_subdirectory(tracy-tools)
  54. add_subdirectory(libswan)
  55. add_subdirectory(libcygnet)
  56. add_subdirectory(core.mod)
  57. add_executable(swan
  58. src/main.cc)
  59. target_link_libraries(swan libswan libcygnet ${libraries})
  60. add_dependencies(swan core.mod)
  61. add_executable(perlin-test EXCLUDE_FROM_ALL
  62. src/perlin-test.cc)
  63. target_link_libraries(perlin-test libswan PNG::PNG ${libraries})
  64. add_executable(lighting-test EXCLUDE_FROM_ALL
  65. src/lighting-test.cc)
  66. target_link_libraries(lighting-test libswan PNG::PNG ${libraries})
  67. add_executable(cygnet-test EXCLUDE_FROM_ALL
  68. src/cygnet-test.cc)
  69. target_link_libraries(cygnet-test libcygnet ${libraries})
  70. set(assets
  71. assets/icon.png
  72. assets/music/happy-1.wav)
  73. foreach(a ${assets})
  74. configure_file("${a}" "${a}" COPYONLY)
  75. endforeach(a)
  76. install(TARGETS swan DESTINATION swan)
  77. install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/assets DESTINATION swan)
  78. add_custom_target(check DEPENDS check_libswan)
  79. add_custom_target(cloc
  80. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  81. COMMAND cloc core.mod src libcygnet libswan)