💿🐜 Antkeeper source code https://antkeeper.com
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.

120 lines
4.1 KiB

  1. cmake_minimum_required(VERSION 3.25)
  2. option(APPLICATION_NAME "Application name" "Antkeeper")
  3. option(APPLICATION_VERSION "Application version string" "0.0.0")
  4. option(APPLICATION_AUTHOR "Application author" "C. J. Howard")
  5. # Slugify application name
  6. string(TOLOWER ${APPLICATION_NAME} APPLICATION_SLUG)
  7. string(REPLACE " " "-" APPLICATION_SLUG ${APPLICATION_SLUG})
  8. project(${APPLICATION_SLUG} VERSION ${APPLICATION_VERSION} LANGUAGES CXX)
  9. set(APPLICATION_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
  10. set(APPLICATION_VERSION_MINOR ${PROJECT_VERSION_MINOR})
  11. set(APPLICATION_VERSION_PATCH ${PROJECT_VERSION_PATCH})
  12. # Find dependency packages
  13. find_package(dr_wav REQUIRED CONFIG)
  14. find_package(stb REQUIRED CONFIG)
  15. find_package(tinyexr REQUIRED CONFIG)
  16. find_package(glad REQUIRED CONFIG)
  17. find_package(EnTT REQUIRED CONFIG)
  18. find_package(OpenGL REQUIRED)
  19. find_package(SDL2 REQUIRED CONFIG)
  20. find_package(OpenAL REQUIRED CONFIG)
  21. find_library(physfs REQUIRED NAMES physfs-static PATHS "${CMAKE_PREFIX_PATH}/lib")
  22. find_package(freetype REQUIRED CONFIG)
  23. # Determine dependencies
  24. set(STATIC_LIBS
  25. dr_wav
  26. stb
  27. tinyexr
  28. glad
  29. SDL2::SDL2-static
  30. SDL2::SDL2main
  31. OpenAL::OpenAL
  32. ${physfs}
  33. freetype)
  34. set(SHARED_LIBS
  35. ${OPENGL_gl_LIBRARY})
  36. # Generate configuration header file
  37. configure_file(${PROJECT_SOURCE_DIR}/src/engine/config.hpp.in ${PROJECT_BINARY_DIR}/src/engine/config.hpp)
  38. # Collect source files
  39. file(GLOB_RECURSE SOURCE_FILES
  40. ${PROJECT_SOURCE_DIR}/src/*.cpp)
  41. # Remove platform-specific source files
  42. set(EXCLUDE_DIR "${PROJECT_SOURCE_DIR}/src/game/platform/")
  43. foreach(TMP_PATH ${SOURCE_FILES})
  44. string(FIND ${TMP_PATH} ${EXCLUDE_DIR} EXCLUDE_DIR_FOUND)
  45. if (NOT ${EXCLUDE_DIR_FOUND} EQUAL -1)
  46. list(REMOVE_ITEM SOURCE_FILES ${TMP_PATH})
  47. endif ()
  48. endforeach(TMP_PATH)
  49. if(MSVC)
  50. # Add platform-specific source files
  51. list(APPEND SOURCE_FILES "${PROJECT_SOURCE_DIR}/src/game/platform/windows/high-performance-graphics.cpp")
  52. # Generate Windows icon resource file
  53. set(ICON_FILE "${PROJECT_SOURCE_DIR}/../antkeeper-data/src/icons/antkeeper.ico")
  54. if(EXISTS "${ICON_FILE}")
  55. configure_file(${PROJECT_SOURCE_DIR}/src/game/platform/windows/icon.rc.in ${PROJECT_BINARY_DIR}/src/game/platform/windows/icon.rc)
  56. list(APPEND SOURCE_FILES "${PROJECT_BINARY_DIR}/src/game/platform/windows/icon.rc")
  57. endif()
  58. # Generate Windows version-information resource file
  59. configure_file(${PROJECT_SOURCE_DIR}/src/game/platform/windows/version.rc.in ${PROJECT_BINARY_DIR}/src/game/platform/windows/version.rc)
  60. list(APPEND SOURCE_FILES "${PROJECT_BINARY_DIR}/src/game/platform/windows/version.rc")
  61. # Make executable DPI-aware on Windows
  62. list(APPEND SOURCE_FILES "${PROJECT_SOURCE_DIR}/src/game/platform/windows/dpi-aware.manifest")
  63. endif()
  64. # Add executable target
  65. set(EXECUTABLE_TARGET ${APPLICATION_SLUG}-executable)
  66. add_executable(${EXECUTABLE_TARGET} ${SOURCE_FILES})
  67. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES
  68. OUTPUT_NAME ${APPLICATION_SLUG}
  69. COMPILE_WARNING_AS_ERROR ON
  70. CXX_STANDARD 23
  71. CXX_STANDARD_REQUIRED ON
  72. CXX_EXTENSIONS OFF)
  73. target_compile_definitions(${EXECUTABLE_TARGET} PRIVATE _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING)
  74. if(MSVC)
  75. target_compile_options(${EXECUTABLE_TARGET} PRIVATE /W3)
  76. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES
  77. LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE"
  78. LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS /ENTRY:\"mainCRTStartup\""
  79. MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
  80. else()
  81. target_compile_options(${EXECUTABLE_TARGET} PRIVATE -Wall -Wextra -Wpedantic)
  82. endif()
  83. # Add compile definitions
  84. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  85. target_compile_definitions(${EXECUTABLE_TARGET} PRIVATE DEBUG)
  86. else()
  87. target_compile_definitions(${EXECUTABLE_TARGET} PRIVATE NDEBUG)
  88. endif()
  89. # Set include directories
  90. target_include_directories(${EXECUTABLE_TARGET} PUBLIC
  91. ${PROJECT_SOURCE_DIR}/src
  92. ${PROJECT_BINARY_DIR}/src)
  93. # Link to dependencies
  94. target_link_libraries(${EXECUTABLE_TARGET} ${STATIC_LIBS} ${SHARED_LIBS})
  95. # Install executable
  96. if(PACKAGE_PLATFORM MATCHES "linux")
  97. install(TARGETS ${EXECUTABLE_TARGET} DESTINATION bin)
  98. elseif(PACKAGE_PLATFORM MATCHES "win")
  99. install(TARGETS ${EXECUTABLE_TARGET} DESTINATION .)
  100. endif()