CMakeLists.txt 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. cmake_minimum_required(VERSION 2.8.12)
  2. project("shadertoy_launcher")
  3. OPTION(USE_WAYLAND_LINUX "use Wayland for Linux" OFF)
  4. find_package(Vulkan REQUIRED)
  5. if(NOT Vulkan_FOUND)
  6. MESSAGE(FATAL_ERROR "ERROR: Vulkan not found")
  7. endif(NOT Vulkan_FOUND)
  8. set(Vulkan_LIBRARY)
  9. set(Wayland_client "")
  10. IF (NOT WIN32)
  11. if(USE_WAYLAND_LINUX)
  12. find_program(PKG_CONFIG pkg-config)
  13. if (NOT PKG_CONFIG)
  14. MESSAGE(FATAL_ERROR "pkg-config binary not found")
  15. endif ()
  16. find_program(WAYLAND_SCANNER wayland-scanner)
  17. if (NOT WAYLAND_SCANNER)
  18. MESSAGE(FATAL_ERROR "wayland-scanner binary not found")
  19. endif ()
  20. set(Wayland_client "${CMAKE_BINARY_DIR}/xdg-shell-client-protocol.c")
  21. set(WAYLAND_INCLUDE_DIR "/usr/include/wayland")
  22. MESSAGE(STATUS " Wayland include path ${WAYLAND_INCLUDE_DIR}")
  23. include_directories(${WAYLAND_INCLUDE_DIR})
  24. execute_process(COMMAND ${PKG_CONFIG} --variable=pkgdatadir wayland-protocols OUTPUT_VARIABLE protocol_dir OUTPUT_STRIP_TRAILING_WHITESPACE)
  25. execute_process(COMMAND ${WAYLAND_SCANNER} client-header ${protocol_dir}/stable/xdg-shell/xdg-shell.xml xdg-shell-client-protocol.h
  26. COMMAND ${WAYLAND_SCANNER} private-code ${protocol_dir}/stable/xdg-shell/xdg-shell.xml xdg-shell-client-protocol.c)
  27. include_directories(${CMAKE_BINARY_DIR})
  28. endif ()
  29. endif ()
  30. if (Vulkan_FOUND)
  31. MESSAGE(STATUS " [Found Vulkan library]")
  32. MESSAGE(STATUS " Vulkan include directory:" ${Vulkan_INCLUDE_DIR})
  33. FOREACH(item ${Vulkan_LIBRARIES})
  34. MESSAGE(STATUS " using lib: " ${item})
  35. ENDFOREACH()
  36. include_directories(${Vulkan_INCLUDE_DIR})
  37. endif()
  38. set(SOURCES
  39. "main.c"
  40. "../vk_utils/vk_utils.c"
  41. "../vk_utils/vk_error_print.c"
  42. "../vk_utils/vk_render_helper.c"
  43. ${Wayland_client}
  44. )
  45. add_executable(
  46. Vk_shadertoy
  47. ${SOURCES}
  48. )
  49. add_custom_command(TARGET Vk_shadertoy POST_BUILD
  50. COMMAND ${CMAKE_COMMAND} -E copy_directory
  51. ${CMAKE_SOURCE_DIR}/shaders $<TARGET_FILE_DIR:Vk_shadertoy>/shaders)
  52. add_custom_command(TARGET Vk_shadertoy POST_BUILD
  53. COMMAND ${CMAKE_COMMAND} -E copy_directory
  54. ${CMAKE_SOURCE_DIR}/textures $<TARGET_FILE_DIR:Vk_shadertoy>/textures)
  55. if(("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC"))
  56. add_definitions(-DVK_USE_PLATFORM_WIN32_KHR -DUSE_stb_image)
  57. target_link_libraries(Vk_shadertoy ${Vulkan_LIBRARY})
  58. elseif(("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") AND ("${CMAKE_SYSTEM}" MATCHES "Linux"))
  59. if(USE_WAYLAND_LINUX)
  60. add_definitions(-DVK_USE_PLATFORM_WAYLAND_KHR -DUSE_stb_image -O2 -s -fdata-sections -ffunction-sections -Wl,--gc-sections)
  61. target_link_libraries(Vk_shadertoy m wayland-client ${Vulkan_LIBRARY} )
  62. else()
  63. add_definitions(-DVK_USE_PLATFORM_XCB_KHR -DUSE_stb_image -O2 -s -fdata-sections -ffunction-sections -Wl,--gc-sections)
  64. target_link_libraries(Vk_shadertoy m xcb xcb-keysyms ${Vulkan_LIBRARY} )
  65. endif()
  66. else()
  67. message(WARNING "Unknown compiler '${CMAKE_C_COMPILER_ID}'!")
  68. endif()