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

123 lines
3.7 KiB

  1. cmake_minimum_required(VERSION 3.7)
  2. option(VERSION_STRING "Project version string" "0.0.0")
  3. project(antkeeper VERSION ${VERSION_STRING} LANGUAGES CXX)
  4. # Set compiler flags
  5. if(CMAKE_COMPILER_IS_GNUCC)
  6. set(CMAKE_CXX_FLAGS "-Wall -Wextra")
  7. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g")
  8. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3")
  9. elseif(MSVC)
  10. set(CMAKE_CXX_FLAGS "/W3 /MP /MD")
  11. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS}")
  12. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} /Ox")
  13. endif()
  14. # Find dependency packages
  15. find_package(vmq REQUIRED CONFIG)
  16. find_package(dr_wav REQUIRED CONFIG)
  17. find_package(stb REQUIRED CONFIG)
  18. find_package(glad REQUIRED CONFIG)
  19. find_package(EnTT REQUIRED CONFIG)
  20. find_package(OpenGL REQUIRED)
  21. find_package(SDL2 REQUIRED COMPONENTS SDL2::SDL2-static SDL2::SDL2main CONFIG)
  22. find_package(OpenAL REQUIRED CONFIG)
  23. # Determine dependencies
  24. set(STATIC_LIBS
  25. vmq
  26. dr_wav
  27. stb
  28. glad
  29. EnTT
  30. SDL2::SDL2main)
  31. set(SHARED_LIBS
  32. ${OPENGL_gl_LIBRARY}
  33. SDL2::SDL2
  34. OpenAL::OpenAL)
  35. # Generate configuration header file
  36. configure_file(${PROJECT_SOURCE_DIR}/src/configuration.hpp.in
  37. ${PROJECT_BINARY_DIR}/src/configuration.hpp)
  38. # Collect source files
  39. file(GLOB_RECURSE SOURCE_FILES
  40. ${PROJECT_SOURCE_DIR}/src/*.cpp)
  41. if(MSVC)
  42. # Generate Windows icon resource file
  43. set(ICON_FILE "${PROJECT_SOURCE_DIR}/../antkeeper-data/src/icons/antkeeper.ico")
  44. configure_file(${PROJECT_SOURCE_DIR}/src/platform/windows/icon.rc.in
  45. ${PROJECT_BINARY_DIR}/src/platform/windows/icon.rc)
  46. # Add executable icon
  47. list(APPEND SOURCE_FILES "${PROJECT_BINARY_DIR}/src/platform/windows/icon.rc")
  48. # Make DPI-aware on Windows
  49. list(APPEND SOURCE_FILES "${PROJECT_SOURCE_DIR}/src/platform/windows/dpi-aware.manifest")
  50. endif()
  51. # Add executable target
  52. set(EXECUTABLE_TARGET ${PROJECT_NAME}-executable)
  53. add_executable(${EXECUTABLE_TARGET} ${SOURCE_FILES})
  54. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
  55. # Add compile definitions
  56. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  57. target_compile_definitions(${EXECUTABLE_TARGET} PRIVATE DEBUG)
  58. else()
  59. target_compile_definitions(${EXECUTABLE_TARGET} PRIVATE NDEBUG)
  60. endif()
  61. # Set C++17 standard
  62. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES
  63. CXX_STANDARD 17
  64. CXX_EXTENSIONS OFF)
  65. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  66. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES COMPILE_FLAGS "-std=c++17")
  67. elseif(MSVC)
  68. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES COMPILE_FLAGS "/std:c++17")
  69. endif()
  70. # Set link flags to show console window on debug builds and hide it on release builds
  71. if(MSVC)
  72. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE")
  73. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS /ENTRY:\"mainCRTStartup\"")
  74. endif(MSVC)
  75. # Set include directories
  76. target_include_directories(${EXECUTABLE_TARGET}
  77. PUBLIC
  78. ${PROJECT_SOURCE_DIR}/src
  79. ${PROJECT_BINARY_DIR}/src)
  80. # Link to dependencies
  81. target_link_libraries(${EXECUTABLE_TARGET} ${STATIC_LIBS} ${SHARED_LIBS})
  82. # Install executable
  83. if(PACKAGE_PLATFORM MATCHES "linux")
  84. install(TARGETS ${EXECUTABLE_TARGET} DESTINATION bin)
  85. elseif(PACKAGE_PLATFORM MATCHES "win")
  86. # Install executable
  87. install(TARGETS ${EXECUTABLE_TARGET} DESTINATION .)
  88. # Install SDL2 DLLs
  89. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  90. get_target_property(SDL2_DLL SDL2::SDL2 IMPORTED_LOCATION_DEBUG)
  91. else()
  92. get_target_property(SDL2_DLL SDL2::SDL2 IMPORTED_LOCATION_RELEASE)
  93. endif()
  94. install(FILES ${SDL2_DLL} DESTINATION .)
  95. # Install OpenAL DLL
  96. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  97. get_target_property(OPENAL_DLL OpenAL::OpenAL IMPORTED_LOCATION_DEBUG)
  98. else()
  99. get_target_property(OPENAL_DLL OpenAL::OpenAL IMPORTED_LOCATION_RELEASE)
  100. endif()
  101. install(FILES ${OPENAL_DLL} DESTINATION .)
  102. endif()