CMakeLists.txt 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #
  2. # First download and extract SFML 2.5.1 for the respective OS we are on
  3. #
  4. set(DEPS_DIR "${CMAKE_CURRENT_LIST_DIR}/dependencies/")
  5. if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
  6. set(SFML_URL "https://www.sfml-dev.org/files/SFML-2.5.1-macOS-clang.tar.gz")
  7. set(SFML_DIR ${DEPS_DIR}/SFML-2.5.1-macos-clang)
  8. if (NOT EXISTS "${SFML_DIR}")
  9. message("Downloading SFML for Mac OS X")
  10. file(DOWNLOAD "${SFML_URL}" "${DEPS_DIR}/sfml.tar.gz")
  11. execute_process(
  12. COMMAND ${CMAKE_COMMAND} -E tar xzf ${DEPS_DIR}/sfml.tar.gz
  13. WORKING_DIRECTORY ${DEPS_DIR}
  14. )
  15. # copy freetype over to Frameworks/ so rpath resoultion works
  16. execute_process(
  17. COMMAND ${CMAKE_COMMAND} -E copy_directory ${SFML_DIR}/extlibs/freetype.framework ${SFML_DIR}/Frameworks/freetype.framework
  18. WORKING_DIRECTORY ${SFML_DIR}
  19. )
  20. endif()
  21. elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
  22. set(SFML_URL "https://www.sfml-dev.org/files/SFML-2.5.1-linux-gcc-64-bit.tar.gz")
  23. set(SFML_DIR ${DEPS_DIR}/SFML-2.5.1)
  24. if (NOT EXISTS ${SFML_DIR})
  25. message("Downloading SFML for Linux 64-bit")
  26. file(DOWNLOAD "${SFML_URL}" "${DEPS_DIR}/sfml.tar.gz")
  27. execute_process(
  28. COMMAND ${CMAKE_COMMAND} -E tar xzf ${DEPS_DIR}/sfml.tar.gz
  29. WORKING_DIRECTORY ${DEPS_DIR}
  30. )
  31. endif()
  32. else()
  33. set(SFML_URL "https://www.sfml-dev.org/files/SFML-2.6.1-windows-vc17-64-bit.zip")
  34. set(SFML_DIR ${DEPS_DIR}/SFML-2.6.1)
  35. if (NOT EXISTS ${SFML_DIR})
  36. message("Downloading SFML for Windows 64-bit")
  37. file(DOWNLOAD "${SFML_URL}" "${DEPS_DIR}/sfml.zip")
  38. execute_process(
  39. COMMAND ${CMAKE_COMMAND} -E tar x ${DEPS_DIR}/sfml.zip
  40. WORKING_DIRECTORY ${DEPS_DIR}
  41. )
  42. endif()
  43. endif()
  44. if(MSVC)
  45. message("MSCV detected")
  46. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS")
  47. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_CRT_SECURE_NO_WARNINGS")
  48. else()
  49. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -std=c99")
  50. set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wnon-virtual-dtor -pedantic -std=c++11 -fno-exceptions -fno-rtti")
  51. endif()
  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)