CMakeLists.txt 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. cmake_minimum_required(VERSION 3.0)
  2. project(Asteroids)
  3. set(OpenGL_GL_PREFERENCE GLVND)
  4. # setup deps
  5. set(GLFW_ROOT "${CMAKE_SOURCE_DIR}/deps/glfw")
  6. set(GLFW_INC "${GLFW_ROOT}/include")
  7. set(GLAD_ROOT "${CMAKE_SOURCE_DIR}/deps/glad")
  8. set(GLAD_INC "${GLAD_ROOT}/include")
  9. set(GLAD_SRC "${GLAD_ROOT}/src/glad.c")
  10. set(GLM_ROOT "${CMAKE_SOURCE_DIR}/deps/glm")
  11. set(GLM_INC "${GLM_ROOT}")
  12. # asteroids target
  13. file(GLOB CCSOURCES src/*.cc)
  14. add_executable(asteroids ${CCSOURCES} ${GLAD_SRC})
  15. # c++ flags
  16. set(CMAKE_CXX_STANDARD 14)
  17. if(MINGW)
  18. set(CMAKE_EXE_LINKER_FLAGS "-static -static-libgcc -static-libstdc++")
  19. set_target_properties(asteroids PROPERTIES LINK_SEARCH_END_STATIC 1)
  20. target_link_libraries(asteroids -mwindows)
  21. endif()
  22. set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -s -O2")
  23. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s -O2")
  24. # glfw
  25. set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
  26. set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
  27. set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
  28. add_subdirectory(${GLFW_ROOT})
  29. find_package(OpenGL REQUIRED)
  30. # asteroids
  31. include_directories(
  32. include
  33. ${GLFW_INC}
  34. ${GLAD_INC}
  35. ${GLM_INC}
  36. )
  37. target_link_libraries(asteroids glfw ${OPENGL_gl_LIBRARY})
  38. add_custom_target(copy_resources ALL
  39. COMMAND ${CMAKE_COMMAND} -E copy_directory
  40. ${CMAKE_SOURCE_DIR}/resources ${CMAKE_CURRENT_BINARY_DIR}/resources
  41. COMMAND ${CMAKE_COMMAND} -E copy
  42. ${CMAKE_SOURCE_DIR}/deps/SDL_GameControllerDB/gamecontrollerdb.txt
  43. ${CMAKE_CURRENT_BINARY_DIR}/resources
  44. )
  45. add_custom_target(zip DEPENDS copy_resources asteroids
  46. COMMAND ${CMAKE_COMMAND} -E tar "cfv" "asteroids.zip" --format="zip"
  47. "${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_FILE_NAME:asteroids>"
  48. "${CMAKE_CURRENT_BINARY_DIR}/resources"
  49. )