2025-01-24 09:53:06 +01:00
|
|
|
# Copyright (C) 2016-2025 by Sascha Willems - www.saschawillems.de
|
2023-11-28 19:33:14 +01:00
|
|
|
# This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
|
|
|
|
|
|
2025-04-11 19:52:01 +02:00
|
|
|
cmake_minimum_required(VERSION 3.10.0 FATAL_ERROR)
|
2016-02-16 19:33:57 +02:00
|
|
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
|
2016-02-16 15:07:25 +01:00
|
|
|
|
2025-08-17 18:56:17 +02:00
|
|
|
set(NAME inihb)
|
2016-02-16 15:07:25 +01:00
|
|
|
|
|
|
|
|
project(${NAME})
|
|
|
|
|
|
|
|
|
|
include_directories(external)
|
|
|
|
|
include_directories(external/glm)
|
2017-04-22 11:50:13 +02:00
|
|
|
include_directories(external/imgui)
|
2018-09-03 20:27:15 +02:00
|
|
|
include_directories(external/tinygltf)
|
2020-07-28 20:20:38 +02:00
|
|
|
include_directories(external/ktx/include)
|
|
|
|
|
include_directories(external/ktx/other_include)
|
2016-02-16 15:07:25 +01:00
|
|
|
include_directories(base)
|
|
|
|
|
|
2016-11-04 15:40:22 -07:00
|
|
|
OPTION(USE_D2D_WSI "Build the project using Direct to Display swapchain" OFF)
|
2020-09-13 10:12:33 +02:00
|
|
|
OPTION(USE_DIRECTFB_WSI "Build the project using DirectFB swapchain" OFF)
|
2017-02-02 08:54:56 +00:00
|
|
|
OPTION(USE_WAYLAND_WSI "Build the project using Wayland swapchain" OFF)
|
2021-04-27 13:52:27 +02:00
|
|
|
OPTION(USE_HEADLESS "Build the project using headless extension swapchain" OFF)
|
2023-11-28 19:33:14 +01:00
|
|
|
OPTION(USE_RELATIVE_ASSET_PATH "Load assets (shaders, models, textures) from a fixed path relative to the binar" OFF)
|
2023-12-30 13:15:37 +01:00
|
|
|
OPTION(FORCE_VALIDATION "Forces validation on for all samples at compile time (prefer using the -v / --validation command line arguments)" OFF)
|
2016-11-04 13:32:58 -07:00
|
|
|
|
2017-07-03 14:49:18 +03:00
|
|
|
set(RESOURCE_INSTALL_DIR "" CACHE PATH "Path to install resources to (leave empty for running uninstalled)")
|
|
|
|
|
|
2025-04-11 19:52:01 +02:00
|
|
|
message(STATUS "Using module to find Vulkan")
|
|
|
|
|
find_package(Vulkan)
|
2016-11-12 13:33:21 +01:00
|
|
|
|
2020-09-12 03:19:28 +09:00
|
|
|
IF(UNIX AND NOT APPLE)
|
|
|
|
|
set(LINUX TRUE)
|
|
|
|
|
ENDIF()
|
|
|
|
|
|
2016-02-16 15:07:25 +01:00
|
|
|
IF(WIN32)
|
2016-11-12 13:33:21 +01:00
|
|
|
IF (NOT Vulkan_FOUND)
|
|
|
|
|
find_library(Vulkan_LIBRARY NAMES vulkan-1 vulkan PATHS ${CMAKE_SOURCE_DIR}/libs/vulkan)
|
|
|
|
|
IF (Vulkan_LIBRARY)
|
|
|
|
|
set(Vulkan_FOUND ON)
|
2017-01-08 01:44:31 -08:00
|
|
|
MESSAGE("Using bundled Vulkan library version")
|
2016-11-12 13:33:21 +01:00
|
|
|
ENDIF()
|
|
|
|
|
ENDIF()
|
2016-02-16 15:07:25 +01:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_WIN32_KHR")
|
2020-09-12 03:19:28 +09:00
|
|
|
ELSEIF(LINUX)
|
2016-11-12 13:33:21 +01:00
|
|
|
IF (NOT Vulkan_FOUND)
|
|
|
|
|
find_library(Vulkan_LIBRARY NAMES vulkan HINTS "$ENV{VULKAN_SDK}/lib" "${CMAKE_SOURCE_DIR}/libs/vulkan" REQUIRED)
|
|
|
|
|
IF (Vulkan_LIBRARY)
|
|
|
|
|
set(Vulkan_FOUND ON)
|
2017-01-08 01:44:31 -08:00
|
|
|
MESSAGE("Using bundled Vulkan library version")
|
2016-11-12 13:33:21 +01:00
|
|
|
ENDIF()
|
|
|
|
|
ENDIF()
|
2016-04-03 11:05:12 +02:00
|
|
|
find_package(Threads REQUIRED)
|
2020-09-12 03:19:28 +09:00
|
|
|
IF(USE_D2D_WSI)
|
|
|
|
|
MESSAGE("Using direct to display extension...")
|
|
|
|
|
add_definitions(-D_DIRECT2DISPLAY)
|
2020-09-13 10:12:33 +02:00
|
|
|
ELSEIF(USE_DIRECTFB_WSI)
|
|
|
|
|
find_package(DirectFB REQUIRED)
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_DIRECTFB_EXT")
|
|
|
|
|
include_directories(${DIRECTFB_INCLUDE_DIR})
|
2020-09-12 03:19:28 +09:00
|
|
|
ELSEIF(USE_WAYLAND_WSI)
|
|
|
|
|
find_program(PKG_CONFIG pkg-config)
|
|
|
|
|
if (NOT PKG_CONFIG)
|
|
|
|
|
message(FATAL_ERROR "pkg-config binary not found")
|
|
|
|
|
endif ()
|
|
|
|
|
find_package(Wayland REQUIRED)
|
|
|
|
|
if (NOT WAYLAND_FOUND)
|
|
|
|
|
message(FATAL_ERROR "Wayland development package not found")
|
|
|
|
|
endif ()
|
|
|
|
|
pkg_check_modules(WAYLAND_PROTOCOLS REQUIRED wayland-protocols)
|
|
|
|
|
if (NOT WAYLAND_PROTOCOLS_FOUND)
|
|
|
|
|
message(FATAL_ERROR "Wayland protocols package not found")
|
|
|
|
|
endif ()
|
|
|
|
|
find_program(WAYLAND_SCANNER wayland-scanner)
|
|
|
|
|
if (NOT WAYLAND_SCANNER)
|
|
|
|
|
message(FATAL_ERROR "wayland-scanner binary not found")
|
|
|
|
|
endif ()
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_WAYLAND_KHR")
|
|
|
|
|
include_directories(${WAYLAND_INCLUDE_DIR})
|
2021-05-04 17:25:03 +01:00
|
|
|
pkg_get_variable(protocol_dir wayland-protocols pkgdatadir)
|
2020-09-12 03:19:28 +09:00
|
|
|
execute_process(COMMAND ${WAYLAND_SCANNER} client-header ${protocol_dir}/stable/xdg-shell/xdg-shell.xml ${CMAKE_BINARY_DIR}/xdg-shell-client-protocol.h
|
|
|
|
|
COMMAND ${WAYLAND_SCANNER} private-code ${protocol_dir}/stable/xdg-shell/xdg-shell.xml ${CMAKE_BINARY_DIR}/xdg-shell-protocol.c)
|
|
|
|
|
include_directories(${CMAKE_BINARY_DIR})
|
2021-04-27 13:52:27 +02:00
|
|
|
ELSEIF(USE_HEADLESS)
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_HEADLESS_EXT")
|
2020-09-12 03:19:28 +09:00
|
|
|
ELSE(USE_D2D_WSI)
|
|
|
|
|
find_package(XCB REQUIRED)
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_XCB_KHR")
|
|
|
|
|
ENDIF(USE_D2D_WSI)
|
|
|
|
|
ELSEIF(APPLE)
|
2024-05-04 07:53:08 -04:00
|
|
|
IF (CMAKE_GENERATOR MATCHES "Xcode")
|
|
|
|
|
# Suppress regeneration for Xcode since environment variables will be lost if not set in Xcode locations/custom paths
|
|
|
|
|
set(CMAKE_SUPPRESS_REGENERATION ON)
|
|
|
|
|
set(CMAKE_XCODE_GENERATE_SCHEME ON)
|
|
|
|
|
IF (Vulkan_FOUND)
|
|
|
|
|
# If the Vulkan loader was found and its environment variables are defined, make them available within Xcode schemes
|
|
|
|
|
IF (DEFINED ENV{VK_ADD_LAYER_PATH})
|
|
|
|
|
set(CMAKE_XCODE_SCHEME_ENVIRONMENT "${CMAKE_XCODE_SCHEME_ENVIRONMENT};VK_ADD_LAYER_PATH=$ENV{VK_ADD_LAYER_PATH}")
|
|
|
|
|
ENDIF()
|
|
|
|
|
IF (DEFINED ENV{VK_ICD_FILENAMES})
|
|
|
|
|
set(CMAKE_XCODE_SCHEME_ENVIRONMENT "${CMAKE_XCODE_SCHEME_ENVIRONMENT};VK_ICD_FILENAMES=$ENV{VK_ICD_FILENAMES}")
|
|
|
|
|
ENDIF()
|
|
|
|
|
IF (DEFINED ENV{VK_DRIVER_FILES})
|
|
|
|
|
set(CMAKE_XCODE_SCHEME_ENVIRONMENT "${CMAKE_XCODE_SCHEME_ENVIRONMENT};VK_DRIVER_FILES=$ENV{VK_DRIVER_FILES}")
|
|
|
|
|
ENDIF()
|
|
|
|
|
ENDIF()
|
|
|
|
|
ENDIF()
|
|
|
|
|
IF (NOT Vulkan_FOUND)
|
|
|
|
|
# If the Vulkan loader was not found, then look for libMoltenVK.dylib in the Vulkan SDK and legacy MoltenVK locations
|
|
|
|
|
set(CMAKE_FIND_FRAMEWORK NEVER)
|
|
|
|
|
find_library(Vulkan_LIBRARY NAMES MoltenVK HINTS "$ENV{VULKAN_SDK}/lib" "$ENV{VULKAN_SDK}/dylib/macOS" REQUIRED)
|
|
|
|
|
IF (Vulkan_LIBRARY)
|
|
|
|
|
set(Vulkan_FOUND ON)
|
|
|
|
|
MESSAGE(STATUS "Using MoltenVK Vulkan Portability library")
|
|
|
|
|
ENDIF()
|
|
|
|
|
ENDIF()
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_METAL_EXT -DVK_EXAMPLE_XCODE_GENERATED")
|
2016-02-16 15:07:25 +01:00
|
|
|
# Todo : android?
|
|
|
|
|
ENDIF(WIN32)
|
|
|
|
|
|
2016-11-12 13:33:21 +01:00
|
|
|
IF (NOT Vulkan_FOUND)
|
|
|
|
|
message(FATAL_ERROR "Could not find Vulkan library!")
|
|
|
|
|
ELSE()
|
|
|
|
|
message(STATUS ${Vulkan_LIBRARY})
|
|
|
|
|
ENDIF()
|
2016-02-16 15:07:25 +01:00
|
|
|
|
|
|
|
|
# Set preprocessor defines
|
2016-03-21 23:59:42 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOMINMAX -D_USE_MATH_DEFINES")
|
2016-02-16 15:07:25 +01:00
|
|
|
|
2017-01-09 20:23:30 +01:00
|
|
|
# Clang specific stuff
|
|
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-switch-enum")
|
|
|
|
|
endif()
|
|
|
|
|
|
2016-03-22 00:06:50 +00:00
|
|
|
|
2016-02-16 15:07:25 +01:00
|
|
|
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
2025-01-24 09:53:06 +01:00
|
|
|
set(CMAKE_CXX_STANDARD 20)
|
2020-04-19 18:26:24 +02:00
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
2016-02-16 15:07:25 +01:00
|
|
|
|
2017-08-17 20:40:52 +02:00
|
|
|
file(GLOB SOURCE *.cpp )
|
2016-02-16 15:07:25 +01:00
|
|
|
|
2023-11-28 19:33:14 +01:00
|
|
|
# Asset and shader path selection
|
2017-07-03 14:49:18 +03:00
|
|
|
if(RESOURCE_INSTALL_DIR)
|
2023-05-09 21:05:01 +02:00
|
|
|
add_definitions(-DVK_EXAMPLE_ASSETS_DIR=\"${RESOURCE_INSTALL_DIR}/\")
|
2023-07-12 10:00:25 -05:00
|
|
|
add_definitions(-DVK_EXAMPLE_SHADERS_DIR=\"${RESOURCE_INSTALL_DIR}/shaders/\")
|
2023-07-12 10:00:38 -05:00
|
|
|
install(DIRECTORY assets/ DESTINATION ${RESOURCE_INSTALL_DIR}/)
|
2023-07-10 08:47:08 -05:00
|
|
|
install(DIRECTORY shaders/ DESTINATION ${RESOURCE_INSTALL_DIR}/shaders/)
|
2017-07-03 14:49:18 +03:00
|
|
|
else()
|
2023-11-28 19:33:14 +01:00
|
|
|
if(NOT USE_RELATIVE_ASSET_PATH)
|
|
|
|
|
add_definitions(-DVK_EXAMPLE_ASSETS_DIR=\"${CMAKE_SOURCE_DIR}/assets/\")
|
|
|
|
|
add_definitions(-DVK_EXAMPLE_SHADERS_DIR=\"${CMAKE_SOURCE_DIR}/shaders/\")
|
|
|
|
|
endif()
|
2017-07-03 14:49:18 +03:00
|
|
|
endif()
|
|
|
|
|
|
2023-12-30 13:15:37 +01:00
|
|
|
# Force validation at compile time
|
|
|
|
|
if (FORCE_VALIDATION)
|
|
|
|
|
add_definitions(-DFORCE_VALIDATION)
|
|
|
|
|
endif()
|
|
|
|
|
|
2016-02-16 15:07:25 +01:00
|
|
|
# Compiler specific stuff
|
|
|
|
|
IF(MSVC)
|
2016-07-19 20:41:29 +02:00
|
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
|
2020-09-12 03:19:28 +09:00
|
|
|
ELSEIF(APPLE)
|
2024-05-04 07:53:08 -04:00
|
|
|
IF(CMAKE_GENERATOR MATCHES "Makefiles" OR CMAKE_GENERATOR MATCHES "Ninja")
|
|
|
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fobjc-arc -ObjC++")
|
|
|
|
|
ELSE() # SRS - use objective-c++ language flag vs. ObjC++ for Xcode builds
|
2020-11-18 00:17:20 -08:00
|
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fobjc-arc -xobjective-c++")
|
2024-05-04 07:53:08 -04:00
|
|
|
ENDIF()
|
2016-02-16 15:07:25 +01:00
|
|
|
ENDIF(MSVC)
|
|
|
|
|
|
|
|
|
|
IF(WIN32)
|
|
|
|
|
# Nothing here (yet)
|
2020-09-12 03:19:28 +09:00
|
|
|
ELSEIF(APPLE)
|
|
|
|
|
link_libraries(${Vulkan_LIBRARY} "-framework AppKit" "-framework QuartzCore")
|
2016-02-16 15:07:25 +01:00
|
|
|
ELSE(WIN32)
|
2020-09-13 10:12:33 +02:00
|
|
|
link_libraries(${XCB_LIBRARIES} ${Vulkan_LIBRARY} ${Vulkan_LIBRARY} ${DIRECTFB_LIBRARIES} ${WAYLAND_CLIENT_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
|
2016-02-16 15:07:25 +01:00
|
|
|
ENDIF(WIN32)
|
|
|
|
|
|
2017-07-03 14:49:18 +03:00
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/")
|
2016-02-16 15:07:25 +01:00
|
|
|
|
2017-08-17 20:40:52 +02:00
|
|
|
add_subdirectory(base)
|
2025-08-17 18:56:17 +02:00
|
|
|
add_subdirectory(src)
|