libcruft-vk/CMakeLists.txt

231 lines
5.8 KiB
CMake

###############################################################################
cmake_minimum_required(VERSION 3.18.0)
project(cruft-vulkan CXX)
###############################################################################
find_package (PythonInterp 3 REQUIRED)
find_package (glfw3 REQUIRED)
find_program (GLSLANG glslangValidator REQUIRED)
###############################################################################
set (GENERATED_BASE "${CMAKE_CURRENT_BINARY_DIR}/prefix")
set (GENERATED_PREFIX "${GENERATED_BASE}/cruft/vk/")
file (MAKE_DIRECTORY "${GENERATED_PREFIX}/load")
file (MAKE_DIRECTORY "${GENERATED_PREFIX}/tools")
if (WIN32)
set(VK_PLATFORM "win32")
elseif(LINUX)
set(VK_PLATFORM "xcb")
else()
message(FATAL_ERROR "unhandled platform")
endif()
##-----------------------------------------------------------------------------
add_custom_command (
OUTPUT
"${GENERATED_PREFIX}/vk.hpp"
"${GENERATED_PREFIX}/load/dispatch.cpp"
"${GENERATED_PREFIX}/load/vtable.hpp"
"${GENERATED_PREFIX}/tools/trace.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" "${GENERATED_PREFIX}/vk.hpp"
"--load" "${GENERATED_PREFIX}/load/vtable.hpp"
"--dispatch" "${GENERATED_PREFIX}/load/dispatch.cpp"
"--trace" "${GENERATED_PREFIX}/tools/trace.cpp"
"--platform" "${VK_PLATFORM}"
DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/tools/spec.py"
"${CMAKE_CURRENT_SOURCE_DIR}/specs/xml/vk.xml"
)
###############################################################################
if (WIN32)
set(VK_LOADER_VENDOR win32)
elseif (LINUX)
set(VK_LOADER_VENDOR posix)
else ()
message (FATAL_ERROR "unhandled vk-loader platform")
endif()
##-----------------------------------------------------------------------------
list (APPEND VK_LOAD_SOURCES
load/fwd.hpp
${GENERATED_PREFIX}/load/vtable.hpp
${GENERATED_PREFIX}/load/dispatch.cpp
load/dispatch.hpp
load/init.cpp
load/ostream.cpp
load/ostream.hpp
load/vendor.hpp
load/vendor.cpp
load/vendor_${VK_LOADER_VENDOR}.cpp
load/vtable.cpp
)
add_library (vulkan SHARED ${VK_LOAD_SOURCES})
set_target_properties(vulkan PROPERTIES VERSION 1.1.98)
set_target_properties(vulkan PROPERTIES SOVERSION 1)
add_library (cruft-vk-load STATIC ${VK_LOAD_SOURCES})
foreach (lib vulkan cruft-vk-load)
target_include_directories (${lib}
PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}"
"${GENERATED_PREFIX}"
"${CMAKE_CURRENT_SOURCE_DIR}/specs/include/vulkan"
)
target_link_libraries (${lib} cruft-json cruft)
endforeach ()
###############################################################################
list (APPEND sources
"${GENERATED_PREFIX}/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
meta/info.cpp
meta/info.hpp
)
##-----------------------------------------------------------------------------
add_library (cruft-vk STATIC ${sources})
target_link_libraries (cruft-vk cruft)
target_include_directories (cruft-vk
PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}"
"${GENERATED_PREFIX}"
"${CMAKE_CURRENT_SOURCE_DIR}/specs/include/vulkan"
)
###############################################################################
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")
endforeach ()
target_link_libraries (vk_info cruft-vk cruft-vk-load)
target_link_libraries (vk_hello ${NC_CXX_STDCXXFS} cruft cruft-vk glfw vulkan)
add_library (trace SHARED
"${GENERATED_PREFIX}/tools/trace.cpp"
)
target_include_directories (trace
PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}"
"${CMAKE_CURRENT_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/specs/include/vulkan"
)
target_link_libraries(trace cruft-vk)
##-----------------------------------------------------------------------------
add_dependencies (vk_hello hello.vert.spv hello.frag.spv)
###############################################################################
configure_file(libcruft-vk.pc.in libcruft-vk.pc)
configure_file(Doxyfile.in Doxyfile)