Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 68 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,27 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


# Options
option(SOURCEPP_LIBS_START_ENABLED "Libraries will all build by default" ON)
option(SOURCEPP_USE_BSPPP "Build bsppp library" ${SOURCEPP_LIBS_START_ENABLED})
option(SOURCEPP_USE_DMXPP "Build dmxpp library" ${SOURCEPP_LIBS_START_ENABLED})
option(SOURCEPP_USE_GAMEPP "Build gamepp library" ${SOURCEPP_LIBS_START_ENABLED})
option(SOURCEPP_USE_KVPP "Build kvpp library" ${SOURCEPP_LIBS_START_ENABLED})
option(SOURCEPP_USE_MDLPP "Build mdlpp library" ${SOURCEPP_LIBS_START_ENABLED})
option(SOURCEPP_USE_STEAMPP "Build steampp library" ${SOURCEPP_LIBS_START_ENABLED})
option(SOURCEPP_USE_TOOLPP "Build toolpp library" ${SOURCEPP_LIBS_START_ENABLED})
option(SOURCEPP_USE_VICEPP "Build vicepp library" ${SOURCEPP_LIBS_START_ENABLED})
option(SOURCEPP_USE_VPKPP "Build vpkpp library" ${SOURCEPP_LIBS_START_ENABLED})
option(SOURCEPP_USE_VTFPP "Build vtfpp library" ${SOURCEPP_LIBS_START_ENABLED})
option(SOURCEPP_BUILD_C_WRAPPERS "Build C wrappers for supported libraries" OFF)
option(SOURCEPP_BUILD_TESTS "Build tests for enabled libraries" OFF)
option(SOURCEPP_BUILD_WIN7_COMPAT "Build with Windows 7 compatibility" OFF)
option(SOURCEPP_LINK_STATIC_MSVC_RUNTIME "Link to static MSVC runtime library" OFF)
# Options (update print_options at the bottom of this file when modifying)
option(SOURCEPP_LIBS_START_ENABLED "Libraries will all build by default" ON)
option(SOURCEPP_USE_BSPPP "Build bsppp library" ${SOURCEPP_LIBS_START_ENABLED})
option(SOURCEPP_USE_DMXPP "Build dmxpp library" ${SOURCEPP_LIBS_START_ENABLED})
option(SOURCEPP_USE_GAMEPP "Build gamepp library" ${SOURCEPP_LIBS_START_ENABLED})
option(SOURCEPP_USE_KVPP "Build kvpp library" ${SOURCEPP_LIBS_START_ENABLED})
option(SOURCEPP_USE_MDLPP "Build mdlpp library" ${SOURCEPP_LIBS_START_ENABLED})
option(SOURCEPP_USE_STEAMPP "Build steampp library" ${SOURCEPP_LIBS_START_ENABLED})
option(SOURCEPP_USE_TOOLPP "Build toolpp library" ${SOURCEPP_LIBS_START_ENABLED})
option(SOURCEPP_USE_VICEPP "Build vicepp library" ${SOURCEPP_LIBS_START_ENABLED})
option(SOURCEPP_USE_VPKPP "Build vpkpp library" ${SOURCEPP_LIBS_START_ENABLED})
option(SOURCEPP_USE_VTFPP "Build vtfpp library" ${SOURCEPP_LIBS_START_ENABLED})

option(SOURCEPP_BUILD_BENCHMARKS "Build benchmarks for supported libraries" OFF)
option(SOURCEPP_BUILD_C_WRAPPERS "Build C wrappers for supported libraries" OFF)
option(SOURCEPP_BUILD_WITH_OPENCL "Build with support for GPU compute" OFF)
option(SOURCEPP_BUILD_WITH_TBB "Build with support for std::execution" OFF)
option(SOURCEPP_BUILD_TESTS "Build tests for supported libraries" OFF)
option(SOURCEPP_BUILD_WIN7_COMPAT "Build with Windows 7 compatibility" OFF)

option(SOURCEPP_LINK_STATIC_MSVC_RUNTIME "Link to static MSVC runtime library" OFF)


# Option overrides
Expand All @@ -43,6 +48,11 @@ if(SOURCEPP_USE_VPKPP)
set(SOURCEPP_USE_KVPP ON CACHE INTERNAL "" FORCE)
endif()

if(MSVC)
# MSVC does not rely on tbb for std::execution policies, so we can force this on
set(SOURCEPP_BUILD_WITH_TBB ON CACHE INTERNAL "" FORCE)
endif()


