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

68 lines
2.2 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 link flags to show console window on debug builds and hide it on release builds
  43. if(MSVC)
  44. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE")
  45. set_target_properties(${EXECUTABLE_TARGET} PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS /ENTRY:\"mainCRTStartup\"")
  46. endif(MSVC)
  47. # Set include directories
  48. target_include_directories(${EXECUTABLE_TARGET}
  49. PUBLIC
  50. ${PROJECT_SOURCE_DIR}/src
  51. ${PROJECT_BINARY_DIR}/src)
  52. # Link to dependencies
  53. target_link_libraries(${EXECUTABLE_TARGET} ${STATIC_LIBS} ${SHARED_LIBS})
  54. # Install executable
  55. install(TARGETS ${EXECUTABLE_TARGET} DESTINATION bin)