Skip to content

Commit

Permalink
Merge branch 'main' into feature/resources-init
Browse files Browse the repository at this point in the history
  • Loading branch information
DynamicField authored Oct 8, 2023
2 parents 7b1b9e9 + 8cf5352 commit fc7f3f5
Show file tree
Hide file tree
Showing 177 changed files with 1,099 additions and 2,220 deletions.
240 changes: 66 additions & 174 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
cmake_minimum_required(VERSION 3.19 FATAL_ERROR)
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)

cmake_policy(SET CMP0091 NEW)
if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()
cmake_policy(SET CMP0077 NEW) # option() honors normal variables
cmake_policy(SET CMP0083 NEW) # control generation of PIE
cmake_policy(SET CMP0091 NEW) # MSVC runtime library flags
cmake_policy(SET CMP0135 NEW) # ExternalProject_Add respects timestamps

set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum macOS / OS X deployment version")
# We require windows SDK version: v10.0.22621 due to the D3D12 enum values we want only being available from this version onwards.
# The value sets the minimal version that we need to use during building
set(CMAKE_SYSTEM_VERSION 10.0.22621.0)
# Hacky hack hack for Windows
# Needs to be set before project is called. -__-
# We require windows SDK version: v10.0.22621 due to the D3D12 enum values
# we want only being available from this version onwards.
if(WIN32)
set(CMAKE_SYSTEM_VERSION 10.0.22621.0)
endif()

