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

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