# Set defaults after project call
if(PROJECT_IS_TOP_LEVEL)
Expand All @@ -59,6 +69,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(AddPrettyParser)
include(AddSourcePPLibrary)
include(IncludeSubdirectory)
include(PrintOptions)


# Include thirdparty libraries
Expand All @@ -82,25 +93,40 @@ if(SOURCEPP_BUILD_TESTS)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.14.0)
GIT_TAG v1.15.2)
FetchContent_MakeAvailable(googletest)
enable_testing()
set(${SOURCEPP_TEST_NAME}_SOURCES "")
list(APPEND ${SOURCEPP_TEST_NAME}_DEPS gtest_main)
endif()


# Benchmarks, part 1
if(SOURCEPP_BUILD_BENCHMARKS)
set(SOURCEPP_BENCH_NAME "${PROJECT_NAME}_bench")
include(FetchContent)
FetchContent_Declare(
benchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.9.0)
set(BENCHMARK_ENABLE_TESTING OFF CACHE INTERNAL "" FORCE)
FetchContent_MakeAvailable(benchmark)
list(APPEND ${SOURCEPP_BENCH_NAME}_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/test/bench/_bench.cpp")
list(APPEND ${SOURCEPP_BENCH_NAME}_DEPS benchmark::benchmark)
endif()


# Add libraries
add_sourcepp_library(bsppp NO_TEST) # sourcepp::bsppp
add_sourcepp_library(dmxpp) # sourcepp::dmxpp
add_sourcepp_library(gamepp) # sourcepp::gamepp
add_sourcepp_library(kvpp) # sourcepp::kvpp
add_sourcepp_library(mdlpp) # sourcepp::mdlpp
add_sourcepp_library(steampp C) # sourcepp::steampp
add_sourcepp_library(toolpp) # sourcepp::toolpp
add_sourcepp_library(vicepp C CSHARP) # sourcepp::vicepp
add_sourcepp_library(vpkpp C CSHARP NO_TEST) # sourcepp::vpkpp
add_sourcepp_library(vtfpp) # sourcepp::vtfpp
add_sourcepp_library(bsppp NO_TEST ) # sourcepp::bsppp
add_sourcepp_library(dmxpp ) # sourcepp::dmxpp
add_sourcepp_library(gamepp ) # sourcepp::gamepp
add_sourcepp_library(kvpp ) # sourcepp::kvpp
add_sourcepp_library(mdlpp ) # sourcepp::mdlpp
add_sourcepp_library(steampp C ) # sourcepp::steampp
add_sourcepp_library(toolpp ) # sourcepp::toolpp
add_sourcepp_library(vicepp C CSHARP ) # sourcepp::vicepp
add_sourcepp_library(vpkpp C CSHARP NO_TEST ) # sourcepp::vpkpp
add_sourcepp_library(vtfpp BENCH) # sourcepp::vtfpp


# Tests, part 2
Expand All @@ -111,3 +137,18 @@ if(SOURCEPP_BUILD_TESTS)
include(GoogleTest)
gtest_discover_tests(${SOURCEPP_TEST_NAME})
endif()


# Benchmarks, part 2
if(SOURCEPP_BUILD_BENCHMARKS)
add_executable(${SOURCEPP_BENCH_NAME} ${${SOURCEPP_BENCH_NAME}_SOURCES})
target_link_libraries(${SOURCEPP_BENCH_NAME} PUBLIC ${${SOURCEPP_BENCH_NAME}_DEPS})
target_compile_definitions(${SOURCEPP_BENCH_NAME} PUBLIC ASSET_ROOT="${CMAKE_CURRENT_SOURCE_DIR}/test/res/")
endif()


# Print options
print_options(OPTIONS
USE_BSPPP USE_DMXPP USE_GAMEPP USE_KVPP USE_MDLPP USE_STEAMPP USE_TOOLPP USE_VICEPP USE_VPKPP USE_VTFPP
BUILD_BENCHMARKS BUILD_C_WRAPPERS BUILD_WITH_OPENCL BUILD_WITH_TBB BUILD_TESTS BUILD_WIN7_COMPAT
LINK_STATIC_MSVC_RUNTIME)
4 changes: 2 additions & 2 deletions Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ WARN_LOGFILE =
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
# Note: If this tag is empty the current directory is searched.

INPUT = docs/DOXYMAINPAGE.md \
INPUT = docs/index.md \
include \
src

Expand Down Expand Up @@ -1165,7 +1165,7 @@ FILTER_SOURCE_PATTERNS =
# (index.html). This can be useful if you have a project on for instance GitHub
# and want to reuse the introduction page also for the doxygen output.

USE_MDFILE_AS_MAINPAGE = docs/DOXYMAINPAGE.md
USE_MDFILE_AS_MAINPAGE = docs/index.md

# The Fortran standard specifies that for fixed formatted Fortran code all
# characters from position 72 are to be considered as comment. A common
Expand Down
5 changes: 5 additions & 0 deletions cmake/AddPrettyParser.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ function(add_pretty_parser TARGET)
# Define DEBUG macro
target_compile_definitions(${TARGET} PRIVATE "$<$<CONFIG:Debug>:DEBUG>")

# MSVC on its bullshit again
if(MSVC)
target_compile_options(${TARGET} PRIVATE "/Zc:preprocessor")
endif()

# Set optimization flags
if(CMAKE_BUILD_TYPE MATCHES "Debug")
# Build with debug friendly optimizations and debug symbols (MSVC defaults are fine)
Expand Down
16 changes: 14 additions & 2 deletions cmake/AddSourcePPLibrary.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function(add_sourcepp_library TARGET)
cmake_parse_arguments(PARSE_ARGV 1 OPTIONS "C;CSHARP;NO_TEST" "" "")
cmake_parse_arguments(PARSE_ARGV 1 OPTIONS "C;CSHARP;NO_TEST;BENCH" "" "")
string(TOUPPER ${TARGET} TARGET_UPPER)
if(SOURCEPP_USE_${TARGET_UPPER})
# Add C++
Expand All @@ -17,11 +17,23 @@ function(add_sourcepp_library TARGET)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/lang/csharp/src/sourcepp/TARGET.csproj.in" "${CMAKE_CURRENT_SOURCE_DIR}/lang/csharp/src/${TARGET}/${TARGET}.csproj")
endif()

set(PROPAGATE_VARS "")

# Add tests
if(NOT OPTIONS_NO_TEST AND SOURCEPP_BUILD_TESTS)
list(APPEND ${SOURCEPP_TEST_NAME}_DEPS ${TARGET})
list(APPEND ${SOURCEPP_TEST_NAME}_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/test/${TARGET}.cpp")
return(PROPAGATE ${SOURCEPP_TEST_NAME}_DEPS ${SOURCEPP_TEST_NAME}_SOURCES)
list(APPEND PROPAGATE_VARS ${SOURCEPP_TEST_NAME}_DEPS ${SOURCEPP_TEST_NAME}_SOURCES)
endif()

# Add benchmarks
if(OPTIONS_BENCH AND SOURCEPP_BUILD_BENCHMARKS)
include("${CMAKE_CURRENT_SOURCE_DIR}/test/bench/${TARGET}.cmake")
list(APPEND ${SOURCEPP_BENCH_NAME}_DEPS ${TARGET})
list(APPEND ${SOURCEPP_BENCH_NAME}_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/test/bench/${TARGET}.cpp")
list(APPEND PROPAGATE_VARS ${SOURCEPP_BENCH_NAME}_DEPS ${SOURCEPP_BENCH_NAME}_SOURCES)
endif()

return(PROPAGATE ${PROPAGATE_VARS})
endif()
endfunction()
10 changes: 10 additions & 0 deletions cmake/PrintOptions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function(print_options)
cmake_parse_arguments(PARSE_ARGV 0 IN "" "" "OPTIONS")
foreach (OPT ${IN_OPTIONS})
if(SOURCEPP_${OPT})
message(STATUS "[X] SOURCEPP_${OPT}")
else()
message(STATUS "[ ] SOURCEPP_${OPT}")
endif()
endforeach()
endfunction()
File renamed without changes.
35 changes: 31 additions & 4 deletions ext/_ext.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/compressonator")

# cryptopp
if(NOT TARGET cryptopp::cryptopp)
set(CRYPTOPP_BUILD_TESTING OFF CACHE INTERNAL "")
set(CRYPTOPP_INSTALL OFF CACHE INTERNAL "")
set(CRYPTOPP_BUILD_TESTING OFF CACHE INTERNAL "" FORCE)
set(CRYPTOPP_INSTALL OFF CACHE INTERNAL "" FORCE)
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/cryptopp")

# hack: clang on windows (NOT clang-cl) needs these to compile cryptopp
Expand Down Expand Up @@ -39,7 +39,7 @@ endif()

# minizip-ng
if(NOT TARGET MINIZIP::minizip)
set(MZ_COMPAT OFF CACHE INTERNAL "")
set(MZ_COMPAT OFF CACHE INTERNAL "" FORCE)
set(MZ_ZLIB ON CACHE INTERNAL "")
set(MZ_BZIP2 ON CACHE INTERNAL "")
set(MZ_LZMA ON CACHE INTERNAL "")
Expand All @@ -50,7 +50,7 @@ if(NOT TARGET MINIZIP::minizip)
set(MZ_OPENSSL OFF CACHE INTERNAL "")
set(MZ_FETCH_LIBS ON CACHE INTERNAL "")
set(MZ_FORCE_FETCH_LIBS ON CACHE INTERNAL "")
set(SKIP_INSTALL_ALL ON CACHE INTERNAL "")
set(SKIP_INSTALL_ALL ON CACHE INTERNAL "" FORCE)
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/minizip-ng")

if(SOURCEPP_BUILD_WIN7_COMPAT)
Expand All @@ -63,5 +63,32 @@ if(NOT TARGET MINIZIP::minizip)
endif()


# OpenCL
if(SOURCEPP_BUILD_WITH_OPENCL AND NOT TARGET OpenCL::OpenCL)
find_package(OpenCL)
if(NOT OpenCL_FOUND)
set(SOURCEPP_BUILD_WITH_OPENCL OFF CACHE INTERNAL "" FORCE)
endif()
endif()

function(sourcepp_add_opencl TARGET)
if(SOURCEPP_BUILD_WITH_OPENCL)
target_compile_definitions(${TARGET} PRIVATE SOURCEPP_BUILD_WITH_OPENCL)
target_link_libraries(${TARGET} PRIVATE OpenCL::OpenCL)
endif()
endfunction()


# stb
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/stb")


# TBB
function(sourcepp_add_tbb TARGET)
if(SOURCEPP_BUILD_WITH_TBB)
target_compile_definitions(${TARGET} PRIVATE SOURCEPP_BUILD_WITH_TBB)
if(NOT MSVC)
target_link_libraries(${TARGET} PRIVATE tbb)
endif()
endif()
endfunction()
8 changes: 4 additions & 4 deletions include/sourcepp/math/Float.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ namespace sourcepp::math {
// https://stackoverflow.com/a/60047308
class FloatCompressed16 {
public:
explicit FloatCompressed16(uint16_t in) {
this->data = in;
}
explicit FloatCompressed16(uint16_t in)
: data(in) {}

explicit FloatCompressed16(float in) { // IEEE-754 16-bit floating-point format (without infinity): 1-5-10, exp-15, +-131008.0, +-6.1035156E-5, +-5.9604645E-8, 3.311 digits
// NOLINTNEXTLINE(*-explicit-constructor)
FloatCompressed16(float in) { // IEEE-754 16-bit floating-point format (without infinity): 1-5-10, exp-15, +-131008.0, +-6.1035156E-5, +-5.9604645E-8, 3.311 digits
const auto b = *reinterpret_cast<uint32_t*>(&in) + 0x00001000; // round-to-nearest-even: add last bit after truncated mantissa
const auto e = (b & 0x7F800000) >> 23; // exponent
const auto m = b & 0x007FFFFF; // mantissa; in line below: 0x007FF000 = 0x00800000-0x00001000 = decimal indicator flag - initial rounding
Expand Down
2 changes: 1 addition & 1 deletion include/toolpp/FGD.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class FGDWriter {

[[nodiscard]] std::string bake();

void bake(const std::string& fgdPath);
bool bake(const std::string& fgdPath);

protected:
FGDWriter();
Expand Down
5 changes: 5 additions & 0 deletions include/vpkpp/PackFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ class PackFile {
/// Run a callback for each entry in the pack file
void runForAllEntries(const EntryCallback& operation, bool includeUnbaked = true) const;

/// Run a callback for each entry in the pack file under the parent directory
void runForAllEntries(const std::string& parentDir, const EntryCallback& operation, bool recursive = true, bool includeUnbaked = true) const;

/// /home/user/pak01_dir.vpk
[[nodiscard]] std::string_view getFilepath() const;

Expand Down Expand Up @@ -186,6 +189,8 @@ class PackFile {

void runForAllEntriesInternal(const std::function<void(const std::string&, Entry&)>& operation, bool includeUnbaked = true);

void runForAllEntriesInternal(const std::string& parentDir, const std::function<void(const std::string&, Entry&)>& operation, bool recursive = true, bool includeUnbaked = true);

[[nodiscard]] std::vector<std::string> verifyEntryChecksumsUsingCRC32() const;

virtual void addEntryInternal(Entry& entry, const std::string& path, std::vector<std::byte>& buffer, EntryOptions options) = 0;
Expand Down
Loading