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

92 lines
2.9 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. # Add executable target
  33. set(EXECUTABLE_TARGET ${PROJECT_NAME}-executable)
  34. add_executable(${EXECUTABLE_TARGET} ${SOURCE_FILES})
  35. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
  36. # Add compile definitions
  37. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  38. target_compile_definitions(${EXECUTABLE_TARGET} PRIVATE DEBUG)
  39. else()
  40. target_compile_definitions(${EXECUTABLE_TARGET} PRIVATE NDEBUG)
  41. endif()
  42. # Set C++17 standard
  43. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES
  44. CXX_STANDARD 17
  45. CXX_EXTENSIONS OFF)
  46. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  47. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES COMPILE_FLAGS "-std=c++17")
  48. elseif(MSVC)
  49. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES COMPILE_FLAGS "/std:c++17")
  50. endif()
  51. # Set link flags to show console window on debug builds and hide it on release builds
  52. if(MSVC)
  53. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE")
  54. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS /ENTRY:\"mainCRTStartup\"")
  55. endif(MSVC)
  56. # Set include directories
  57. target_include_directories(${EXECUTABLE_TARGET}
  58. PUBLIC
  59. ${PROJECT_SOURCE_DIR}/src
  60. ${PROJECT_BINARY_DIR}/src)
  61. # Link to dependencies
  62. target_link_libraries(${EXECUTABLE_TARGET} ${STATIC_LIBS} ${SHARED_LIBS})
  63. # Install executable
  64. if(PACKAGE_PLATFORM MATCHES "linux")
  65. install(TARGETS ${EXECUTABLE_TARGET} DESTINATION bin)
  66. elseif(PACKAGE_PLATFORM MATCHES "win")
  67. # Install executable
  68. install(TARGETS ${EXECUTABLE_TARGET} DESTINATION .)
  69. # Install OpenAL DLL
  70. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  71. get_target_property(OPENAL_DLL OpenAL::OpenAL IMPORTED_LOCATION_DEBUG)
  72. else()
  73. get_target_property(OPENAL_DLL OpenAL::OpenAL IMPORTED_LOCATION_RELEASE)
  74. endif()
  75. install(FILES ${OPENAL_DLL} DESTINATION .)
  76. endif()