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

97 lines
3.1 KiB

5 years ago
5 years ago
5 years ago
  1. # Prevent in-source builds
  2. if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
  3. message(FATAL_ERROR "In-source builds prohibited. Call cmake from the build directory.")
  4. endif()
  5. cmake_minimum_required(VERSION 3.7)
  6. # Set compiler flags
  7. if(CMAKE_COMPILER_IS_GNUCC)
  8. set(CMAKE_CXX_FLAGS "-Wall -Wextra")
  9. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g")
  10. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3")
  11. elseif(MSVC)
  12. set(CMAKE_CXX_FLAGS "/W3 /MP /MD")
  13. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS}")
  14. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} /Ox")
  15. endif()
  16. # Include project macro
  17. include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/project.cmake)
  18. # Find dependency packages
  19. find_package(emergent REQUIRED CONFIG)
  20. find_package(OpenAL REQUIRED CONFIG)
  21. # Determine dependencies
  22. set(STATIC_LIBS
  23. emergent)
  24. set(SHARED_LIBS
  25. OpenAL::OpenAL)
  26. # Generate configuration header file
  27. configure_file(${PROJECT_SOURCE_DIR}/src/configuration.hpp.in
  28. ${PROJECT_BINARY_DIR}/src/configuration.hpp)
  29. # Collect source files
  30. file(GLOB_RECURSE SOURCE_FILES
  31. ${PROJECT_SOURCE_DIR}/src/*.cpp)
  32. # Make DPI-aware on Windows
  33. if(MSVC)
  34. list(APPEND SOURCE_FILES "${PROJECT_SOURCE_DIR}/src/dpi-aware.manifest")
  35. endif()
  36. # Add executable target
  37. set(EXECUTABLE_TARGET ${PROJECT_NAME}-executable)
  38. add_executable(${EXECUTABLE_TARGET} ${SOURCE_FILES})
  39. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
  40. # Add compile definitions
  41. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  42. target_compile_definitions(${EXECUTABLE_TARGET} PRIVATE DEBUG)
  43. else()
  44. target_compile_definitions(${EXECUTABLE_TARGET} PRIVATE NDEBUG)
  45. endif()
  46. # Set C++17 standard
  47. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES
  48. CXX_STANDARD 17
  49. CXX_EXTENSIONS OFF)
  50. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  51. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES COMPILE_FLAGS "-std=c++17")
  52. elseif(MSVC)
  53. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES COMPILE_FLAGS "/std:c++17")
  54. endif()
  55. # Set link flags to show console window on debug builds and hide it on release builds
  56. if(MSVC)
  57. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE")
  58. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS /ENTRY:\"mainCRTStartup\"")
  59. endif(MSVC)
  60. # Set include directories
  61. target_include_directories(${EXECUTABLE_TARGET}
  62. PUBLIC
  63. ${PROJECT_SOURCE_DIR}/src
  64. ${PROJECT_BINARY_DIR}/src)
  65. # Link to dependencies
  66. target_link_libraries(${EXECUTABLE_TARGET} ${STATIC_LIBS} ${SHARED_LIBS})
  67. # Install executable
  68. if(PACKAGE_PLATFORM MATCHES "linux")
  69. install(TARGETS ${EXECUTABLE_TARGET} DESTINATION bin)
  70. elseif(PACKAGE_PLATFORM MATCHES "win")
  71. # Install executable
  72. install(TARGETS ${EXECUTABLE_TARGET} DESTINATION .)
  73. # Install OpenAL DLL
  74. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  75. get_target_property(OPENAL_DLL OpenAL::OpenAL IMPORTED_LOCATION_DEBUG)
  76. else()
  77. get_target_property(OPENAL_DLL OpenAL::OpenAL IMPORTED_LOCATION_RELEASE)
  78. endif()
  79. install(FILES ${OPENAL_DLL} DESTINATION .)
  80. endif()