############################################################################### cmake_minimum_required(VERSION 3.7.0) project(cruft-vulkan CXX) ############################################################################### find_package (PythonInterp 3 REQUIRED) find_package (glfw3 REQUIRED) find_program (GLSLANG glslangValidator) if (NOT GLSLANG) message (FATAL_ERROR "could not locate glslangValidator") endif () ############################################################################### file (MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/icd") include_directories ("${CMAKE_CURRENT_BINARY_DIR}") if (WIN32) set(VK_PLATFORM "win32") elseif(LINUX) set(VK_PLATFORM "xcb") else() message(FATAL_ERROR "unhandled platform") endif() ##----------------------------------------------------------------------------- add_custom_command ( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/vk.hpp" "${CMAKE_CURRENT_BINARY_DIR}/icd/dispatch.cpp" COMMENT "[spec.py] vk.hpp" COMMAND "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/tools/spec.py" "--src" "${CMAKE_CURRENT_SOURCE_DIR}/specs/xml/vk.xml" "--dst" "${CMAKE_CURRENT_BINARY_DIR}/vk.hpp" "--dispatch" "${CMAKE_CURRENT_BINARY_DIR}/icd/dispatch.cpp" "--platform" "${VK_PLATFORM}" DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/tools/spec.py" "${CMAKE_CURRENT_SOURCE_DIR}/specs/xml/vk.xml" ) include_directories("${CMAKE_CURRENT_SOURCE_DIR}/specs/include/vulkan") ############################################################################### if (WIN32) set(VK_LOADER_VENDOR win32) elseif (LINUX) set(VK_LOADER_VENDOR posix) else () message (FATAL_ERROR "unhandled vk-loader platform") endif() ##----------------------------------------------------------------------------- add_library (cruft-vk-icd STATIC ${CMAKE_CURRENT_BINARY_DIR}/icd/dispatch.cpp icd/vendor.hpp icd/vendor.cpp icd/vendor_${VK_LOADER_VENDOR} ) target_link_libraries (cruft-vk-icd cruft-json cruft) ############################################################################### list (APPEND sources vk.hpp fwd.hpp object.cpp object.hpp buffer.cpp buffer.hpp callback.hpp command_buffer.cpp command_buffer.hpp command_pool.cpp command_pool.hpp device.cpp device.hpp device_memory.cpp device_memory.hpp event.cpp event.hpp except.cpp except.hpp fence.cpp fence.hpp framebuffer.cpp framebuffer.hpp instance.cpp instance.hpp image.cpp image.hpp image_view.hpp ostream.cpp ostream.hpp physical_device.cpp physical_device.hpp pipeline.cpp pipeline.hpp pipeline_cache.cpp pipeline_cache.hpp pipeline_layout.cpp pipeline_layout.hpp queue.cpp queue.hpp render_pass.cpp render_pass.hpp semaphore.cpp semaphore.hpp shader_module.cpp shader_module.hpp surface.cpp surface.hpp swapchain.hpp traits.cpp traits.hpp ) ##----------------------------------------------------------------------------- add_library (cruft-vk STATIC ${sources}) target_link_libraries (cruft-vk cruft-vk-icd cruft) ############################################################################### list (APPEND shaders tools/hello/shader.vert tools/hello/shader.frag ) foreach (src ${shaders}) set(src "${CMAKE_CURRENT_SOURCE_DIR}/${src}") get_filename_component(ext ${src} EXT) get_filename_component(name ${src} DIRECTORY) get_filename_component(name ${name} NAME) set(label "${name}${ext}.spv") set(dst "${CMAKE_CURRENT_BINARY_DIR}/tools/${label}") add_custom_command( OUTPUT ${dst} COMMAND ${GLSLANG} -s -o ${dst} -V100 ${src} DEPENDS ${src} COMMENT "[glslang] ${label}" VERBATIM ) add_custom_target(${label} DEPENDS ${dst}) endforeach () ############################################################################### foreach (t info hello) add_executable (vk_${t} "tools/${t}.cpp") set_target_properties(vk_${t} PROPERTIES OUTPUT_NAME ${t}) set_target_properties(vk_${t} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/tools") target_link_libraries (vk_${t} cruft-vk glfw) endforeach () ##----------------------------------------------------------------------------- add_dependencies (vk_hello hello.vert.spv hello.frag.spv) ############################################################################### configure_file(libcruft-vk.pc.in libcruft-vk.pc) configure_file(Doxyfile.in Doxyfile)