project(NovelRT
VERSION 1.0.0 #MVP Version
Expand All @@ -17,27 +20,35 @@ project(NovelRT
LANGUAGES C CXX
)

if(MSVC)
# CMake by default appends /W3, so we need to strip it to prevent warnings (D9025)
string(REGEX REPLACE " /W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
string(REGEX REPLACE " /W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REGEX REPLACE " /M[TD]d?" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
string(REGEX REPLACE " /M[TD]d?" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()
include(CheckPIESupported)
check_pie_supported()

if(NOT GENERATOR_IS_MULTI_CONFIG AND CMAKE_BUILD_TYPE STREQUAL "")
message(STATUS "Defaulting to Debug build as no build type was specified")
set(CMAKE_BUILD_TYPE "Debug")
endif()

if(WIN32)
# this is needed, because Windows can be weird, man.
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
#
# Set the proper backend target for NovelRT
#
set(NOVELRT_TARGET_OPTIONS "Win32" "Linux" "macOS")
set(NOVELRT_TARGET_OPTIONS "${NOVELRT_TARGET_OPTIONS}" CACHE INTERNAL "List of valid platforms for NovelRT")
if(NOT DEFINED NOVELRT_TARGET)
message(STATUS "No backend specified - setting default based on detected OS.")
if(WIN32)
set(NOVELRT_TARGET "Win32" CACHE STRING "")
elseif(APPLE)
set(NOVELRT_TARGET "macOS" CACHE STRING "")
elseif(UNIX)
set(NOVELRT_TARGET "Linux" CACHE STRING "")
else()
set(NOVELRT_TARGET "Unknown" CACHE STRING "")
endif()
endif()

# Prepend so that our FindVulkan gets picked up first
#
# Prepend so that our FindVulkan gets picked up first when needed
#
list(PREPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

#
# Defining options
#
option(NOVELRT_FETCH_DEPENDENCIES "Fetch and build NovelRT dependencies instead of providing system-based ones" ON)
option(NOVELRT_BUILD_SAMPLES "Build NovelRT samples" ON)
option(NOVELRT_BUILD_DOCUMENTATION "Build NovelRT documentation" OFF)
Expand All @@ -48,6 +59,9 @@ option(NOVELRT_INSTALL "Generate installation targets" ON)
option(NOVELRT_USE_STD_SPAN "Alias \"NovelRT::Utilities::Misc:Span\" to \"std::span\" instead of \"gsl::span\"." OFF)
option(NOVELRT_BUILD_DEPS_WITH_MAX_CPU "Use all available CPU processing power when scaffolding/building the NovelRT internal dependences" OFF)

#
# Dependency Version Constraints
#
set(NOVELRT_DOXYGEN_VERSION "1.8.17" CACHE STRING "Doxygen version")
set(NOVELRT_FLAC_VERSION "1.3.4" CACHE STRING "FLAC version")
set(NOVELRT_GLFW_VERSION "3.3.7" CACHE STRING "GLFW3 version")
Expand All @@ -62,15 +76,6 @@ set(NOVELRT_SPDLOG_VERSION "1.10.0" CACHE STRING "spdlog version")
set(NOVELRT_VORBIS_VERSION "1.3.7" CACHE STRING "Vorbis version")
set(NOVELRT_VULKAN_VERSION "1.3.231" CACHE STRING "Vulkan version")

#
# Allow for generating documentation
#
if(NOVELRT_BUILD_DOCUMENTATION)
find_package(Doxygen ${NOVELRT_DOXYGEN_VERSION}
COMPONENTS dot
)
endif()

#
# Alias "NovelRT::Utilities::Misc:Span" to "std::span" instead of "gsl::span".
# If enabled, you need to make sure you current configuration supports "std::span".
Expand All @@ -80,172 +85,67 @@ if(NOVELRT_USE_STD_SPAN)
endif()

#
# Do a Vulkan check before we bother getting other deps
# since we scaffold the others
# Setup Debug Output
#
if(APPLE)
find_package(Vulkan ${NOVELRT_VULKAN_VERSION} REQUIRED COMPONENTS MoltenVK)
else()
find_package(Vulkan ${NOVELRT_VULKAN_VERSION} REQUIRED)
if(NOVELRT_VERBOSE_BUILD)
set(CMAKE_VERBOSE_MAKEFILE TRUE)
set(VERBOSE TRUE)
message(VERBOSE "NovelRT - Target Link Libs:")
message(VERBOSE ${NOVELRT_ENGINE_LINK_LIBS})
message(VERBOSE "NovelRT - Target Compile Definitions:")
message(VERBOSE ${NOVELRT_TARGET_COMPILE_DEFS})
message(VERBOSE "NovelRT - Target Compile Options:")
message(VERBOSE ${NOVELRT_TARGET_COMPILE_OPTIONS})
endif()

#
# Handle Apple-specific requirements for CMake
#
if(APPLE)
find_library(COREFOUNDATION CoreFoundation "/")
set(CMAKE_MACOSX_RPATH 1)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "@loader_path/")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "@loader_path/" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "@loader_path/")
endif("${isSystemDir}" STREQUAL "-1")
endif()

#
# Generate and Locate NovelRT's Dependencies
# Documentation Generation target
#
include(ProcessorCount)
ProcessorCount(CORES)
if(CORES EQUAL 0)
set(CORES_AMT 1)
else()
math(EXPR CORES_AMT "${CORES} / 2")
if(CORES_AMT LESS 1)
set(CORES_AMT 1)
endif()
endif()
if(NOVELRT_FETCH_DEPENDENCIES)
if(NOT NOVELRT_DEPS_INSTALLED)
if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
set(GENERATOR_ARCH_PARAM -A ${CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE})
endif()

execute_process(
COMMAND ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_SOURCE_DIR}/internal -B ${CMAKE_CURRENT_BINARY_DIR}/depbuild -DCMAKE_BUILD_TYPE=Release -G ${CMAKE_GENERATOR} ${GENERATOR_ARCH_PARAM} -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/dist
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND_ERROR_IS_FATAL LAST
)

if(NOVELRT_BUILD_DEPS_WITH_MAX_CPU)
set(NOVELRT_DEPENDENCY_CORE_COUNT ${CORES})
else()
set(NOVELRT_DEPENDENCY_CORE_COUNT ${CORES_AMT})
endif()

execute_process(
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/depbuild --config Release -j${NOVELRT_DEPENDENCY_CORE_COUNT}
COMMAND_ERROR_IS_FATAL LAST
)
execute_process(
COMMAND ${CMAKE_COMMAND} --install ${CMAKE_CURRENT_BINARY_DIR}/depbuild --config Release
COMMAND_ERROR_IS_FATAL LAST
)

set(NOVELRT_DEPS_PATH "${CMAKE_CURRENT_BINARY_DIR}/dist" CACHE FILEPATH "Path where NovelRT's Dependencies were previously installed")
set(NOVELRT_DEPS_INSTALLED TRUE CACHE BOOL "Indicates if NovelRT's Dependencies have been installed locally via FetchContent")
if(NOVELRT_BUILD_DOCUMENTATION)
find_package(Doxygen ${NOVELRT_DOXYGEN_VERSION}
COMPONENTS dot
)
if(DOXYGEN_FOUND)
add_subdirectory(doxygen)
endif()
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_BINARY_DIR}/dist)
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_BINARY_DIR}/dist/share)
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_BINARY_DIR}/dist/lib/cmake)
endif()

