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

127 lines
4.0 KiB

  1. cmake_minimum_required(VERSION 3.25)
  2. option(VERSION_STRING "Project version string" "0.0.0")
  3. project(antkeeper VERSION ${VERSION_STRING} LANGUAGES CXX)
  4. # Find dependency packages
  5. find_package(dr_wav REQUIRED CONFIG)
  6. find_package(stb REQUIRED CONFIG)
  7. find_package(tinyexr REQUIRED CONFIG)
  8. find_package(glad REQUIRED CONFIG)
  9. find_package(EnTT REQUIRED CONFIG)
  10. find_package(OpenGL REQUIRED)
  11. find_package(SDL2 REQUIRED CONFIG)
  12. find_package(OpenAL REQUIRED CONFIG)
  13. find_library(physfs REQUIRED NAMES physfs-static PATHS "${CMAKE_PREFIX_PATH}/lib")
  14. find_package(freetype REQUIRED CONFIG)
  15. # Determine dependencies
  16. set(STATIC_LIBS
  17. dr_wav
  18. stb
  19. tinyexr
  20. glad
  21. SDL2::SDL2-static
  22. SDL2::SDL2main
  23. OpenAL::OpenAL
  24. ${physfs}
  25. freetype)
  26. set(SHARED_LIBS
  27. ${OPENGL_gl_LIBRARY})
  28. # Generate configuration header file
  29. configure_file(${PROJECT_SOURCE_DIR}/src/config.hpp.in
  30. ${PROJECT_BINARY_DIR}/src/config.hpp)
  31. # Collect source files
  32. file(GLOB_RECURSE SOURCE_FILES
  33. ${PROJECT_SOURCE_DIR}/src/*.cpp)
  34. # Remove platform-specific source files
  35. set(EXCLUDE_DIR "${PROJECT_SOURCE_DIR}/src/platform/")
  36. foreach(TMP_PATH ${SOURCE_FILES})
  37. string(FIND ${TMP_PATH} ${EXCLUDE_DIR} EXCLUDE_DIR_FOUND)
  38. if (NOT ${EXCLUDE_DIR_FOUND} EQUAL -1)
  39. list(REMOVE_ITEM SOURCE_FILES ${TMP_PATH})
  40. endif ()
  41. endforeach(TMP_PATH)
  42. if(MSVC)
  43. # Add platform-specific source files
  44. list(APPEND SOURCE_FILES "${PROJECT_SOURCE_DIR}/src/platform/windows/nvidia.cpp")
  45. # Generate Windows icon resource file
  46. set(ICON_FILE "${PROJECT_SOURCE_DIR}/../antkeeper-data/src/icons/antkeeper.ico")
  47. if(EXISTS "${ICON_FILE}")
  48. configure_file(${PROJECT_SOURCE_DIR}/src/platform/windows/icon.rc.in
  49. ${PROJECT_BINARY_DIR}/src/platform/windows/icon.rc)
  50. list(APPEND SOURCE_FILES "${PROJECT_BINARY_DIR}/src/platform/windows/icon.rc")
  51. endif()
  52. # Make DPI-aware on Windows
  53. list(APPEND SOURCE_FILES "${PROJECT_SOURCE_DIR}/src/platform/windows/dpi-aware.manifest")
  54. endif()
  55. # Add executable target
  56. set(EXECUTABLE_TARGET ${PROJECT_NAME}-executable)
  57. add_executable(${EXECUTABLE_TARGET} ${SOURCE_FILES})
  58. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
  59. if(MSVC)
  60. # Select the static multithreaded MSVC runtime library
  61. set_property(TARGET ${EXECUTABLE_TARGET} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
  62. endif()
  63. # Add compile definitions
  64. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  65. target_compile_definitions(${EXECUTABLE_TARGET} PRIVATE DEBUG)
  66. else()
  67. target_compile_definitions(${EXECUTABLE_TARGET} PRIVATE NDEBUG)
  68. endif()
  69. # Set C++ standard
  70. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES
  71. CXX_STANDARD 23
  72. CXX_STANDARD_REQUIRED ON
  73. CXX_EXTENSIONS OFF)
  74. # Set link flags to show console window on debug builds and hide it on release builds
  75. if(MSVC)
  76. #set_target_properties(${EXECUTABLE_TARGET} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:libvcruntime.lib")
  77. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE")
  78. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS /ENTRY:\"mainCRTStartup\"")
  79. endif(MSVC)
  80. # Set include directories
  81. target_include_directories(${EXECUTABLE_TARGET}
  82. PUBLIC
  83. ${PROJECT_SOURCE_DIR}/src
  84. ${PROJECT_BINARY_DIR}/src)
  85. # Link to dependencies
  86. target_link_libraries(${EXECUTABLE_TARGET} ${STATIC_LIBS} ${SHARED_LIBS})
  87. # Install executable
  88. if(PACKAGE_PLATFORM MATCHES "linux")
  89. install(TARGETS ${EXECUTABLE_TARGET} DESTINATION bin)
  90. elseif(PACKAGE_PLATFORM MATCHES "win")
  91. # Install executable
  92. install(TARGETS ${EXECUTABLE_TARGET} DESTINATION .)
  93. # Install SDL2 DLLs
  94. #if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  95. # get_target_property(SDL2_DLL SDL2::SDL2 IMPORTED_LOCATION_DEBUG)
  96. #else()
  97. # get_target_property(SDL2_DLL SDL2::SDL2 IMPORTED_LOCATION_RELEASE)
  98. #endif()
  99. #install(FILES ${SDL2_DLL} DESTINATION .)
  100. # Install OpenAL DLL
  101. #if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  102. # get_target_property(OPENAL_DLL OpenAL::OpenAL IMPORTED_LOCATION_DEBUG)
  103. #else()
  104. # get_target_property(OPENAL_DLL OpenAL::OpenAL IMPORTED_LOCATION_RELEASE)
  105. #endif()
  106. #install(FILES ${OPENAL_DLL} DESTINATION .)
  107. endif()