CMakeLists.txt 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. cmake_minimum_required(VERSION 3.10)
  2. project( vkw LANGUAGES CXX)
  3. ################################################################################
  4. # Create an interface for vkw so that it can be
  5. # included as a subdir
  6. ################################################################################
  7. add_library(vkw INTERFACE)
  8. add_library(vkw::vkw ALIAS vkw)
  9. target_include_directories(vkw INTERFACE include)
  10. target_link_libraries( vkw INTERFACE)
  11. ################################################################################
  12. ################################################################################
  13. # Only create examples if this project is a root project
  14. # if it is included as a subdirectory it will not create the examples
  15. ################################################################################
  16. get_directory_property(vkw_has_parent PARENT_DIRECTORY)
  17. if(vkw_has_parent)
  18. # Don't build examples if we are a submodule.
  19. message("Not building examples")
  20. option(VKW_BUILD_EXAMPLES "Build examples" OFF)
  21. else()
  22. option(VKW_BUILD_EXAMPLES "Build examples" ON)
  23. endif()
  24. ################################################################################
  25. if( VKW_BUILD_EXAMPLES )
  26. # Set the current binary directory
  27. set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_MODULE_PATH})
  28. # Needed for vulkan
  29. find_package(Vulkan REQUIRED)
  30. find_package(SDL2 REQUIRED)
  31. find_package(glfw3 REQUIRED)
  32. SET(vulkan_libs Vulkan::Vulkan)
  33. add_executable( example_GLFWWindow examples/example_GLFWWindow.cpp )
  34. target_link_libraries(example_GLFWWindow glfw::glfw vkw::vkw ${vulkan_libs})
  35. add_executable( example_SDLWindow examples/example_SDLWindow.cpp )
  36. target_link_libraries(example_SDLWindow SDL2::SDL2 vkw::vkw ${vulkan_libs} )
  37. add_executable( example_SDLWindow_vulkanProfiles examples/example_SDLWindow_vulkanProfiles.cpp )
  38. target_link_libraries(example_SDLWindow_vulkanProfiles SDL2::SDL2 vkw::vkw ${vulkan_libs} )
  39. add_executable( example_widget_sdl examples/example_widget.cpp )
  40. target_link_libraries(example_widget_sdl SDL2::SDL2 vkw::vkw ${vulkan_libs})
  41. target_compile_definitions(example_widget_sdl PRIVATE VKW_WINDOW_LIB=1)
  42. add_executable( example_widget_glfw examples/example_widget.cpp )
  43. target_link_libraries(example_widget_glfw glfw::glfw vkw::vkw ${vulkan_libs})
  44. target_compile_definitions(example_widget_glfw PRIVATE VKW_WINDOW_LIB=2)
  45. set(CMAKE_AUTOUIC ON)
  46. set(CMAKE_AUTOMOC ON)
  47. set(CMAKE_AUTORCC ON)
  48. set(CMAKE_CXX_STANDARD 17)
  49. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  50. # First look for Qt6
  51. find_package(Qt6 COMPONENTS Widgets)
  52. if (QT6_INSTALL_PREFIX)
  53. add_executable( example_widget_qt examples/example_widget_qt.cpp )
  54. target_link_libraries(example_widget_qt Qt6::Widgets pthread vkw::vkw ${vulkan_libs})
  55. else()
  56. find_package(Qt5 COMPONENTS Widgets)
  57. if( Qt5Widgets_FOUND )
  58. if (Qt5Widgets_VERSION VERSION_LESS 5.15.0)
  59. message(NOTICE "Minimum supported Qt5 version is 5.15. Cannot build Qt examples!")
  60. else()
  61. add_executable( example_widget_qt examples/example_widget_qt.cpp )
  62. target_link_libraries(example_widget_qt Qt5::Widgets pthread vkw::vkw ${vulkan_libs})
  63. endif()
  64. else()
  65. message(NOTICE "The Qt5 library could not be found! Not building Qt examples")
  66. endif()
  67. endif()
  68. endif()
  69. ################################################################################