# Packages w/o version specified typically break as they don't support
# versioning like the others do.
find_package(spdlog ${NOVELRT_SPDLOG_VERSION} REQUIRED)
find_package(TBB ${NOVELRT_ONETBB_VERSION} CONFIG REQUIRED)
find_package(Microsoft.GSL ${NOVELRT_GSL_VERSION} REQUIRED)
find_package(stduuid CONFIG REQUIRED)
find_package(glfw3 ${NOVELRT_GLFW_VERSION} CONFIG REQUIRED)
find_package(glm REQUIRED)
find_package(Ogg ${NOVELRT_OGG_VERSION} REQUIRED)
find_package(OpenAL CONFIG REQUIRED)
find_package(Opus REQUIRED)
find_package(Vorbis ${NOVELRT_VORBIS_VERSION} REQUIRED)
find_package(flac ${NOVELRT_FLAC_VERSION} REQUIRED)
find_package(SndFile REQUIRED)
find_package(nlohmann_json REQUIRED)



if(NOVELRT_DEPS_INSTALLED)
#CMake-standard FindZLIB breaks runtime deps for Windows
#So we just use our version that doesn't :)
find_package(ZLIB CONFIG REQUIRED)
include(${NOVELRT_DEPS_PATH}/lib/libpng/libpng16.cmake)
else()
find_package(ZLIB REQUIRED)
find_package(PNG ${NOVELRT_PNG_VERSION} REQUIRED)
endif()

#
# Generate required files for install
#
include(CMakePackageConfigHelpers)
set(NOVELRT_CONFIG_PATH lib/cmake/NovelRT)

configure_package_config_file(cmake/NovelRTConfig.cmake.in
src/NovelRTConfig.cmake
INSTALL_DESTINATION ${NOVELRT_CONFIG_PATH})

write_basic_package_version_file(src/NovelRTConfigVersion.cmake
COMPATIBILITY SameMajorVersion)

#
# Setup Debug Output
#
if(NOVELRT_VERBOSE_BUILD)
set(CMAKE_VERBOSE_MAKEFILE TRUE)
if(CMAKE_GENERATOR STREQUAL "Visual Studio 2019 16" OR CMAKE_GENERATOR STREQUAL "Visual Studio 2022 17")
string(APPEND CMAKE_CXX_FLAGS "-v:detailed")
endif()
set(VERBOSE TRUE)
find_package(Vulkan ${NOVElRT_VULKAN_VERSION} REQUIRED
OPTIONAL_COMPONENTS MoltenVK)
if(APPLE AND NOT Vulkan_MoltenVK_FOUND)
message(SEND_ERROR "Could not find MoltenVK, which is required for graphics support")
endif()


#
# Add subdirectories
#
add_subdirectory(internal/Fabulist)
add_subdirectory(thirdparty)
add_subdirectory(resources)
add_subdirectory(graphics)
add_subdirectory(audio)
add_subdirectory(src)

if(NOVELRT_BUILD_SAMPLES)
add_subdirectory(samples)
endif()

