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

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