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
67 changes: 48 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ option(SOURCEPP_USE_VCRYPTPP "Build vcryptpp library" ${SOURC
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_WITH_THREADS "Build with support for threading" ON)
option(SOURCEPP_BUILD_TESTS "Build tests for supported libraries" OFF)
option(SOURCEPP_BUILD_WIN7_COMPAT "Build with Windows 7 compatibility" OFF)
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_CSHARP_WRAPPERS "Build C# wrappers for supported libraries" OFF)
option(SOURCEPP_BUILD_PYTHON_WRAPPERS "Build Python 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_WITH_THREADS "Build with support for threading" ON)
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)

Expand All @@ -53,6 +55,9 @@ if(SOURCEPP_USE_VPKPP)
set(SOURCEPP_USE_KVPP ON CACHE INTERNAL "" FORCE)
endif()

if(SOURCEPP_BUILD_CSHARP_WRAPPERS)
set(SOURCEPP_BUILD_C_WRAPPERS 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)
Expand All @@ -73,6 +78,7 @@ endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(AddPrettyParser)
include(AddSourcePPLibrary)
include(FetchContent)
include(IncludeSubdirectory)
include(PrintOptions)
include(TargetOptimize)
Expand All @@ -92,10 +98,24 @@ if(SOURCEPP_BUILD_C_WRAPPERS)
endif()


# Python bindings, part 1
if(SOURCEPP_BUILD_PYTHON_WRAPPERS)
set(SOURCEPP_PYTHON_NAME "${PROJECT_NAME}_python")
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
FetchContent_Declare(
pybind11
GIT_REPOSITORY "https://github.com/pybind/pybind11.git"
GIT_TAG "v2.13.6")
FetchContent_MakeAvailable(pybind11)
set(${SOURCEPP_PYTHON_NAME}_SOURCES "")
set(${SOURCEPP_PYTHON_NAME}_DEFINES "")
list(APPEND ${SOURCEPP_PYTHON_NAME}_DEPS pybind11::headers)
endif()


# Tests, part 1
if(SOURCEPP_BUILD_TESTS)
set(SOURCEPP_TEST_NAME "${PROJECT_NAME}_test")
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY "https://github.com/google/googletest.git"
Expand Down Expand Up @@ -138,16 +158,16 @@ 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 BENCH) # sourcepp::kvpp
add_sourcepp_library(mdlpp ) # sourcepp::mdlpp
add_sourcepp_library(steampp C ) # sourcepp::steampp
add_sourcepp_library(toolpp ) # sourcepp::toolpp
add_sourcepp_library(vcryptpp C CSHARP ) # sourcepp::vcryptpp
add_sourcepp_library(vpkpp C CSHARP NO_TEST ) # sourcepp::vpkpp
add_sourcepp_library(vtfpp BENCH) # sourcepp::vtfpp
add_sourcepp_library(bsppp NO_TEST ) # sourcepp::bsppp
add_sourcepp_library(dmxpp ) # sourcepp::dmxpp
add_sourcepp_library(gamepp PYTHON ) # sourcepp::gamepp
add_sourcepp_library(kvpp BENCH) # sourcepp::kvpp
add_sourcepp_library(mdlpp ) # sourcepp::mdlpp
add_sourcepp_library(steampp C PYTHON ) # sourcepp::steampp
add_sourcepp_library(toolpp ) # sourcepp::toolpp
add_sourcepp_library(vcryptpp C CSHARP PYTHON ) # sourcepp::vcryptpp
add_sourcepp_library(vpkpp C CSHARP NO_TEST ) # sourcepp::vpkpp
add_sourcepp_library(vtfpp BENCH) # sourcepp::vtfpp


# Tests, part 2
Expand All @@ -160,9 +180,18 @@ if(SOURCEPP_BUILD_TESTS)
endif()


