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

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