CMakeLists.txt 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. cmake_minimum_required(VERSION 3.10)
  2. project(spine-glfw)
  3. include(FetchContent)
  4. # Suppress dependency targets from appearing in IDE
  5. set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
  6. # Fetch GLFW with minimal targets
  7. set(GLFW_BUILD_EXAMPLES OFF)
  8. set(GLFW_BUILD_TESTS OFF)
  9. set(GLFW_BUILD_DOCS OFF)
  10. set(GLFW_INSTALL OFF)
  11. FetchContent_Declare(
  12. glfw
  13. GIT_REPOSITORY https://github.com/glfw/glfw.git
  14. GIT_TAG latest
  15. GIT_SHALLOW 1
  16. )
  17. FetchContent_MakeAvailable(glfw)
  18. # Fetch glbinding with minimal targets
  19. set(OPTION_BUILD_DOCS OFF)
  20. set(OPTION_BUILD_EXAMPLES OFF)
  21. set(OPTION_BUILD_TEST OFF)
  22. set(OPTION_BUILD_TOOLS OFF)
  23. FetchContent_Declare(
  24. glbinding
  25. GIT_REPOSITORY https://github.com/cginternals/glbinding.git
  26. GIT_TAG v3.4.0
  27. GIT_SHALLOW 1
  28. )
  29. FetchContent_MakeAvailable(glbinding)
  30. # Organize dependency targets into folders for cleaner IDE view
  31. set_property(GLOBAL PROPERTY USE_FOLDERS ON)
  32. set_target_properties(glfw PROPERTIES FOLDER "Dependencies")
  33. set_target_properties(glbinding PROPERTIES FOLDER "Dependencies")
  34. set_target_properties(glbinding-aux PROPERTIES FOLDER "Dependencies")
  35. if(TARGET glbinding-glmeta)
  36. set_target_properties(glbinding-glmeta PROPERTIES FOLDER "Dependencies")
  37. endif()
  38. if(TARGET KHRplatform-sources)
  39. set_target_properties(KHRplatform-sources PROPERTIES FOLDER "Dependencies")
  40. endif()
  41. if(TARGET cubescape-sdl-gl)
  42. set_target_properties(cubescape-sdl-gl PROPERTIES FOLDER "Dependencies/glbinding-examples")
  43. endif()
  44. if(TARGET cubescape-sdl-gles)
  45. set_target_properties(cubescape-sdl-gles PROPERTIES FOLDER "Dependencies/glbinding-examples")
  46. endif()
  47. if(TARGET cubescape-shared-gl)
  48. set_target_properties(cubescape-shared-gl PROPERTIES FOLDER "Dependencies/glbinding-examples")
  49. endif()
  50. if(TARGET cubescape-shared-gles)
  51. set_target_properties(cubescape-shared-gles PROPERTIES FOLDER "Dependencies/glbinding-examples")
  52. endif()
  53. # Organize cmake utility targets
  54. if(TARGET uninstall)
  55. set_target_properties(uninstall PROPERTIES FOLDER "CMake")
  56. endif()
  57. if(TARGET update_mappings)
  58. set_target_properties(update_mappings PROPERTIES FOLDER "CMake")
  59. endif()
  60. if(TARGET pack)
  61. set_target_properties(pack PROPERTIES FOLDER "CMake")
  62. endif()
  63. if(TARGET pack-glbinding)
  64. set_target_properties(pack-glbinding PROPERTIES FOLDER "CMake")
  65. endif()
  66. if(TARGET install)
  67. set_target_properties(install PROPERTIES FOLDER "CMake")
  68. endif()
  69. if(TARGET component_install)
  70. set_target_properties(component_install PROPERTIES FOLDER "CMake")
  71. endif()
  72. if(TARGET ALL_BUILD)
  73. set_target_properties(ALL_BUILD PROPERTIES FOLDER "CMake")
  74. endif()
  75. if(TARGET ZERO_CHECK)
  76. set_target_properties(ZERO_CHECK PROPERTIES FOLDER "CMake")
  77. endif()
  78. include_directories(${glbinding_SOURCE_DIR}/include)
  79. include_directories(src)
  80. # Find local OpenGL lib
  81. find_package(OpenGL REQUIRED)
  82. # Default flags
  83. include(${CMAKE_SOURCE_DIR}/../flags.cmake)
  84. # Add spine-cpp
  85. add_subdirectory(${CMAKE_SOURCE_DIR}/../spine-cpp ${CMAKE_BINARY_DIR}/spine-cpp-build)
  86. # spine-glfw library
  87. add_library(spine-glfw STATIC src/spine-glfw.cpp src/spine-glfw.h src/stb_image.h)
  88. target_link_libraries(spine-glfw PRIVATE glbinding::glbinding)
  89. target_link_libraries(spine-glfw LINK_PUBLIC spine-cpp-lite)
  90. # Example
  91. add_executable(spine-glfw-example example/main.cpp)
  92. target_link_libraries(spine-glfw-example PRIVATE glfw)
  93. target_link_libraries(spine-glfw-example PRIVATE OpenGL::GL)
  94. target_link_libraries(spine-glfw-example LINK_PUBLIC spine-glfw)
  95. target_link_libraries(spine-glfw-example PRIVATE glbinding::glbinding)
  96. set_property(TARGET spine-glfw-example PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/spine-glfw")
  97. # spine-cpp-lite Example
  98. add_executable(spine-glfw-example-cpp-lite example/main-cpp-lite.cpp)
  99. target_link_libraries(spine-glfw-example-cpp-lite PRIVATE glfw)
  100. target_link_libraries(spine-glfw-example-cpp-lite PRIVATE OpenGL::GL)
  101. target_link_libraries(spine-glfw-example-cpp-lite LINK_PUBLIC spine-glfw)
  102. target_link_libraries(spine-glfw-example-cpp-lite PRIVATE glbinding::glbinding)
  103. set_property(TARGET spine-glfw-example-cpp-lite PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/spine-glfw")
  104. # copy data to build directory
  105. add_custom_command(TARGET spine-glfw-example PRE_BUILD
  106. COMMAND ${CMAKE_COMMAND} -E copy_directory
  107. ${CMAKE_CURRENT_LIST_DIR}/data $<TARGET_FILE_DIR:spine-glfw-example>/data)