Compare commits
4 Commits
d3c6337068
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 072167ccf4 | |||
| 96b6c7e764 | |||
| e562fb2037 | |||
| bf63dfb11e |
15
CMakeLists.txt
Normal file
15
CMakeLists.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||
|
||||
project(ecs)
|
||||
|
||||
if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
|
||||
message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.")
|
||||
endif()
|
||||
|
||||
include(cmake/tools.cmake)
|
||||
|
||||
add_subdirectory(io)
|
||||
add_subdirectory(test)
|
||||
|
||||
set_target_properties(io_test PROPERTIES EXCLUDE_FROM_ALL YES)
|
||||
set_target_properties(test_framework PROPERTIES EXCLUDE_FROM_ALL YES)
|
||||
475
cmake/CPM.cmake
Normal file
475
cmake/CPM.cmake
Normal file
@@ -0,0 +1,475 @@
|
||||
# CPM.cmake - CMake's missing package manager
|
||||
# ===========================================
|
||||
# See https://github.com/TheLartians/CPM.cmake for usage and update instructions.
|
||||
#
|
||||
# MIT License
|
||||
# -----------
|
||||
#[[
|
||||
Copyright (c) 2019 Lars Melchior
|
||||
|
||||
Permisson is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
]]
|
||||
|
||||
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||
|
||||
set(CURRENT_CPM_VERSION 0.26.2)
|
||||
|
||||
if(CPM_DIRECTORY)
|
||||
if(NOT CPM_DIRECTORY STREQUAL CMAKE_CURRENT_LIST_DIR)
|
||||
if (CPM_VERSION VERSION_LESS CURRENT_CPM_VERSION)
|
||||
message(AUTHOR_WARNING "${CPM_INDENT} \
|
||||
A dependency is using a more recent CPM version (${CURRENT_CPM_VERSION}) than the current project (${CPM_VERSION}). \
|
||||
It is recommended to upgrade CPM to the most recent version. \
|
||||
See https://github.com/TheLartians/CPM.cmake for more information."
|
||||
)
|
||||
endif()
|
||||
return()
|
||||
endif()
|
||||
|
||||
get_property(CPM_INITIALIZED GLOBAL "" PROPERTY CPM_INITIALIZED SET)
|
||||
if (CPM_INITIALIZED)
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set_property(GLOBAL PROPERTY CPM_INITIALIZED true)
|
||||
|
||||
option(CPM_USE_LOCAL_PACKAGES "Always try to use `find_package` to get dependencies" $ENV{CPM_USE_LOCAL_PACKAGES})
|
||||
option(CPM_LOCAL_PACKAGES_ONLY "Only use `find_package` to get dependencies" $ENV{CPM_LOCAL_PACKAGES_ONLY})
|
||||
option(CPM_DOWNLOAD_ALL "Always download dependencies from source" $ENV{CPM_DOWNLOAD_ALL})
|
||||
option(CPM_DONT_UPDATE_MODULE_PATH "Don't update the module path to allow using find_package" $ENV{CPM_DONT_UPDATE_MODULE_PATH})
|
||||
option(CPM_DONT_CREATE_PACKAGE_LOCK "Don't create a package lock file in the binary path" $ENV{CPM_DONT_CREATE_PACKAGE_LOCK})
|
||||
option(CPM_INCLUDE_ALL_IN_PACKAGE_LOCK "Add all packages added through CPM.cmake to the package lock" $ENV{CPM_INCLUDE_ALL_IN_PACKAGE_LOCK})
|
||||
|
||||
set(CPM_VERSION ${CURRENT_CPM_VERSION} CACHE INTERNAL "")
|
||||
set(CPM_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} CACHE INTERNAL "")
|
||||
set(CPM_FILE ${CMAKE_CURRENT_LIST_FILE} CACHE INTERNAL "")
|
||||
set(CPM_PACKAGES "" CACHE INTERNAL "")
|
||||
set(CPM_DRY_RUN OFF CACHE INTERNAL "Don't download or configure dependencies (for testing)")
|
||||
|
||||
if(DEFINED ENV{CPM_SOURCE_CACHE})
|
||||
set(CPM_SOURCE_CACHE_DEFAULT $ENV{CPM_SOURCE_CACHE})
|
||||
else()
|
||||
set(CPM_SOURCE_CACHE_DEFAULT OFF)
|
||||
endif()
|
||||
|
||||
set(CPM_SOURCE_CACHE ${CPM_SOURCE_CACHE_DEFAULT} CACHE PATH "Directory to downlaod CPM dependencies")
|
||||
|
||||
if (NOT CPM_DONT_UPDATE_MODULE_PATH)
|
||||
set(CPM_MODULE_PATH "${CMAKE_BINARY_DIR}/CPM_modules" CACHE INTERNAL "")
|
||||
# remove old modules
|
||||
FILE(REMOVE_RECURSE ${CPM_MODULE_PATH})
|
||||
file(MAKE_DIRECTORY ${CPM_MODULE_PATH})
|
||||
# locally added CPM modules should override global packages
|
||||
set(CMAKE_MODULE_PATH "${CPM_MODULE_PATH};${CMAKE_MODULE_PATH}")
|
||||
endif()
|
||||
|
||||
if (NOT CPM_DONT_CREATE_PACKAGE_LOCK)
|
||||
set(CPM_PACKAGE_LOCK_FILE "${CMAKE_BINARY_DIR}/cpm-package-lock.cmake" CACHE INTERNAL "")
|
||||
file(WRITE ${CPM_PACKAGE_LOCK_FILE} "# CPM Package Lock\n# This file should be committed to version control\n\n")
|
||||
endif()
|
||||
|
||||
include(FetchContent)
|
||||
include(CMakeParseArguments)
|
||||
|
||||
# Initialize logging prefix
|
||||
if(NOT CPM_INDENT)
|
||||
set(CPM_INDENT "CPM:")
|
||||
endif()
|
||||
|
||||
function(cpm_find_package NAME VERSION)
|
||||
string(REPLACE " " ";" EXTRA_ARGS "${ARGN}")
|
||||
find_package(${NAME} ${VERSION} ${EXTRA_ARGS} QUIET)
|
||||
if(${CPM_ARGS_NAME}_FOUND)
|
||||
message(STATUS "${CPM_INDENT} using local package ${CPM_ARGS_NAME}@${VERSION}")
|
||||
CPMRegisterPackage(${CPM_ARGS_NAME} "${VERSION}")
|
||||
set(CPM_PACKAGE_FOUND YES PARENT_SCOPE)
|
||||
else()
|
||||
set(CPM_PACKAGE_FOUND NO PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Create a custom FindXXX.cmake module for a CPM package
|
||||
# This prevents `find_package(NAME)` from finding the system library
|
||||
function(CPMCreateModuleFile Name)
|
||||
if (NOT CPM_DONT_UPDATE_MODULE_PATH)
|
||||
# erase any previous modules
|
||||
FILE(WRITE ${CPM_MODULE_PATH}/Find${Name}.cmake "include(${CPM_FILE})\n${ARGN}\nset(${Name}_FOUND TRUE)")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Find a package locally or fallback to CPMAddPackage
|
||||
function(CPMFindPackage)
|
||||
set(oneValueArgs
|
||||
NAME
|
||||
VERSION
|
||||
FIND_PACKAGE_ARGUMENTS
|
||||
)
|
||||
|
||||
cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "" ${ARGN})
|
||||
|
||||
if (NOT DEFINED CPM_ARGS_VERSION)
|
||||
if (DEFINED CPM_ARGS_GIT_TAG)
|
||||
cpm_get_version_from_git_tag("${CPM_ARGS_GIT_TAG}" CPM_ARGS_VERSION)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (CPM_DOWNLOAD_ALL)
|
||||
CPMAddPackage(${ARGN})
|
||||
cpm_export_variables(${CPM_ARGS_NAME})
|
||||
return()
|
||||
endif()
|
||||
|
||||
CPMCheckIfPackageAlreadyAdded(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" "${CPM_ARGS_OPTIONS}")
|
||||
if (CPM_PACKAGE_ALREADY_ADDED)
|
||||
cpm_export_variables(${CPM_ARGS_NAME})
|
||||
return()
|
||||
endif()
|
||||
|
||||
cpm_find_package(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" ${CPM_ARGS_FIND_PACKAGE_ARGUMENTS})
|
||||
|
||||
if(NOT CPM_PACKAGE_FOUND)
|
||||
CPMAddPackage(${ARGN})
|
||||
cpm_export_variables(${CPM_ARGS_NAME})
|
||||
endif()
|
||||
|
||||
endfunction()
|
||||
|
||||
# checks if a package has been added before
|
||||
function(CPMCheckIfPackageAlreadyAdded CPM_ARGS_NAME CPM_ARGS_VERSION CPM_ARGS_OPTIONS)
|
||||
if ("${CPM_ARGS_NAME}" IN_LIST CPM_PACKAGES)
|
||||
CPMGetPackageVersion(${CPM_ARGS_NAME} CPM_PACKAGE_VERSION)
|
||||
if("${CPM_PACKAGE_VERSION}" VERSION_LESS "${CPM_ARGS_VERSION}")
|
||||
message(WARNING "${CPM_INDENT} requires a newer version of ${CPM_ARGS_NAME} (${CPM_ARGS_VERSION}) than currently included (${CPM_PACKAGE_VERSION}).")
|
||||
endif()
|
||||
if (CPM_ARGS_OPTIONS)
|
||||
foreach(OPTION ${CPM_ARGS_OPTIONS})
|
||||
cpm_parse_option(${OPTION})
|
||||
if(NOT "${${OPTION_KEY}}" STREQUAL "${OPTION_VALUE}")
|
||||
message(WARNING "${CPM_INDENT} ignoring package option for ${CPM_ARGS_NAME}: ${OPTION_KEY} = ${OPTION_VALUE} (${${OPTION_KEY}})")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
cpm_get_fetch_properties(${CPM_ARGS_NAME})
|
||||
SET(${CPM_ARGS_NAME}_ADDED NO)
|
||||
SET(CPM_PACKAGE_ALREADY_ADDED YES PARENT_SCOPE)
|
||||
cpm_export_variables(${CPM_ARGS_NAME})
|
||||
else()
|
||||
SET(CPM_PACKAGE_ALREADY_ADDED NO PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Download and add a package from source
|
||||
function(CPMAddPackage)
|
||||
|
||||
set(oneValueArgs
|
||||
NAME
|
||||
FORCE
|
||||
VERSION
|
||||
GIT_TAG
|
||||
DOWNLOAD_ONLY
|
||||
GITHUB_REPOSITORY
|
||||
GITLAB_REPOSITORY
|
||||
GIT_REPOSITORY
|
||||
SOURCE_DIR
|
||||
DOWNLOAD_COMMAND
|
||||
FIND_PACKAGE_ARGUMENTS
|
||||
)
|
||||
|
||||
set(multiValueArgs
|
||||
OPTIONS
|
||||
)
|
||||
|
||||
cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}")
|
||||
|
||||
# Set default values for arguments
|
||||
|
||||
if (NOT DEFINED CPM_ARGS_VERSION)
|
||||
if (DEFINED CPM_ARGS_GIT_TAG)
|
||||
cpm_get_version_from_git_tag("${CPM_ARGS_GIT_TAG}" CPM_ARGS_VERSION)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CPM_ARGS_DOWNLOAD_ONLY)
|
||||
set(DOWNLOAD_ONLY ${CPM_ARGS_DOWNLOAD_ONLY})
|
||||
else()
|
||||
set(DOWNLOAD_ONLY NO)
|
||||
endif()
|
||||
|
||||
if (DEFINED CPM_ARGS_GITHUB_REPOSITORY)
|
||||
set(CPM_ARGS_GIT_REPOSITORY "https://github.com/${CPM_ARGS_GITHUB_REPOSITORY}.git")
|
||||
endif()
|
||||
|
||||
if (DEFINED CPM_ARGS_GITLAB_REPOSITORY)
|
||||
list(CPM_ARGS_GIT_REPOSITORY "https://gitlab.com/${CPM_ARGS_GITLAB_REPOSITORY}.git")
|
||||
endif()
|
||||
|
||||
if (DEFINED CPM_ARGS_GIT_REPOSITORY)
|
||||
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_REPOSITORY ${CPM_ARGS_GIT_REPOSITORY})
|
||||
if (NOT DEFINED CPM_ARGS_GIT_TAG)
|
||||
set(CPM_ARGS_GIT_TAG v${CPM_ARGS_VERSION})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (DEFINED CPM_ARGS_GIT_TAG)
|
||||
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS GIT_TAG ${CPM_ARGS_GIT_TAG})
|
||||
endif()
|
||||
|
||||
# Check if package has been added before
|
||||
CPMCheckIfPackageAlreadyAdded(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" "${CPM_ARGS_OPTIONS}")
|
||||
if (CPM_PACKAGE_ALREADY_ADDED)
|
||||
cpm_export_variables(${CPM_ARGS_NAME})
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Check for manual overrides
|
||||
if (NOT CPM_ARGS_FORCE AND NOT "${CPM_${CPM_ARGS_NAME}_SOURCE}" STREQUAL "")
|
||||
set(PACKAGE_SOURCE ${CPM_${CPM_ARGS_NAME}_SOURCE})
|
||||
set(CPM_${CPM_ARGS_NAME}_SOURCE "")
|
||||
CPMAddPackage(
|
||||
NAME ${CPM_ARGS_NAME}
|
||||
SOURCE_DIR ${PACKAGE_SOURCE}
|
||||
FORCE True
|
||||
)
|
||||
cpm_export_variables(${CPM_ARGS_NAME})
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Check for available declaration
|
||||
if (NOT CPM_ARGS_FORCE AND NOT "${CPM_DECLARATION_${CPM_ARGS_NAME}}" STREQUAL "")
|
||||
set(declaration ${CPM_DECLARATION_${CPM_ARGS_NAME}})
|
||||
set(CPM_DECLARATION_${CPM_ARGS_NAME} "")
|
||||
CPMAddPackage(${declaration})
|
||||
cpm_export_variables(${CPM_ARGS_NAME})
|
||||
# checking again to ensure version and option compatibility
|
||||
CPMCheckIfPackageAlreadyAdded(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" "${CPM_ARGS_OPTIONS}")
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(CPM_USE_LOCAL_PACKAGES OR CPM_LOCAL_PACKAGES_ONLY)
|
||||
cpm_find_package(${CPM_ARGS_NAME} "${CPM_ARGS_VERSION}" ${CPM_ARGS_FIND_PACKAGE_ARGUMENTS})
|
||||
|
||||
if(CPM_PACKAGE_FOUND)
|
||||
cpm_export_variables(${CPM_ARGS_NAME})
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(CPM_LOCAL_PACKAGES_ONLY)
|
||||
message(SEND_ERROR "CPM: ${CPM_ARGS_NAME} not found via find_package(${CPM_ARGS_NAME} ${CPM_ARGS_VERSION})")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
CPMRegisterPackage("${CPM_ARGS_NAME}" "${CPM_ARGS_VERSION}")
|
||||
|
||||
if (CPM_ARGS_OPTIONS)
|
||||
foreach(OPTION ${CPM_ARGS_OPTIONS})
|
||||
cpm_parse_option(${OPTION})
|
||||
set(${OPTION_KEY} ${OPTION_VALUE} CACHE INTERNAL "")
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
if (DEFINED CPM_ARGS_GIT_TAG)
|
||||
set(PACKAGE_INFO "${CPM_ARGS_GIT_TAG}")
|
||||
elseif (DEFINED CPM_ARGS_SOURCE_DIR)
|
||||
set(PACKAGE_INFO "${CPM_ARGS_SOURCE_DIR}")
|
||||
else()
|
||||
set(PACKAGE_INFO "${CPM_ARGS_VERSION}")
|
||||
endif()
|
||||
|
||||
if (DEFINED CPM_ARGS_DOWNLOAD_COMMAND)
|
||||
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS DOWNLOAD_COMMAND ${CPM_ARGS_DOWNLOAD_COMMAND})
|
||||
elseif (DEFINED CPM_ARGS_SOURCE_DIR)
|
||||
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS SOURCE_DIR ${CPM_ARGS_SOURCE_DIR})
|
||||
elseif (CPM_SOURCE_CACHE)
|
||||
string(TOLOWER ${CPM_ARGS_NAME} lower_case_name)
|
||||
set(origin_parameters ${CPM_ARGS_UNPARSED_ARGUMENTS})
|
||||
list(SORT origin_parameters)
|
||||
string(SHA1 origin_hash "${origin_parameters}")
|
||||
set(download_directory ${CPM_SOURCE_CACHE}/${lower_case_name}/${origin_hash})
|
||||
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS SOURCE_DIR ${download_directory})
|
||||
if (EXISTS ${download_directory})
|
||||
# disable the download command to allow offline builds
|
||||
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS DOWNLOAD_COMMAND "${CMAKE_COMMAND}")
|
||||
set(PACKAGE_INFO "${download_directory}")
|
||||
else()
|
||||
# remove timestamps so CMake will re-download the dependency
|
||||
file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/_deps/${lower_case_name}-subbuild)
|
||||
set(PACKAGE_INFO "${PACKAGE_INFO} -> ${download_directory}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
CPMCreateModuleFile(${CPM_ARGS_NAME} "CPMAddPackage(${ARGN})")
|
||||
|
||||
if (CPM_PACKAGE_LOCK_ENABLED)
|
||||
if ((CPM_ARGS_VERSION AND NOT CPM_ARGS_SOURCE_DIR) OR CPM_INCLUDE_ALL_IN_PACKAGE_LOCK)
|
||||
cpm_add_to_package_lock(${CPM_ARGS_NAME} "${ARGN}")
|
||||
elseif(CPM_ARGS_SOURCE_DIR)
|
||||
cpm_add_comment_to_package_lock(${CPM_ARGS_NAME} "local directory")
|
||||
else()
|
||||
cpm_add_comment_to_package_lock(${CPM_ARGS_NAME} "${ARGN}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
cpm_declare_fetch("${CPM_ARGS_NAME}" "${CPM_ARGS_VERSION}" "${PACKAGE_INFO}" "${CPM_ARGS_UNPARSED_ARGUMENTS}")
|
||||
cpm_fetch_package("${CPM_ARGS_NAME}" "${DOWNLOAD_ONLY}")
|
||||
cpm_get_fetch_properties("${CPM_ARGS_NAME}")
|
||||
|
||||
SET(${CPM_ARGS_NAME}_ADDED YES)
|
||||
cpm_export_variables("${CPM_ARGS_NAME}")
|
||||
endfunction()
|
||||
|
||||
# Fetch a previously declared package
|
||||
macro(CPMGetPackage Name)
|
||||
if (DEFINED "CPM_DECLARATION_${Name}")
|
||||
CPMAddPackage(
|
||||
NAME ${Name}
|
||||
)
|
||||
else()
|
||||
message(SEND_ERROR "Cannot retrieve package ${Name}: no declaration available")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# export variables available to the caller to the parent scope
|
||||
# expects ${CPM_ARGS_NAME} to be set
|
||||
macro(cpm_export_variables name)
|
||||
SET(${name}_SOURCE_DIR "${${name}_SOURCE_DIR}" PARENT_SCOPE)
|
||||
SET(${name}_BINARY_DIR "${${name}_BINARY_DIR}" PARENT_SCOPE)
|
||||
SET(${name}_ADDED "${${name}_ADDED}" PARENT_SCOPE)
|
||||
endmacro()
|
||||
|
||||
# declares a package, so that any call to CPMAddPackage for the
|
||||
# package name will use these arguments instead.
|
||||
# Previous declarations will not be overriden.
|
||||
macro(CPMDeclarePackage Name)
|
||||
if (NOT DEFINED "CPM_DECLARATION_${Name}")
|
||||
set("CPM_DECLARATION_${Name}" "${ARGN}")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
function(cpm_add_to_package_lock Name)
|
||||
if (NOT CPM_DONT_CREATE_PACKAGE_LOCK)
|
||||
file(APPEND ${CPM_PACKAGE_LOCK_FILE} "# ${Name}\nCPMDeclarePackage(${Name} \"${ARGN}\")\n")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(cpm_add_comment_to_package_lock Name)
|
||||
if (NOT CPM_DONT_CREATE_PACKAGE_LOCK)
|
||||
file(APPEND ${CPM_PACKAGE_LOCK_FILE} "# ${Name} (unversioned)\n# CPMDeclarePackage(${Name} \"${ARGN}\")\n")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# includes the package lock file if it exists and creates a target
|
||||
# `cpm-write-package-lock` to update it
|
||||
macro(CPMUsePackageLock file)
|
||||
if (NOT CPM_DONT_CREATE_PACKAGE_LOCK)
|
||||
get_filename_component(CPM_ABSOLUTE_PACKAGE_LOCK_PATH ${file} ABSOLUTE)
|
||||
if(EXISTS ${CPM_ABSOLUTE_PACKAGE_LOCK_PATH})
|
||||
include(${CPM_ABSOLUTE_PACKAGE_LOCK_PATH})
|
||||
endif()
|
||||
if (NOT TARGET cpm-update-package-lock)
|
||||
add_custom_target(cpm-update-package-lock COMMAND ${CMAKE_COMMAND} -E copy ${CPM_PACKAGE_LOCK_FILE} ${CPM_ABSOLUTE_PACKAGE_LOCK_PATH})
|
||||
endif()
|
||||
set(CPM_PACKAGE_LOCK_ENABLED true)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# registers a package that has been added to CPM
|
||||
function(CPMRegisterPackage PACKAGE VERSION)
|
||||
list(APPEND CPM_PACKAGES ${PACKAGE})
|
||||
set(CPM_PACKAGES ${CPM_PACKAGES} CACHE INTERNAL "")
|
||||
set("CPM_PACKAGE_${PACKAGE}_VERSION" ${VERSION} CACHE INTERNAL "")
|
||||
endfunction()
|
||||
|
||||
# retrieve the current version of the package to ${OUTPUT}
|
||||
function(CPMGetPackageVersion PACKAGE OUTPUT)
|
||||
set(${OUTPUT} "${CPM_PACKAGE_${PACKAGE}_VERSION}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# declares a package in FetchContent_Declare
|
||||
function (cpm_declare_fetch PACKAGE VERSION INFO)
|
||||
message(STATUS "${CPM_INDENT} adding package ${PACKAGE}@${VERSION} (${INFO})")
|
||||
|
||||
if (${CPM_DRY_RUN})
|
||||
message(STATUS "${CPM_INDENT} package not declared (dry run)")
|
||||
return()
|
||||
endif()
|
||||
|
||||
FetchContent_Declare(${PACKAGE}
|
||||
${ARGN}
|
||||
)
|
||||
endfunction()
|
||||
|
||||
# returns properties for a package previously defined by cpm_declare_fetch
|
||||
function (cpm_get_fetch_properties PACKAGE)
|
||||
if (${CPM_DRY_RUN})
|
||||
return()
|
||||
endif()
|
||||
FetchContent_GetProperties(${PACKAGE})
|
||||
string(TOLOWER ${PACKAGE} lpackage)
|
||||
SET(${PACKAGE}_SOURCE_DIR "${${lpackage}_SOURCE_DIR}" PARENT_SCOPE)
|
||||
SET(${PACKAGE}_BINARY_DIR "${${lpackage}_BINARY_DIR}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# downloads a previously declared package via FetchContent
|
||||
function (cpm_fetch_package PACKAGE DOWNLOAD_ONLY)
|
||||
if (${CPM_DRY_RUN})
|
||||
message(STATUS "${CPM_INDENT} package ${PACKAGE} not fetched (dry run)")
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(DOWNLOAD_ONLY)
|
||||
FetchContent_GetProperties(${PACKAGE})
|
||||
if(NOT ${PACKAGE}_POPULATED)
|
||||
FetchContent_Populate(${PACKAGE})
|
||||
endif()
|
||||
else()
|
||||
set(CPM_OLD_INDENT "${CPM_INDENT}")
|
||||
set(CPM_INDENT "${CPM_INDENT} ${PACKAGE}:")
|
||||
FetchContent_MakeAvailable(${PACKAGE})
|
||||
set(CPM_INDENT "${CPM_OLD_INDENT}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# splits a package option
|
||||
function(cpm_parse_option OPTION)
|
||||
string(REGEX MATCH "^[^ ]+" OPTION_KEY ${OPTION})
|
||||
string(LENGTH ${OPTION} OPTION_LENGTH)
|
||||
string(LENGTH ${OPTION_KEY} OPTION_KEY_LENGTH)
|
||||
if (OPTION_KEY_LENGTH STREQUAL OPTION_LENGTH)
|
||||
# no value for key provided, assume user wants to set option to "ON"
|
||||
set(OPTION_VALUE "ON")
|
||||
else()
|
||||
math(EXPR OPTION_KEY_LENGTH "${OPTION_KEY_LENGTH}+1")
|
||||
string(SUBSTRING ${OPTION} "${OPTION_KEY_LENGTH}" "-1" OPTION_VALUE)
|
||||
endif()
|
||||
set(OPTION_KEY "${OPTION_KEY}" PARENT_SCOPE)
|
||||
set(OPTION_VALUE "${OPTION_VALUE}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# guesses the package version from a git tag
|
||||
function(cpm_get_version_from_git_tag GIT_TAG RESULT)
|
||||
string(LENGTH ${GIT_TAG} length)
|
||||
if (length EQUAL 40)
|
||||
# GIT_TAG is probably a git hash
|
||||
SET(${RESULT} 0 PARENT_SCOPE)
|
||||
else()
|
||||
string(REGEX MATCH "v?([0123456789.]*).*" _ ${GIT_TAG})
|
||||
SET(${RESULT} ${CMAKE_MATCH_1} PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
57
cmake/tools.cmake
Normal file
57
cmake/tools.cmake
Normal file
@@ -0,0 +1,57 @@
|
||||
# this file contains a list of tools that can be activated and downloaded on-demand
|
||||
# each tool is enabled during configuration by passing an additional `-DUSE_<TOOL>=<VALUE>` argument to CMake
|
||||
|
||||
# only activate tools for top level project
|
||||
if (NOT PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
||||
return()
|
||||
endif()
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/CPM.cmake)
|
||||
|
||||
# enables sanitizers support using the the `USE_SANITIZER` flag
|
||||
# available values are: Address, Memory, MemoryWithOrigins, Undefined, Thread, Leak, 'Address;Undefined'
|
||||
if (USE_SANITIZER OR USE_STATIC_ANALYZER)
|
||||
CPMAddPackage(
|
||||
NAME StableCoder-cmake-scripts
|
||||
GITHUB_REPOSITORY StableCoder/cmake-scripts
|
||||
GIT_TAG 3d2d5a9fb26f0ce24e3e4eaeeff686ec2ecfb3fb
|
||||
)
|
||||
|
||||
if (USE_SANITIZER)
|
||||
include(${StableCoder-cmake-scripts_SOURCE_DIR}/sanitizers.cmake)
|
||||
endif()
|
||||
|
||||
if (USE_STATIC_ANALYZER)
|
||||
if ("clang-tidy" IN_LIST USE_STATIC_ANALYZER)
|
||||
SET(CLANG_TIDY ON CACHE INTERNAL "")
|
||||
else()
|
||||
SET(CLANG_TIDY OFF CACHE INTERNAL "")
|
||||
endif()
|
||||
if ("iwyu" IN_LIST USE_STATIC_ANALYZER)
|
||||
SET(IWYU ON CACHE INTERNAL "")
|
||||
else()
|
||||
SET(IWYU OFF CACHE INTERNAL "")
|
||||
endif()
|
||||
if ("cppcheck" IN_LIST USE_STATIC_ANALYZER)
|
||||
SET(CPPCHECK ON CACHE INTERNAL "")
|
||||
else()
|
||||
SET(CPPCHECK OFF CACHE INTERNAL "")
|
||||
endif()
|
||||
|
||||
include(${StableCoder-cmake-scripts_SOURCE_DIR}/tools.cmake)
|
||||
|
||||
clang_tidy(${CLANG_TIDY_ARGS})
|
||||
include_what_you_use(${IWYU_ARGS})
|
||||
cppcheck(${CPPCHECK_ARGS})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# enables CCACHE support through the USE_CCACHE flag
|
||||
# possible values are: YES, NO or equivalent
|
||||
if (USE_CCACHE)
|
||||
CPMAddPackage(
|
||||
NAME Ccache.cmake
|
||||
GITHUB_REPOSITORY TheLartians/Ccache.cmake
|
||||
VERSION 1.1
|
||||
)
|
||||
endif()
|
||||
20
flint.yaml
20
flint.yaml
@@ -1,20 +0,0 @@
|
||||
git:
|
||||
test_framework:
|
||||
url: https://git.mtgames.nl/Dreaded_X/test_framework
|
||||
revision: master
|
||||
|
||||
include:
|
||||
- .build/git/test_framework/flint.yaml
|
||||
|
||||
targets:
|
||||
io:
|
||||
type: lib
|
||||
path: .
|
||||
|
||||
test:
|
||||
type: exe
|
||||
path: test
|
||||
dependency:
|
||||
- io
|
||||
- logging
|
||||
- test_framework
|
||||
@@ -1,20 +0,0 @@
|
||||
#pragma once
|
||||
#include <string_view>
|
||||
|
||||
namespace io {
|
||||
template <typename T>
|
||||
concept NumberByte = std::is_integral_v<T> && sizeof(T) == 1;
|
||||
|
||||
template <typename T>
|
||||
concept Container = requires (T a) {
|
||||
typename T::value_type;
|
||||
typename T::size_type;
|
||||
typename T::iterator;
|
||||
typename T::const_iterator;
|
||||
a.size();
|
||||
a.begin();
|
||||
a.end();
|
||||
a.cbegin();
|
||||
a.cend();
|
||||
} && !std::is_convertible_v<T, std::string_view>;
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
#pragma once
|
||||
#include "helper.h"
|
||||
#include <iostream>
|
||||
#include <cstdint>
|
||||
#include <tuple>
|
||||
|
||||
namespace io {
|
||||
// This exists to allow for specialization and clearer errors
|
||||
template <typename T>
|
||||
void write(std::ostream&, T) {
|
||||
static_assert(!std::is_same_v<T,T>, "No known specialization of io::write for type");
|
||||
}
|
||||
|
||||
template <NumberByte T>
|
||||
void write(std::ostream& os, T value) {
|
||||
os.write(reinterpret_cast<const char*>(&value), sizeof(T));
|
||||
}
|
||||
|
||||
namespace {
|
||||
template <typename T>
|
||||
void write_bytes(std::ostream& os, T value, size_t length) {
|
||||
for (size_t i = length; i > 0; --i) {
|
||||
uint8_t byte = (value >> (i-1)*8) & 0xFF;
|
||||
write<uint8_t>(os, byte);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T> requires std::is_integral_v<T>
|
||||
void write(std::ostream& os, T value) {
|
||||
write_bytes(os, value, sizeof(T));
|
||||
}
|
||||
|
||||
template <>
|
||||
void write(std::ostream& os, float value);
|
||||
|
||||
// Special implementation for size_t (also uint64_t, so maybe this is not that smart)
|
||||
template <>
|
||||
void write(std::ostream& os, size_t value);
|
||||
|
||||
template <typename T> requires std::is_convertible_v<T, std::string_view>
|
||||
void write(std::ostream& os, T value, bool store_length = true) {
|
||||
std::string_view s = value;
|
||||
if (store_length) {
|
||||
write<size_t>(os, s.length());
|
||||
}
|
||||
os << s;
|
||||
}
|
||||
|
||||
// @todo Merge this into one function with the proper default automatically
|
||||
template <Container T>
|
||||
void write(std::ostream& os, const T& value, bool store_length = true) {
|
||||
if (store_length) {
|
||||
write<size_t>(os, value.size());
|
||||
}
|
||||
for (const auto& entry : value) {
|
||||
write<typename T::value_type>(os, entry);
|
||||
}
|
||||
}
|
||||
|
||||
template <Container T> requires requires (T a) { std::tuple_size<T>::value; }
|
||||
void write(std::ostream& os, const T& value, bool store_length = false) {
|
||||
if (store_length) {
|
||||
write<size_t>(os, value.size());
|
||||
}
|
||||
for (const auto& entry : value) {
|
||||
write<typename T::value_type>(os, entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
46
io/CMakeLists.txt
Normal file
46
io/CMakeLists.txt
Normal file
@@ -0,0 +1,46 @@
|
||||
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
|
||||
|
||||
project(io
|
||||
LANGUAGES CXX
|
||||
VERSION 0.1
|
||||
)
|
||||
|
||||
include(../cmake/CPM.cmake)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME PackageProject.cmake
|
||||
GITHUB_REPOSITORY TheLartians/PackageProject.cmake
|
||||
VERSION 1.3
|
||||
)
|
||||
|
||||
file(GLOB_RECURSE headers CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
|
||||
file(GLOB_RECURSE sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
|
||||
|
||||
add_library(${PROJECT_NAME} ${headers} ${sources})
|
||||
|
||||
# being a cross-platform target, we enforce standards conformance on MSVC
|
||||
target_compile_options(${PROJECT_NAME} PUBLIC "$<$<BOOL:${MSVC}>:/permissive->")
|
||||
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
CXX_STANDARD 20
|
||||
OUTPUT_NAME "${PROJECT_NAME}"
|
||||
)
|
||||
|
||||
string(TOLOWER ${PROJECT_NAME}/version.h VERSION_HEADER_LOCATION)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
|
||||
)
|
||||
|
||||
string(TOLOWER ${PROJECT_NAME}/version.h VERSION_HEADER_LOCATION)
|
||||
packageProject(
|
||||
NAME ${PROJECT_NAME}
|
||||
VERSION ${PROJECT_VERSION}
|
||||
BINARY_DIR ${PROJECT_BINARY_DIR}
|
||||
INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include
|
||||
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
|
||||
VERSION_HEADER "${VERSION_HEADER_LOCATION}"
|
||||
DEPENDENCIES ""
|
||||
)
|
||||
38
io/include/io/helper.h
Normal file
38
io/include/io/helper.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
#include <string_view>
|
||||
#include <tuple>
|
||||
|
||||
namespace io {
|
||||
template <typename T>
|
||||
concept Array = requires (T a) {
|
||||
std::tuple_size<T>::value;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
concept Container = requires (T a) {
|
||||
typename T::value_type;
|
||||
typename T::size_type;
|
||||
typename T::iterator;
|
||||
typename T::const_iterator;
|
||||
a.size();
|
||||
a.begin();
|
||||
a.end();
|
||||
a.cbegin();
|
||||
a.cend();
|
||||
} && !std::is_convertible_v<T, std::string_view> && !Array<T>;
|
||||
|
||||
template <typename T>
|
||||
concept Size = std::is_same_v<T, size_t>;
|
||||
|
||||
template <typename T>
|
||||
concept NumberByte = std::is_integral_v<T> && sizeof(T) == 1;
|
||||
|
||||
template <typename T>
|
||||
concept Number = (std::is_integral_v<T> && !NumberByte<T>) && !Size<T>;
|
||||
|
||||
template <typename T>
|
||||
concept Float = std::is_same_v<T, float>;
|
||||
|
||||
template <typename T>
|
||||
concept String = std::is_convertible_v<T, std::string_view>;
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "helper.h"
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
|
||||
namespace io {
|
||||
// This exists to allow for specialization and clearer errors
|
||||
@@ -29,7 +30,7 @@ namespace io {
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T> requires std::is_integral_v<T>
|
||||
template <typename T> requires (std::is_integral_v<T> && !NumberByte<T>)
|
||||
T read(std::istream& is) {
|
||||
T value = read_bytes<T>(is, sizeof(T));
|
||||
return value;
|
||||
@@ -56,8 +57,6 @@ namespace io {
|
||||
return read<T>(is, length);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <Container T>
|
||||
T read(std::istream& is, size_t length) {
|
||||
T v(length);
|
||||
@@ -73,12 +72,11 @@ namespace io {
|
||||
return read<T>(is, length);
|
||||
}
|
||||
|
||||
// Static sized container
|
||||
template <Container T> requires requires (T a) { std::tuple_size<T>::value; }
|
||||
template <Array T>
|
||||
T read(std::istream& is) {
|
||||
T v;
|
||||
for (size_t i = 0; i < std::tuple_size<T>::value; ++i) {
|
||||
v[i] = io::read<typename T::value_type>(is);
|
||||
for (auto& e : v) {
|
||||
e = io::read<typename T::value_type>(is);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
106
io/include/io/write.h
Normal file
106
io/include/io/write.h
Normal file
@@ -0,0 +1,106 @@
|
||||
#pragma once
|
||||
#include "helper.h"
|
||||
#include <iostream>
|
||||
#include <cstdint>
|
||||
#include <tuple>
|
||||
|
||||
namespace io {
|
||||
// This exists to allow for specialization and clearer errors
|
||||
template <typename T>
|
||||
void write(std::ostream&, const T&) {
|
||||
static_assert(!std::is_same_v<T,T>, "No known specialization of io::write for type");
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void write(std::ostream&, const T&, bool) {
|
||||
static_assert(!std::is_same_v<T,T>, "No known specialization of io::write for type");
|
||||
}
|
||||
|
||||
template <NumberByte T>
|
||||
void write(std::ostream& os, const T& value) {
|
||||
os.write(reinterpret_cast<const char*>(&value), sizeof(T));
|
||||
}
|
||||
|
||||
namespace {
|
||||
template <typename T>
|
||||
void write_bytes(std::ostream& os, const T& value, size_t length) {
|
||||
for (size_t i = length; i > 0; --i) {
|
||||
uint8_t byte = (value >> (i-1)*8) & 0xFF;
|
||||
write<uint8_t>(os, byte);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <Number T>
|
||||
void write(std::ostream& os, const T& value) {
|
||||
write_bytes(os, value, sizeof(T));
|
||||
}
|
||||
|
||||
template <Float T>
|
||||
void write(std::ostream& os, const float& value) {
|
||||
union {
|
||||
uint32_t a;
|
||||
float b;
|
||||
} u;
|
||||
|
||||
u.b = value;
|
||||
write_bytes(os, u.a, sizeof(uint32_t));
|
||||
}
|
||||
|
||||
// Special implementation for size_t (also uint64_t, so maybe this is not that smart)
|
||||
template <Size T>
|
||||
void write(std::ostream& os, const size_t& value) {
|
||||
// Check if we need more then one byte
|
||||
if (value > 0b01111111) {
|
||||
// Calculate how many bytes we need to store the number
|
||||
uint8_t length = 0;
|
||||
auto x = value;
|
||||
while (x != 0) {
|
||||
x >>= 8;
|
||||
length++;
|
||||
}
|
||||
|
||||
write<uint8_t>(os, length | 0b10000000);
|
||||
write_bytes(os, value, length);
|
||||
} else {
|
||||
write<uint8_t>(os, value);
|
||||
}
|
||||
}
|
||||
|
||||
template <String T>
|
||||
void write(std::ostream& os, const T& value, bool store_length) {
|
||||
std::string_view s = value;
|
||||
if (store_length) {
|
||||
write<size_t>(os, s.length());
|
||||
}
|
||||
os << s;
|
||||
}
|
||||
|
||||
template <String T>
|
||||
void write(std::ostream& os, const T& value) {
|
||||
write(os, value, true);
|
||||
}
|
||||
|
||||
// @todo Merge this into one function with the proper default automatically
|
||||
template <Container T>
|
||||
void write(std::ostream& os, const T& value, bool store_length) {
|
||||
if (store_length) {
|
||||
write<size_t>(os, value.size());
|
||||
}
|
||||
for (const auto& entry : value) {
|
||||
write<typename T::value_type>(os, entry);
|
||||
}
|
||||
}
|
||||
|
||||
template <Container T>
|
||||
void write(std::ostream& os, const T& value) {
|
||||
write(os, value, true);
|
||||
}
|
||||
|
||||
template <Array T>
|
||||
void write(std::ostream& os, const T& value) {
|
||||
for (const auto& entry : value) {
|
||||
write<typename T::value_type>(os, entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
4
io/src/write.cpp
Normal file
4
io/src/write.cpp
Normal file
@@ -0,0 +1,4 @@
|
||||
#include "io/write.h"
|
||||
|
||||
namespace io {
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
#include "io/write.h"
|
||||
|
||||
namespace io {
|
||||
template<>
|
||||
void write(std::ostream& os, float value) {
|
||||
union {
|
||||
uint32_t a;
|
||||
float b;
|
||||
} u;
|
||||
|
||||
u.b = value;
|
||||
write_bytes(os, u.a, sizeof(uint32_t));
|
||||
}
|
||||
|
||||
// Special implementation for size_t (also uint64_t, so maybe this is not that smart)
|
||||
template<>
|
||||
void write(std::ostream& os, size_t value) {
|
||||
// Check if we need more then one byte
|
||||
if (value > 0b01111111) {
|
||||
// Calculate how many bytes we need to store the number
|
||||
uint8_t length = 0;
|
||||
auto x = value;
|
||||
while (x != 0) {
|
||||
x >>= 8;
|
||||
length++;
|
||||
}
|
||||
|
||||
write<uint8_t>(os, length | 0b10000000);
|
||||
write_bytes(os, value, length);
|
||||
} else {
|
||||
write<uint8_t>(os, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
38
test/CMakeLists.txt
Normal file
38
test/CMakeLists.txt
Normal file
@@ -0,0 +1,38 @@
|
||||
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
|
||||
|
||||
project(io_test
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
include(../cmake/CPM.cmake)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME test_framework
|
||||
GIT_TAG master
|
||||
GIT_REPOSITORY https://git.mtgames.nl/Dreaded_X/test_framework
|
||||
)
|
||||
|
||||
file(GLOB_RECURSE headers CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
|
||||
file(GLOB_RECURSE sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${headers} ${sources})
|
||||
|
||||
# being a cross-platform target, we enforce standards conformance on MSVC
|
||||
target_compile_options(${PROJECT_NAME} PUBLIC "$<$<BOOL:${MSVC}>:/permissive->")
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
|
||||
)
|
||||
|
||||
|
||||
# Link dependencies (if required)
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC test_framework io)
|
||||
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
CXX_STANDARD 20
|
||||
OUTPUT_NAME "${PROJECT_NAME}"
|
||||
)
|
||||
|
||||
message("${INCLUDE_DIRECTORIES}")
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <list>
|
||||
#include <forward_list>
|
||||
#include <fstream>
|
||||
#include <limits>
|
||||
|
||||
struct A {
|
||||
int b;
|
||||
@@ -18,7 +19,7 @@ struct A {
|
||||
|
||||
namespace io {
|
||||
template <>
|
||||
void write(std::ostream& os, A value) {
|
||||
void write(std::ostream& os, const A& value) {
|
||||
write<int>(os, value.b);
|
||||
}
|
||||
|
||||
@@ -280,10 +281,9 @@ int main() {
|
||||
Test("Write for std::array<char> (length)", [] {
|
||||
std::fstream f("test.bin", std::ios::trunc | std::ios::in | std::ios::out);
|
||||
std::array<char, 2> value = {'c', 'd'};
|
||||
io::write<std::array<char, 2>>(f, value, true);
|
||||
io::write<std::array<char, 2>>(f, value);
|
||||
|
||||
bool succes = 3 == f.tellg(); f.seekg(0); char c;
|
||||
f.read(&c,1); succes &= (c & 0xff) == 2;
|
||||
bool succes = 2 == f.tellg(); f.seekg(0); char c;
|
||||
f.read(&c,1); succes &= (c & 0xff) == 'c';
|
||||
f.read(&c,1); succes &= (c & 0xff) == 'd';
|
||||
return succes;
|
||||
@@ -291,7 +291,7 @@ int main() {
|
||||
|
||||
Test("Read for std::array<char> (as std::vector<char>, length)", [] {
|
||||
std::ifstream f("test.bin");
|
||||
std::vector<char> value = io::read<std::vector<char>>(f);
|
||||
std::vector<char> value = io::read<std::vector<char>>(f, 2);
|
||||
return value.size() == 2 && value[0] == 'c' && value[1] == 'd';
|
||||
}());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user