From 24baf3f59b5841d1bd15aa6353255959d3940c07 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Tue, 16 Jan 2018 08:05:39 +0100 Subject: [PATCH] cmake files to build shared lib --- .gitignore | 1 + CMakeLists.txt | 45 +++++++++++++++++++++++ cmake/FindGLFW3.cmake | 49 ++++++++++++++++++++++++++ vkhelpers.h => include/vkh.h | 1 + vkh_buffer.c => src/vkh_buffer.c | 0 vkh_buffer.h => src/vkh_buffer.h | 2 +- vkh_device.c => src/vkh_device.c | 0 vkh_device.h => src/vkh_device.h | 2 +- vkh_image.c => src/vkh_image.c | 0 vkh_image.h => src/vkh_image.h | 2 +- vkh_presenter.c => src/vkh_presenter.c | 0 src/vkh_presenter.h | 39 ++++++++++++++++++++ vkhelpers.c => src/vkhelpers.c | 2 +- vkh.pc.in | 12 +++++++ vkh_presenter.h | 8 ----- 15 files changed, 151 insertions(+), 12 deletions(-) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 cmake/FindGLFW3.cmake rename vkhelpers.h => include/vkh.h (98%) rename vkh_buffer.c => src/vkh_buffer.c (100%) rename vkh_buffer.h => src/vkh_buffer.h (95%) rename vkh_device.c => src/vkh_device.c (100%) rename vkh_device.h => src/vkh_device.h (89%) rename vkh_image.c => src/vkh_image.c (100%) rename vkh_image.h => src/vkh_image.h (94%) rename vkh_presenter.c => src/vkh_presenter.c (100%) create mode 100644 src/vkh_presenter.h rename vkhelpers.c => src/vkhelpers.c (99%) create mode 100644 vkh.pc.in delete mode 100644 vkh_presenter.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..7bf1302 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,45 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 3.9) + +PROJECT(vkh VERSION 0.1.0 DESCRIPTION "Vulkan helpers library") + +SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") +SET(CMAKE_CXX_FLAGS "-W -Wall") +SET(CMAKE_EXE_LINKER_FLAGS "-lm") + +IF(NOT CMAKE_BUILD_TYPE) + SET(CMAKE_BUILD_TYPE Release) +ENDIF() +MESSAGE(STATUS "${CMAKE_BUILD_TYPE} build.") + +FIND_PACKAGE(Vulkan REQUIRED) +FIND_PACKAGE(GLFW3 REQUIRED) + +INCLUDE(GNUInstallDirs) + +FILE(GLOB VKH_SRC src/*.c) + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${VKH_SRC}) + +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION 1 + PUBLIC_HEADER include/vkh.h +) + +TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${CMAKE_CURRENT_SOURCE_DIR}/src +) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} + ${Vulkan_LIBRARY} + ${GLFW3_LIBRARY} +) + +CONFIGURE_FILE(vkh.pc.in vkh.pc @ONLY) + +INSTALL(FILES ${CMAKE_BINARY_DIR}/vkh.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig) +INSTALL(TARGETS ${PROJECT_NAME} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + diff --git a/cmake/FindGLFW3.cmake b/cmake/FindGLFW3.cmake new file mode 100644 index 0000000..13bbb84 --- /dev/null +++ b/cmake/FindGLFW3.cmake @@ -0,0 +1,49 @@ +# Locate the glfw3 library +# +# This module defines the following variables: +# +# GLFW3_LIBRARY the name of the library; +# GLFW3_INCLUDE_DIR where to find glfw include files. +# GLFW3_FOUND true if both the GLFW3_LIBRARY and GLFW3_INCLUDE_DIR have been found. +# +# To help locate the library and include file, you can define a +# variable called GLFW3_ROOT which points to the root of the glfw library +# installation. +# +# default search dirs +# +# Cmake file from: https://github.com/daw42/glslcookbook + +set( _glfw3_HEADER_SEARCH_DIRS +"/usr/include" +"/usr/local/include" +"${CMAKE_SOURCE_DIR}/includes" +"C:/Program Files (x86)/glfw/include" ) +set( _glfw3_LIB_SEARCH_DIRS +"/usr/lib" +"/usr/local/lib" +"${CMAKE_SOURCE_DIR}/lib" +"C:/Program Files (x86)/glfw/lib-msvc110" ) + +# Check environment for root search directory +set( _glfw3_ENV_ROOT $ENV{GLFW3_ROOT} ) +if( NOT GLFW3_ROOT AND _glfw3_ENV_ROOT ) + set(GLFW3_ROOT ${_glfw3_ENV_ROOT} ) +endif() + +# Put user specified location at beginning of search +if( GLFW3_ROOT ) + list( INSERT _glfw3_HEADER_SEARCH_DIRS 0 "${GLFW3_ROOT}/include" ) + list( INSERT _glfw3_LIB_SEARCH_DIRS 0 "${GLFW3_ROOT}/lib" ) +endif() + +# Search for the header +FIND_PATH(GLFW3_INCLUDE_DIR "GLFW/glfw3.h" +PATHS ${_glfw3_HEADER_SEARCH_DIRS} ) + +# Search for the library +FIND_LIBRARY(GLFW3_LIBRARY NAMES glfw3 glfw +PATHS ${_glfw3_LIB_SEARCH_DIRS} ) +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLFW3 DEFAULT_MSG +GLFW3_LIBRARY GLFW3_INCLUDE_DIR) diff --git a/vkhelpers.h b/include/vkh.h similarity index 98% rename from vkhelpers.h rename to include/vkh.h index 67dcb93..efee4a7 100644 --- a/vkhelpers.h +++ b/include/vkh.h @@ -25,6 +25,7 @@ typedef struct _vkh_device_t* VkhDevice; typedef struct _vkh_image_t* VkhImage; typedef struct _vkh_buffer_t* VkhBuffer; +typedef struct _vkh_presenter_t* VkhPresenter; /////////////////////////////// VkhImage vkh_image_create (VkhDevice pDev, VkFormat format, uint32_t width, uint32_t height, VkImageTiling tiling, diff --git a/vkh_buffer.c b/src/vkh_buffer.c similarity index 100% rename from vkh_buffer.c rename to src/vkh_buffer.c diff --git a/vkh_buffer.h b/src/vkh_buffer.h similarity index 95% rename from vkh_buffer.h rename to src/vkh_buffer.h index 3304744..5710bac 100644 --- a/vkh_buffer.h +++ b/src/vkh_buffer.h @@ -2,7 +2,7 @@ #define VKH_BUFFER_H #include -#include "vkhelpers.h" +#include "vkh.h" typedef struct _vkh_buffer_t { VkhDevice pDev; diff --git a/vkh_device.c b/src/vkh_device.c similarity index 100% rename from vkh_device.c rename to src/vkh_device.c diff --git a/vkh_device.h b/src/vkh_device.h similarity index 89% rename from vkh_device.h rename to src/vkh_device.h index 83ccdb1..7706b65 100644 --- a/vkh_device.h +++ b/src/vkh_device.h @@ -1,7 +1,7 @@ #ifndef VKH_DEVICE_H #define VKH_DEVICE_H -#include "vkhelpers.h" +#include "vkh.h" typedef struct _vkh_device_t{ VkDevice vkDev; diff --git a/vkh_image.c b/src/vkh_image.c similarity index 100% rename from vkh_image.c rename to src/vkh_image.c diff --git a/vkh_image.h b/src/vkh_image.h similarity index 94% rename from vkh_image.h rename to src/vkh_image.h index 6e24a9a..e272681 100644 --- a/vkh_image.h +++ b/src/vkh_image.h @@ -1,7 +1,7 @@ #ifndef VKH_IMAGE_H #define VKH_IMAGE_H -#include "vkhelpers.h" +#include "vkh.h" typedef struct _vkh_image_t { VkhDevice pDev; diff --git a/vkh_presenter.c b/src/vkh_presenter.c similarity index 100% rename from vkh_presenter.c rename to src/vkh_presenter.c diff --git a/src/vkh_presenter.h b/src/vkh_presenter.h new file mode 100644 index 0000000..d13bb22 --- /dev/null +++ b/src/vkh_presenter.h @@ -0,0 +1,39 @@ +#ifndef VKH_PRESENTER_H +#define VKH_PRESENTER_H + +#include "vkh.h" + +typedef struct ImageBuffer_t { + VkImage image; + VkImageView view; +}ImageBuffer; + +typedef struct _vkh_presenter_t { + VkQueue queue; + VkCommandPool cmdPool; + uint32_t qFam; + VkDevice dev; + + //GLFWwindow* window; + VkSurfaceKHR surface; + + VkSemaphore semaPresentEnd; + VkSemaphore semaDrawEnd; + + VkFormat format; + VkColorSpaceKHR colorSpace; + VkPresentModeKHR presentMode; + uint32_t width; + uint32_t height; + + uint32_t imgCount; + uint32_t currentScBufferIndex; + + VkRenderPass renderPass; + VkSwapchainKHR swapChain; + ImageBuffer* ScBuffers; + VkCommandBuffer* cmdBuffs; + VkFramebuffer* frameBuffs; +}vkh_presenter_t; + +#endif diff --git a/vkhelpers.c b/src/vkhelpers.c similarity index 99% rename from vkhelpers.c rename to src/vkhelpers.c index b391eee..1e1104a 100644 --- a/vkhelpers.c +++ b/src/vkhelpers.c @@ -1,5 +1,5 @@ -#include "vkhelpers.h" +#include "vkh.h" VkPhysicalDevice vkh_find_phy (VkInstance inst, VkPhysicalDeviceType phyType) { uint32_t gpu_count = 0; diff --git a/vkh.pc.in b/vkh.pc.in new file mode 100644 index 0000000..6efa801 --- /dev/null +++ b/vkh.pc.in @@ -0,0 +1,12 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=@CMAKE_INSTALL_PREFIX@ +libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@ +includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ + +Name: @PROJECT_NAME@ +Description: @PROJECT_DESCRIPTION@ +Version: @PROJECT_VERSION@ + +Requires: +Libs: -L${libdir} -lvkh +Cflags: -I${includedir} diff --git a/vkh_presenter.h b/vkh_presenter.h deleted file mode 100644 index 0a633e2..0000000 --- a/vkh_presenter.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef VKH_PRESENTER_H -#define VKH_PRESENTER_H - -#include "vkhelpers.h" - - - -#endif -- 2.47.3