💿🐜 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.

141 lines
4.7 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/config.hpp.in
  38. ${PROJECT_BINARY_DIR}/src/config.hpp)
  39. # Collect source files
  40. file(GLOB_RECURSE SOURCE_FILES
  41. ${PROJECT_SOURCE_DIR}/src/*.cpp)
  42. # Remove platform-specific source files
  43. set(EXCLUDE_DIR "${PROJECT_SOURCE_DIR}/src/platform/")
  44. foreach(TMP_PATH ${SOURCE_FILES})
  45. string(FIND ${TMP_PATH} ${EXCLUDE_DIR} EXCLUDE_DIR_FOUND)
  46. if (NOT ${EXCLUDE_DIR_FOUND} EQUAL -1)
  47. list(REMOVE_ITEM SOURCE_FILES ${TMP_PATH})
  48. endif ()
  49. endforeach(TMP_PATH)
  50. if(MSVC)
  51. # Add platform-specific source files
  52. list(APPEND SOURCE_FILES "${PROJECT_SOURCE_DIR}/src/platform/windows/nvidia.cpp")
  53. # Generate Windows icon resource file
  54. set(ICON_FILE "${PROJECT_SOURCE_DIR}/../antkeeper-data/src/icons/antkeeper.ico")
  55. if(EXISTS "${ICON_FILE}")
  56. configure_file(${PROJECT_SOURCE_DIR}/src/platform/windows/icon.rc.in ${PROJECT_BINARY_DIR}/src/platform/windows/icon.rc)
  57. list(APPEND SOURCE_FILES "${PROJECT_BINARY_DIR}/src/platform/windows/icon.rc")
  58. endif()
  59. # Generate Windows version-information resource file
  60. configure_file(${PROJECT_SOURCE_DIR}/src/platform/windows/version.rc.in ${PROJECT_BINARY_DIR}/src/platform/windows/version.rc)
  61. list(APPEND SOURCE_FILES "${PROJECT_BINARY_DIR}/src/platform/windows/version.rc")
  62. # Make executable DPI-aware on Windows
  63. list(APPEND SOURCE_FILES "${PROJECT_SOURCE_DIR}/src/platform/windows/dpi-aware.manifest")
  64. endif()
  65. # Add executable target
  66. set(EXECUTABLE_TARGET ${APPLICATION_SLUG}-executable)
  67. add_executable(${EXECUTABLE_TARGET} ${SOURCE_FILES})
  68. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES OUTPUT_NAME ${APPLICATION_SLUG})
  69. if(MSVC)
  70. # Select the static multithreaded MSVC runtime library
  71. set_property(TARGET ${EXECUTABLE_TARGET} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
  72. endif()
  73. # Add compile definitions
  74. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  75. target_compile_definitions(${EXECUTABLE_TARGET} PRIVATE DEBUG)
  76. else()
  77. target_compile_definitions(${EXECUTABLE_TARGET} PRIVATE NDEBUG)
  78. endif()
  79. # Set C++ standard
  80. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES
  81. CXX_STANDARD 23
  82. CXX_STANDARD_REQUIRED ON
  83. CXX_EXTENSIONS OFF)
  84. # Set link flags to show console window on debug builds and hide it on release builds
  85. if(MSVC)
  86. #set_target_properties(${EXECUTABLE_TARGET} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:libvcruntime.lib")
  87. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE")
  88. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS /ENTRY:\"mainCRTStartup\"")
  89. endif(MSVC)
  90. # Set include directories
  91. target_include_directories(${EXECUTABLE_TARGET}
  92. PUBLIC
  93. ${PROJECT_SOURCE_DIR}/src
  94. ${PROJECT_BINARY_DIR}/src)
  95. # Link to dependencies
  96. target_link_libraries(${EXECUTABLE_TARGET} ${STATIC_LIBS} ${SHARED_LIBS})
  97. # Install executable
  98. if(PACKAGE_PLATFORM MATCHES "linux")
  99. install(TARGETS ${EXECUTABLE_TARGET} DESTINATION bin)
  100. elseif(PACKAGE_PLATFORM MATCHES "win")
  101. # Install executable
  102. install(TARGETS ${EXECUTABLE_TARGET} DESTINATION .)
  103. # Install SDL2 DLLs
  104. #if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  105. # get_target_property(SDL2_DLL SDL2::SDL2 IMPORTED_LOCATION_DEBUG)
  106. #else()
  107. # get_target_property(SDL2_DLL SDL2::SDL2 IMPORTED_LOCATION_RELEASE)
  108. #endif()
  109. #install(FILES ${SDL2_DLL} DESTINATION .)
  110. # Install OpenAL DLL
  111. #if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  112. # get_target_property(OPENAL_DLL OpenAL::OpenAL IMPORTED_LOCATION_DEBUG)
  113. #else()
  114. # get_target_property(OPENAL_DLL OpenAL::OpenAL IMPORTED_LOCATION_RELEASE)
  115. #endif()
  116. #install(FILES ${OPENAL_DLL} DESTINATION .)
  117. endif()