# Python bindings, part 2
if(SOURCEPP_BUILD_PYTHON_WRAPPERS)
python_add_library(${SOURCEPP_PYTHON_NAME} MODULE "${CMAKE_CURRENT_SOURCE_DIR}/lang/python/src/sourcepp.cpp" ${${SOURCEPP_PYTHON_NAME}_SOURCES} WITH_SOABI)
set_target_properties(${SOURCEPP_PYTHON_NAME} PROPERTIES PREFIX "_" LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/lang/python/dist/sourcepp")
target_compile_definitions(${SOURCEPP_PYTHON_NAME} PRIVATE ${${SOURCEPP_PYTHON_NAME}_DEFINES})
target_link_libraries(${SOURCEPP_PYTHON_NAME} PRIVATE ${${SOURCEPP_PYTHON_NAME}_DEPS})
endif()


# Print options
print_options(OPTIONS
USE_BSPPP USE_DMXPP USE_GAMEPP USE_KVPP USE_MDLPP USE_STEAMPP USE_TOOLPP USE_VCRYPTPP USE_VPKPP USE_VTFPP
BUILD_BENCHMARKS BUILD_C_WRAPPERS BUILD_WITH_OPENCL BUILD_WITH_TBB BUILD_WITH_THREADS BUILD_TESTS BUILD_WIN7_COMPAT
BUILD_BENCHMARKS BUILD_C_WRAPPERS BUILD_PYTHON_WRAPPERS BUILD_WITH_OPENCL BUILD_WITH_TBB BUILD_WITH_THREADS BUILD_TESTS BUILD_WIN7_COMPAT
LINK_STATIC_MSVC_RUNTIME
VPKPP_SUPPORT_VPK_V54)
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Several modern C++20 libraries for sanely parsing Valve formats, rolled into one
<td>Get Source engine instance window title/position/size</td>
<td align="center">✅</td>
<td align="center">❌</td>
<td rowspan="3" align="center"></td>
<td rowspan="3" align="center">Python</td>
</tr>
<tr><!-- empty row to disable github striped bg color --></tr>
<tr>
Expand Down Expand Up @@ -84,7 +84,7 @@ Several modern C++20 libraries for sanely parsing Valve formats, rolled into one
<td>Find Steam install folder</td>
<td align="center">✅</td>
<td align="center">-</td>
<td rowspan="3" align="center">C</td>
<td rowspan="3" align="center">C<br>Python</td>
</tr>
<tr><!-- empty row to disable github striped bg color --></tr>
<tr>
Expand Down Expand Up @@ -119,7 +119,7 @@ Several modern C++20 libraries for sanely parsing Valve formats, rolled into one
<td><a href="https://developer.valvesoftware.com/wiki/VICE">VICE</a> encrypted files</td>
<td align="center">✅</td>
<td align="center">✅</td>
<td rowspan="3" align="center">C<br>C#</td>
<td rowspan="3" align="center">C<br>C#<br>Python</td>
</tr>
<tr><!-- empty row to disable github striped bg color --></tr>
<tr>
Expand Down
20 changes: 15 additions & 5 deletions cmake/AddSourcePPLibrary.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
function(add_sourcepp_library TARGET)
cmake_parse_arguments(PARSE_ARGV 1 OPTIONS "C;CSHARP;NO_TEST;BENCH" "" "")
cmake_parse_arguments(PARSE_ARGV 1 OPTIONS "C;CSHARP;PYTHON;NO_TEST;BENCH" "" "")
string(TOUPPER ${TARGET} TARGET_UPPER)
if(SOURCEPP_USE_${TARGET_UPPER})
set(PROPAGATE_VARS "")

# Add C++
include("${CMAKE_CURRENT_SOURCE_DIR}/src/${TARGET}/_${TARGET}.cmake")

Expand All @@ -11,23 +13,31 @@ function(add_sourcepp_library TARGET)
endif()

# Add C#
if(OPTIONS_CSHARP)
if(SOURCEPP_BUILD_CSHARP_WRAPPERS AND OPTIONS_CSHARP)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/lang/csharp/src/sourcepp/Buffer.cs.in" "${CMAKE_CURRENT_SOURCE_DIR}/lang/csharp/src/${TARGET}/Buffer.cs")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/lang/csharp/src/sourcepp/String.cs.in" "${CMAKE_CURRENT_SOURCE_DIR}/lang/csharp/src/${TARGET}/String.cs")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/lang/csharp/src/sourcepp/TARGET.csproj.in" "${CMAKE_CURRENT_SOURCE_DIR}/lang/csharp/src/${TARGET}/${TARGET}.csproj")
add_custom_target(${TARGET}_csharp DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/lang/csharp/src/${TARGET}/${TARGET}.csproj")
add_dependencies(${TARGET}_csharp ${TARGET}c)
endif()

set(PROPAGATE_VARS "")
# Add Python
if(SOURCEPP_BUILD_PYTHON_WRAPPERS AND OPTIONS_PYTHON)
list(APPEND ${SOURCEPP_PYTHON_NAME}_DEPS sourcepp::${TARGET})
list(APPEND ${SOURCEPP_PYTHON_NAME}_DEFINES ${TARGET_UPPER})
list(APPEND ${SOURCEPP_PYTHON_NAME}_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/lang/python/src/${TARGET}.h")
list(APPEND PROPAGATE_VARS ${SOURCEPP_PYTHON_NAME}_DEPS ${SOURCEPP_PYTHON_NAME}_DEFINES ${SOURCEPP_PYTHON_NAME}_SOURCES)
endif()

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

# Add benchmarks
if(OPTIONS_BENCH AND SOURCEPP_BUILD_BENCHMARKS)
if(SOURCEPP_BUILD_BENCHMARKS AND OPTIONS_BENCH)
add_executable(${TARGET}_bench "${CMAKE_CURRENT_SOURCE_DIR}/bench/${TARGET}.cpp")
target_link_libraries(${TARGET}_bench PUBLIC ${SOURCEPP_BENCH_NAME} sourcepp::${TARGET})
include("${CMAKE_CURRENT_SOURCE_DIR}/bench/${TARGET}.cmake")
Expand Down
6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Several modern C++20 libraries for sanely parsing Valve formats, rolled into one
<td>Get Source engine instance window title/position/size</td>
<td align="center">✅</td>
<td align="center">❌</td>
<td rowspan="2" align="center"></td>
<td rowspan="2" align="center">Python</td>
</tr>
<tr>
<td>Run commands in a Source engine instance remotely</td>
Expand Down Expand Up @@ -76,7 +76,7 @@ Several modern C++20 libraries for sanely parsing Valve formats, rolled into one
<td>Find Steam install folder</td>
<td align="center">✅</td>
<td align="center">-</td>
<td rowspan="2" align="center">C</td>
<td rowspan="2" align="center">C<br>Python</td>
</tr>
<tr>
<td>Find installed Steam games</td>
Expand Down Expand Up @@ -107,7 +107,7 @@ Several modern C++20 libraries for sanely parsing Valve formats, rolled into one
<td><a href="https://developer.valvesoftware.com/wiki/VICE">VICE</a> encrypted files</td>
<td align="center">✅</td>
<td align="center">✅</td>
<td rowspan="2" align="center">C<br>C#</td>
<td rowspan="2" align="center">C<br>C#<br>Python</td>
</tr>
<tr>
<td><a href="https://developer.valvesoftware.com/wiki/Vfont">VFONT</a> encrypted fonts</td>
Expand Down
2 changes: 1 addition & 1 deletion ext/bufferstream
2 changes: 1 addition & 1 deletion ext/miniz
Submodule miniz updated 4 files
+31 −23 CMakeLists.txt
+5 −4 miniz_zip.c
+2 −1 miniz_zip.h
+31 −1 tests/main.cpp
114 changes: 1 addition & 113 deletions include/sourcepp/math/Integer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,122 +15,10 @@ using std::uint16_t;
using std::uint32_t;
using std::uint64_t;

/// 3-byte wide unsigned integer
struct uint24_t {
uint24_t() = default;

template<std::integral T>
constexpr uint24_t(T value) // NOLINT(*-explicit-constructor)
: bytes{
static_cast<uint8_t>((value >> 16) & 0xff),
static_cast<uint8_t>((value >> 8) & 0xff),
static_cast<uint8_t>( value & 0xff),
} {}

template<std::integral T>
[[nodiscard]] constexpr operator T() const { // NOLINT(*-explicit-constructor)
return static_cast<T>((bytes[0] << 16) | (bytes[1] << 8) | bytes[2]);
}

template<std::integral T>
constexpr uint24_t& operator=(T value) {
*this = {value};
return *this;
}

template<std::integral T>
[[nodiscard]] constexpr uint24_t operator+(T value) const {
return {uint32_t{*this} + value};
}

template<std::integral T>
constexpr void operator+=(T value) const {
*this = {uint32_t{*this} + value};
}

constexpr uint24_t operator++() {
return *this = {uint32_t{*this} + 1};
}

constexpr uint24_t operator++(int) {
uint24_t out{*this};
*this = {uint32_t{*this} + 1};
return out;
}

template<std::integral T>
[[nodiscard]] constexpr uint24_t operator-(T value) const {
return {uint32_t{*this} - value};
}

template<std::integral T>
constexpr void operator-=(T value) const {
return *this = {uint32_t{*this} - value};
}

constexpr uint24_t operator--() {
return *this = {uint32_t{*this} - 1};
}

constexpr uint24_t operator--(int) {
uint24_t out{*this};
*this = {uint32_t{*this} - 1};
return out;
}

template<std::integral T>
[[nodiscard]] constexpr uint24_t operator*(T value) const {
return {uint32_t{*this} * value};
}

template<std::integral T>
constexpr void operator*=(T value) const {
*this = {uint32_t{*this} * value};
}

template<std::integral T>
[[nodiscard]] constexpr uint24_t operator/(T value) const {
return {uint32_t{*this} / value};
}

template<std::integral T>
constexpr void operator/=(T value) const {
*this = {uint32_t{*this} / value};
}

template<std::integral T>
[[nodiscard]] constexpr uint24_t operator%(T value) const {
return {uint32_t{*this} % value};
}

template<std::integral T>
constexpr void operator%=(T value) const {
*this = {uint32_t{*this} % value};
}

template<std::integral T>
[[nodiscard]] constexpr bool operator==(T value) const {
return uint32_t{*this} == value;
}

template<std::integral T>
[[nodiscard]] constexpr auto operator<=>(T value) const {
return uint32_t{*this} <=> value;
}

[[nodiscard]] constexpr operator bool() const { // NOLINT(*-explicit-constructor)
return static_cast<bool>(uint32_t{*this});
}

uint8_t bytes[3];
};
static_assert(sizeof(uint24_t) == 3, "uint24_t is not 3 bytes wide!");
static_assert(std::is_trivially_copyable_v<uint24_t>, "uint24_t is not a POD type!");

namespace sourcepp::math {

template<typename T>
concept Arithmetic = std::is_arithmetic_v<T> || std::same_as<T, uint24_t>;
concept Arithmetic = std::is_arithmetic_v<T>;

template<Arithmetic T>
[[nodiscard]] constexpr T remap(T value, T l1, T h1, T l2, T h2) {
Expand Down
5 changes: 1 addition & 4 deletions include/sourcepp/math/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct Vec {

using value_type = P;

[[nodiscard]] consteval uint8_t size() const {
[[nodiscard]] constexpr uint8_t size() const {
return S;
}

Expand Down Expand Up @@ -252,7 +252,6 @@ using Vec2i = Vec2i32;

using Vec2ui8 = Vec2<uint8_t>;
using Vec2ui16 = Vec2<uint16_t>;
using Vec2ui24 = Vec2<uint24_t>;
using Vec2ui32 = Vec2<uint32_t>;
using Vec2ui64 = Vec2<uint64_t>;
using Vec2ui = Vec2ui32;
Expand All @@ -272,7 +271,6 @@ using Vec3i = Vec3i32;

using Vec3ui8 = Vec3<uint8_t>;
using Vec3ui16 = Vec3<uint16_t>;
using Vec3ui24 = Vec3<uint24_t>;
using Vec3ui32 = Vec3<uint32_t>;
using Vec3ui64 = Vec3<uint64_t>;
using Vec3ui = Vec3ui32;
Expand All @@ -292,7 +290,6 @@ using Vec4i = Vec4i32;

using Vec4ui8 = Vec4<uint8_t>;
using Vec4ui16 = Vec4<uint16_t>;
using Vec4ui24 = Vec4<uint24_t>;
using Vec4ui32 = Vec4<uint32_t>;
using Vec4ui64 = Vec4<uint64_t>;
using Vec4ui = Vec4ui32;
Expand Down
4 changes: 4 additions & 0 deletions lang/python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Build Files
__pycache__/
dist/sourcepp/*
!dist/sourcepp/__init__.py
5 changes: 5 additions & 0 deletions lang/python/dist/sourcepp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from __future__ import annotations

from ._sourcepp_python import __author__, __doc__, __version__, gamepp, sourcepp, steampp, vcryptpp

__all__ = ['__author__', '__doc__', '__version__', 'gamepp', 'sourcepp', 'steampp', 'vcryptpp']
Loading