if(NOVELRT_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()

if(DOXYGEN_FOUND AND NOVELRT_BUILD_DOCUMENTATION)
add_subdirectory(doxygen)
endif()

#
# Install files other than the libraries themselves
# Targets' CMakeLists contains respective installations
#
if(NOVELRT_INSTALL)
install(
EXPORT NovelRT
FILE NovelRTTargets.cmake
EXPORT NovelRTConfig
EXPORT_LINK_INTERFACE_LIBRARIES
NAMESPACE NovelRT::
DESTINATION "${NOVELRT_CONFIG_PATH}"
)

install(
FILES "${PROJECT_BINARY_DIR}/src/NovelRTConfig.cmake"
"${PROJECT_BINARY_DIR}/src/NovelRTConfigVersion.cmake"
DESTINATION "${NOVELRT_CONFIG_PATH}")

install(
FILES "${PROJECT_SOURCE_DIR}/cmake/FindVulkan.cmake"
DESTINATION "${NOVELRT_CONFIG_PATH}"
DESTINATION lib
)

#Moved to main CMakeLists as headers should always be distributed for now
Expand Down Expand Up @@ -280,13 +180,5 @@ if(NOVELRT_INSTALL)
PATTERN "doc" EXCLUDE
PATTERN "man" EXCLUDE
)
if(WIN32)
install(
DIRECTORY ${NOVELRT_DEPS_PATH}/bin/
DESTINATION bin
PATTERN "png*.exe" EXCLUDE
PATTERN "gtest*" EXCLUDE
)
endif()
endif()
endif()
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root
// for more information.

#include <NovelRT/Audio/Audio.h>
#include <sndfile.h>
#include <NovelRT/Audio/Audio.hpp>

namespace NovelRT::Audio
{
Expand Down
58 changes: 58 additions & 0 deletions audio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
add_library(NovelRT-Audio STATIC
AudioService.cpp
)

target_sources(NovelRT-Audio
PUBLIC
FILE_SET public_headers
TYPE HEADERS
BASE_DIRS include
FILES
include/NovelRT/Audio/Audio.hpp
include/NovelRT/Audio/AudioService.hpp
)

set_target_properties(NovelRT-Audio
PROPERTIES
EXPORT_NAME Audio
POSITION_INDEPENDENT_CODE ON
)

target_compile_features(NovelRT-Audio
PUBLIC
cxx_std_17
)

target_compile_options(NovelRT-Audio
PRIVATE
$<$<CXX_COMPILER_ID:GNU>:-Wall>
$<$<CXX_COMPILER_ID:GNU>:-Wabi>
$<$<CXX_COMPILER_ID:GNU>:-Werror>
$<$<CXX_COMPILER_ID:GNU>:-Wextra>
$<$<CXX_COMPILER_ID:GNU>:-Wpedantic>
$<$<CXX_COMPILER_ID:GNU>:-pedantic-errors>

$<$<CXX_COMPILER_ID:Clang>:-Wall>
$<$<CXX_COMPILER_ID:Clang>:-Werror>
$<$<CXX_COMPILER_ID:Clang>:-Wextra>
$<$<CXX_COMPILER_ID:Clang>:-Wpedantic>
$<$<CXX_COMPILER_ID:Clang>:-pedantic-errors>

$<$<CXX_COMPILER_ID:MSVC>:/W4>
$<$<CXX_COMPILER_ID:MSVC>:/WX>
$<$<CXX_COMPILER_ID:MSVC>:/permissive->
)

target_include_directories(NovelRT-Audio PRIVATE "$<TARGET_PROPERTY:Engine,INCLUDE_DIRECTORIES>")
target_link_libraries(NovelRT-Audio
PUBLIC
spdlog
OpenAL
)

install(
TARGETS NovelRT-Audio
EXPORT NovelRTConfig
LIBRARY DESTINATION lib
FILE_SET public_headers DESTINATION include
)
Loading

0 comments on commit fc7f3f5

Please sign in to comment.