libragephoto: introduce C library port

CMakeLists.txt: fixes for MSVC and C library support
RagePhoto: non C++11 support
RagePhotoC: clarify C instance support in comment
RagePhotoTypedefs: add typedefs for C library
This commit is contained in:
Syping 2023-06-06 19:39:22 +02:00
parent af3580dff4
commit 3046cbd077
5 changed files with 1261 additions and 16 deletions

View File

@ -17,7 +17,7 @@
****************************************************************************]] ****************************************************************************]]
cmake_minimum_required(VERSION 3.8) cmake_minimum_required(VERSION 3.8)
project(ragephoto VERSION 0.4.1 LANGUAGES CXX) project(ragephoto VERSION 0.5.0 LANGUAGES C CXX)
include(GNUInstallDirs) include(GNUInstallDirs)
# RagePhoto CMake includes # RagePhoto CMake includes
@ -32,14 +32,26 @@ else()
endif() endif()
# RagePhoto Source files # RagePhoto Source files
set(RAGEPHOTO_HEADERS option(RAGEPHOTO_C_LIBRARY "Build libragephoto as C library" OFF)
src/RagePhoto.h if (RAGEPHOTO_C_LIBRARY)
src/RagePhotoLibrary.h set(RAGEPHOTO_HEADERS
src/RagePhotoTypedefs.h src/RagePhotoC.h
) src/RagePhotoLibrary.h
set(RAGEPHOTO_SOURCES src/RagePhotoTypedefs.h
src/RagePhoto.cpp )
) set(RAGEPHOTO_SOURCES
src/RagePhoto.c
)
else()
set(RAGEPHOTO_HEADERS
src/RagePhoto.h
src/RagePhotoLibrary.h
src/RagePhotoTypedefs.h
)
set(RAGEPHOTO_SOURCES
src/RagePhoto.cpp
)
endif()
# RagePhoto Library Type # RagePhoto Library Type
option(RAGEPHOTO_STATIC "Build libragephoto as static library" OFF) option(RAGEPHOTO_STATIC "Build libragephoto as static library" OFF)
@ -60,14 +72,21 @@ if (RAGEPHOTO_BENCHMARK)
endif() endif()
# RagePhoto C API # RagePhoto C API
if (RAGEPHOTO_C_API) if (RAGEPHOTO_C_LIBRARY)
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_API) set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_API)
list(APPEND RAGEPHOTO_HEADERS list(APPEND RAGEPHOTO_HEADERS
src/RagePhotoA.h src/RagePhotoA.h
src/RagePhotoC.h
) )
else() else()
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_NOAPI) if (RAGEPHOTO_C_API)
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_API)
list(APPEND RAGEPHOTO_HEADERS
src/RagePhotoA.h
src/RagePhotoC.h
)
else()
set(LIBRAGEPHOTO_API LIBRAGEPHOTO_C_NOAPI)
endif()
endif() endif()
# RagePhoto Win32 Shared Resources # RagePhoto Win32 Shared Resources
@ -99,7 +118,7 @@ target_compile_definitions(ragephoto PRIVATE
LIBRAGEPHOTO_LIBRARY LIBRAGEPHOTO_LIBRARY
${LIBRAGEPHOTO_DEFINES} ${LIBRAGEPHOTO_DEFINES}
) )
if (MSVC) if (MSVC AND MSVC_VERSION GREATER_EQUAL 1914 AND NOT RAGEPHOTO_C_LIBRARY)
target_compile_options(ragephoto PRIVATE "/Zc:__cplusplus") target_compile_options(ragephoto PRIVATE "/Zc:__cplusplus")
endif() endif()
target_include_directories(ragephoto PUBLIC target_include_directories(ragephoto PUBLIC
@ -143,7 +162,6 @@ option(RAGEPHOTO_EXTRACT "Build libragephoto with ragephoto-extract" ${RPTL_ON})
if (RAGEPHOTO_EXTRACT) if (RAGEPHOTO_EXTRACT)
# RagePhoto-Extract Source files # RagePhoto-Extract Source files
if (RAGEPHOTO_C_API) if (RAGEPHOTO_C_API)
enable_language(C)
set(EXTRACT_SOURCES src/RagePhoto-Extract.c) set(EXTRACT_SOURCES src/RagePhoto-Extract.c)
else() else()
set(EXTRACT_SOURCES src/RagePhoto-Extract.cpp) set(EXTRACT_SOURCES src/RagePhoto-Extract.cpp)
@ -161,7 +179,7 @@ if (RAGEPHOTO_EXTRACT)
set_target_properties(ragephoto-extract PROPERTIES set_target_properties(ragephoto-extract PROPERTIES
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
) )
if (MSVC AND NOT RAGEPHOTO_C_API) if (MSVC AND MSVC_VERSION GREATER_EQUAL 1914 AND NOT RAGEPHOTO_C_API)
target_compile_options(ragephoto-extract PRIVATE "/Zc:__cplusplus") target_compile_options(ragephoto-extract PRIVATE "/Zc:__cplusplus")
endif() endif()
target_link_libraries(ragephoto-extract PRIVATE ragephoto) target_link_libraries(ragephoto-extract PRIVATE ragephoto)

1213
src/RagePhoto.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -970,7 +970,11 @@ bool RagePhoto::saveFile(const std::string &filename, uint32_t photoFormat)
m_data->error = Error::Uninitialised; // 0 m_data->error = Error::Uninitialised; // 0
return false; return false;
} }
#if (RAGEPHOTO_CXX_STD >= 11) && (__cplusplus >= 201103L)
ofs << sdata; ofs << sdata;
#else
ofs.write(sdata.data(), sdata.size());
#endif
ok = ofs.good(); ok = ofs.good();
ofs.close(); ofs.close();
return ok; return ok;

