Added functionality to detect debug and release mode in code.
This commit is contained in:
parent
08338d50a8
commit
c07eae32c3
4 changed files with 44 additions and 7 deletions
|
|
@ -1,14 +1,19 @@
|
||||||
cmake_minimum_required(VERSION 3.16)
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
|
||||||
|
# set toolchain file
|
||||||
|
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/toolchain.cmake"
|
||||||
|
CACHE PATH "Path to the desired toolchain file.")
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
set(CMAKE_CXX_CLANG_TIDY)
|
||||||
|
|
||||||
project(yave
|
project(yave
|
||||||
VERSION 0
|
VERSION 0
|
||||||
DESCRIPTION "Yet Another Vulkan Engine"
|
DESCRIPTION "Yet Another Vulkan Engine"
|
||||||
HOMEPAGE_URL "https://git.warwicknew.xyz/yave/"
|
HOMEPAGE_URL "https://git.warwicknew.xyz/yave/"
|
||||||
LANGUAGES C CXX)
|
LANGUAGES C CXX)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
||||||
set(CMAKE_CXX_CLANG_TIDY)
|
|
||||||
|
|
||||||
file(GLOB_RECURSE SOURCE_FILES
|
file(GLOB_RECURSE SOURCE_FILES
|
||||||
${CMAKE_SOURCE_DIR}/src/*.c
|
${CMAKE_SOURCE_DIR}/src/*.c
|
||||||
${CMAKE_SOURCE_DIR}/src/*.cpp)
|
${CMAKE_SOURCE_DIR}/src/*.cpp)
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ YaveVulkanInstance::YaveVulkanInstance() { createInstance(); }
|
||||||
YaveVulkanInstance::~YaveVulkanInstance() { destroyInstance(); }
|
YaveVulkanInstance::~YaveVulkanInstance() { destroyInstance(); }
|
||||||
|
|
||||||
void YaveVulkanInstance::createInstance() {
|
void YaveVulkanInstance::createInstance() {
|
||||||
|
checkLayersValidSuppport();
|
||||||
VkApplicationInfo appInfo{};
|
VkApplicationInfo appInfo{};
|
||||||
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
||||||
appInfo.pApplicationName = "Hello Triangle";
|
appInfo.pApplicationName = "Hello Triangle";
|
||||||
|
|
@ -38,4 +39,13 @@ void YaveVulkanInstance::destroyInstance() {
|
||||||
vkDestroyInstance(this->instance, nullptr);
|
vkDestroyInstance(this->instance, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool YaveVulkanInstance::checkLayersValidSuppport() {
|
||||||
|
// Continue if validation is disabled
|
||||||
|
if (this->enableValidationLayers) {
|
||||||
|
throw std::runtime_error("validation layers requested, but not available!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace yave
|
} // namespace yave
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <vector>
|
||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
|
|
||||||
#define GLFW_INCLUDE_VULKAN
|
#define GLFW_INCLUDE_VULKAN
|
||||||
|
|
@ -11,11 +12,19 @@ class YaveVulkanInstance {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VkInstance instance;
|
VkInstance instance;
|
||||||
|
|
||||||
void createInstance();
|
void createInstance();
|
||||||
|
|
||||||
void destroyInstance();
|
void destroyInstance();
|
||||||
|
|
||||||
|
// Validation support
|
||||||
|
bool checkLayersValidSuppport();
|
||||||
|
const std::vector<const char *> validationLayers = {
|
||||||
|
"VK_LAYER_KHRONOS_validation"};
|
||||||
|
#ifdef NDEBUG // Enable Validation in debug mode
|
||||||
|
const bool enableValidationLayers = false;
|
||||||
|
#else
|
||||||
|
const bool enableValidationLayers = true;
|
||||||
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Delete Copy constructors
|
// Delete Copy constructors
|
||||||
// This class should match one to one with vulkan instances
|
// This class should match one to one with vulkan instances
|
||||||
|
|
|
||||||
13
toolchain.cmake
Normal file
13
toolchain.cmake
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
# CMake toolchain file
|
||||||
|
|
||||||
|
# linker flags
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,--strip-debug")
|
||||||
|
|
||||||
|
# cflags
|
||||||
|
set(CMAKE_CXX_FLAGS_INIT "-ansi -Wall")
|
||||||
|
|
||||||
|
# cflags for debug build
|
||||||
|
set(CMAKE_CXX_FLAGS_DEBUG_INIT "-g3 -ggdb3")
|
||||||
|
|
||||||
|
# cflags for release build
|
||||||
|
set(CMAKE_CXX_FLAGS_RELEASE_INIT "-O3 -DNDEBUG -s")
|
||||||
Loading…
Reference in a new issue