CMakeLists.txt 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. cmake_minimum_required(VERSION 3.10)
  2. project(spine-sfml)
  3. # Default flags
  4. include(${CMAKE_CURRENT_LIST_DIR}/../../flags.cmake)
  5. #
  6. # First download and extract SFML 2.6.1 for the respective OS we are on
  7. #
  8. set(DEPS_DIR "${CMAKE_CURRENT_LIST_DIR}/dependencies/")
  9. if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  10. set(CMAKE_OSX_ARCHITECTURES x86_64)
  11. set(ONLY_ACTIVE_ARCH NO)
  12. set(SFML_URL "https://www.sfml-dev.org/files/SFML-2.6.1-macOS-clang-64-bit.tar.gz")
  13. set(SFML_DIR ${DEPS_DIR}/SFML-2.6.1-macOS-clang-64-bit)
  14. if (NOT EXISTS "${SFML_DIR}")
  15. message("Downloading SFML for Mac OS X")
  16. file(DOWNLOAD "${SFML_URL}" "${DEPS_DIR}/sfml.tar.gz")
  17. execute_process(
  18. COMMAND ${CMAKE_COMMAND} -E tar xzf ${DEPS_DIR}/sfml.tar.gz
  19. WORKING_DIRECTORY ${DEPS_DIR}
  20. )
  21. # copy freetype over to Frameworks/ so rpath resolution works
  22. execute_process(
  23. COMMAND ${CMAKE_COMMAND} -E copy_directory ${SFML_DIR}/extlibs/freetype.framework ${SFML_DIR}/Frameworks/freetype.framework
  24. WORKING_DIRECTORY ${SFML_DIR}
  25. )
  26. endif()
  27. elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
  28. set(SFML_URL "https://www.sfml-dev.org/files/SFML-2.5.1-linux-gcc-64-bit.tar.gz")
  29. set(SFML_DIR ${DEPS_DIR}/SFML-2.5.1)
  30. if (NOT EXISTS ${SFML_DIR})
  31. message("Downloading SFML for Linux 64-bit")
  32. file(DOWNLOAD "${SFML_URL}" "${DEPS_DIR}/sfml.tar.gz")
  33. execute_process(
  34. COMMAND ${CMAKE_COMMAND} -E tar xzf ${DEPS_DIR}/sfml.tar.gz
  35. WORKING_DIRECTORY ${DEPS_DIR}
  36. )
  37. endif()
  38. else()
  39. set(SFML_URL "https://www.sfml-dev.org/files/SFML-2.6.1-windows-vc17-64-bit.zip")
  40. set(SFML_DIR ${DEPS_DIR}/SFML-2.6.1)
  41. if (NOT EXISTS ${SFML_DIR})
  42. message("Downloading SFML for Windows 64-bit")
  43. file(DOWNLOAD "${SFML_URL}" "${DEPS_DIR}/sfml.zip")
  44. execute_process(
  45. COMMAND ${CMAKE_COMMAND} -E tar x ${DEPS_DIR}/sfml.zip
  46. WORKING_DIRECTORY ${DEPS_DIR}
  47. )
  48. endif()
  49. endif()
  50. # Add spine-cpp
  51. add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../../spine-cpp ${CMAKE_BINARY_DIR}/spine-cpp-build)
  52. # Define spine-sfml-cpp library
  53. include_directories(src ${SFML_DIR}/include)
  54. file(GLOB INCLUDES "src/**/*.h")
  55. file(GLOB SOURCES "src/**/*.cpp")
  56. add_library(spine-sfml-cpp STATIC ${SOURCES} ${INCLUDES})
  57. target_link_libraries(spine-sfml-cpp LINK_PUBLIC spine-cpp)
  58. install(TARGETS spine-sfml-cpp DESTINATION dist/lib)
  59. install(FILES ${INCLUDES} DESTINATION dist/include)
  60. # Define spine-sfml example executable
  61. add_executable(spine-sfml-cpp-example example/main.cpp)
  62. target_link_libraries(spine-sfml-cpp-example spine-cpp spine-sfml-cpp)
  63. # Define spine-sfml testbed executable
  64. add_executable(spine-sfml-cpp-testbed example/testbed.cpp)
  65. target_link_libraries(spine-sfml-cpp-testbed spine-cpp spine-sfml-cpp)
  66. # Link in SFML libraries and OS dependencies like OpenGL
  67. if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  68. find_library(SFML SFML PATHS ${SFML_DIR}/Frameworks)
  69. find_library(SFML_SYSTEM "sfml-system" PATHS ${SFML_DIR}/Frameworks)
  70. find_library(SFML_WINDOW sfml-window PATHS ${SFML_DIR}/Frameworks)
  71. find_library(SFML_GRAPHICS sfml-graphics PATHS ${SFML_DIR}/Frameworks)
  72. target_link_libraries(spine-sfml-cpp-example ${SFML} ${SFML_SYSTEM} ${SFML_WINDOW} ${SFML_GRAPHICS})
  73. target_link_libraries(spine-sfml-cpp-testbed ${SFML} ${SFML_SYSTEM} ${SFML_WINDOW} ${SFML_GRAPHICS})
  74. elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
  75. target_link_libraries(spine-sfml-cpp-example sfml-graphics sfml-window sfml-system)
  76. target_link_libraries(spine-sfml-cpp-testbed sfml-graphics sfml-window sfml-system)
  77. else()
  78. set(SFML_LIBS ${SFML_DIR}/lib)
  79. target_link_libraries(spine-sfml-cpp-example ${SFML_LIBS}/sfml-main-d.lib)
  80. target_link_libraries(spine-sfml-cpp-example ${SFML_LIBS}/sfml-graphics-s-d.lib)
  81. target_link_libraries(spine-sfml-cpp-example ${SFML_LIBS}/sfml-window-s-d.lib)
  82. target_link_libraries(spine-sfml-cpp-example ${SFML_LIBS}/sfml-system-s-d.lib)
  83. target_link_libraries(spine-sfml-cpp-example ${SFML_LIBS}/freetype.lib)
  84. target_link_libraries(spine-sfml-cpp-example opengl32)
  85. target_link_libraries(spine-sfml-cpp-example gdi32)
  86. target_link_libraries(spine-sfml-cpp-example winmm)
  87. target_link_libraries(spine-sfml-cpp-testbed ${SFML_LIBS}/sfml-main-d.lib)
  88. target_link_libraries(spine-sfml-cpp-testbed ${SFML_LIBS}/sfml-graphics-s-d.lib)
  89. target_link_libraries(spine-sfml-cpp-testbed ${SFML_LIBS}/sfml-window-s-d.lib)
  90. target_link_libraries(spine-sfml-cpp-testbed ${SFML_LIBS}/sfml-system-s-d.lib)
  91. target_link_libraries(spine-sfml-cpp-testbed ${SFML_LIBS}/freetype.lib)
  92. target_link_libraries(spine-sfml-cpp-testbed opengl32)
  93. target_link_libraries(spine-sfml-cpp-testbed gdi32)
  94. target_link_libraries(spine-sfml-cpp-testbed winmm)
  95. add_definitions(-DSFML_STATIC)
  96. endif()
  97. # copy data to build directory
  98. add_custom_command(TARGET spine-sfml-cpp-example
  99. COMMAND ${CMAKE_COMMAND} -E copy_directory
  100. ${CMAKE_CURRENT_LIST_DIR}/data $<TARGET_FILE_DIR:spine-sfml-cpp-example>/data)
  101. add_custom_command(TARGET spine-sfml-cpp-testbed
  102. COMMAND ${CMAKE_COMMAND} -E copy_directory
  103. ${CMAKE_CURRENT_LIST_DIR}/data $<TARGET_FILE_DIR:spine-sfml-cpp-example>/data)