View File

@ -36,7 +36,7 @@ extern "C" {
* \file RagePhotoC.h * \file RagePhotoC.h
*/ */
/** RagePhoto C++ class typedef for C API. */ /** RagePhoto C instance/C++ class typedef. */
typedef void* ragephoto_t; typedef void* ragephoto_t;
/** Opens a \p ragephoto_t instance. */ /** Opens a \p ragephoto_t instance. */

View File

@ -70,6 +70,12 @@ typedef struct RagePhotoFormatParser {
ragephoto_saveszfunc_t funcSaveSz; /**< Pointer to saveSize function */ ragephoto_saveszfunc_t funcSaveSz; /**< Pointer to saveSize function */
} RagePhotoFormatParser; } RagePhotoFormatParser;
/** RagePhoto instance struct for storing data and format parser pointer. */
typedef struct RagePhotoInstance {
RagePhotoData *data; /**< Pointer for data */
RagePhotoFormatParser *parser; /**< Pointer for format parser */
} RagePhotoInstance;
/* RagePhoto default sizes */ /* RagePhoto default sizes */
#define RAGEPHOTO_DEFAULT_GTA5_PHOTOBUFFER 524288UL /**< GTA V default Photo Buffer Size */ #define RAGEPHOTO_DEFAULT_GTA5_PHOTOBUFFER 524288UL /**< GTA V default Photo Buffer Size */
#define RAGEPHOTO_DEFAULT_RDR2_PHOTOBUFFER 1048576UL /**< RDR 2 default Photo Buffer Size */ #define RAGEPHOTO_DEFAULT_RDR2_PHOTOBUFFER 1048576UL /**< RDR 2 default Photo Buffer Size */
@ -126,6 +132,10 @@ typedef struct RagePhotoFormatParser {
#define RAGEPHOTO_FORMAT_GTA5 0x01000000UL /**< GTA V Photo Format */ #define RAGEPHOTO_FORMAT_GTA5 0x01000000UL /**< GTA V Photo Format */
#define RAGEPHOTO_FORMAT_RDR2 0x04000000UL /**< RDR 2 Photo Format */ #define RAGEPHOTO_FORMAT_RDR2 0x04000000UL /**< RDR 2 Photo Format */
/* RagePhoto sign initials */
#define RAGEPHOTO_SIGNINITIAL_GTA5 0xE47AB81CUL /**< GTA V Sign Initial */
#define RAGEPHOTO_SIGNINITIAL_RDR2 0x00FEEB1EUL /**< RDR 2 Sign Initial */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif // __cplusplus #endif // __cplusplus