Browse Source

WebAssembly CMake support and other changes

RagePhoto-Extract: removed unnecessary includes
Windows RagePhoto-Extract: included Windows resource file

RagePhotoA: include iostream to fix undefined std::

RagePhoto: seperate C and CXX exports to export only C functions with
WebAssembly
Windows RagePhoto: changed Windows resource file language to 0x0

Doxyfile: change PROJECT_VERSION variable to ragephoto_VERSION variable
master
Syping 2 weeks ago
parent
commit
c6566c8f17
  1. 60
      CMakeLists.txt
  2. 2
      doc/Doxyfile.in
  3. 2
      src/RagePhoto-Extract.c
  4. 1
      src/RagePhoto-Extract.cpp
  5. 2
      src/RagePhoto.h
  6. 1
      src/RagePhotoA.h
  7. 64
      src/RagePhotoC.h
  8. 2
      src/RagePhotoData.h
  9. 18
      src/libragephoto_global.h.in
  10. 29
      src/ragephoto-extract.rc.in
  11. 4
      src/ragephoto.rc.in

60
CMakeLists.txt

@ -37,12 +37,20 @@ set(RAGEPHOTO_SOURCES
)
# RagePhoto Library Type
option(BUILD_SHARED "Build libragephoto as shared library" ON)
if (EMSCRIPTEN)
option(BUILD_SHARED "Build libragephoto as shared library" OFF)
else()
option(BUILD_SHARED "Build libragephoto as shared library" ON)
endif()
if (BUILD_SHARED)
option(WITH_C_API "Build libragephoto with C API support" ON)
set(LIBRAGEPHOTO_LIBTYPE LIBRAGEPHOTO_SHARED)
else()
option(WITH_C_API "Build libragephoto with C API support" OFF)
if (EMSCRIPTEN)
option(WITH_C_API "Build libragephoto with C API support" ON)
else()
option(WITH_C_API "Build libragephoto with C API support" OFF)
endif()
set(LIBRAGEPHOTO_LIBTYPE LIBRAGEPHOTO_STATIC)
endif()
@ -93,12 +101,40 @@ target_compile_definitions(ragephoto PRIVATE
${LIBRAGEPHOTO_DEFINES}
)
target_include_directories(ragephoto PUBLIC
${PROJECT_BINARY_DIR}/include
${PROJECT_SOURCE_DIR}/src
${ragephoto_BINARY_DIR}/include
${ragephoto_SOURCE_DIR}/src
)
install(TARGETS ragephoto DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${RAGEPHOTO_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/RagePhoto)
install(FILES ${PROJECT_BINARY_DIR}/pkgconfig/ragephoto.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(FILES ${ragephoto_BINARY_DIR}/pkgconfig/ragephoto.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
# RagePhoto WebAssembly Target
if (EMSCRIPTEN)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13.0")
add_executable(ragephoto-wasm ${RAGEPHOTO_HEADERS} ${RAGEPHOTO_SOURCES})
set_target_properties(ragephoto-wasm PROPERTIES
PREFIX "lib"
OUTPUT_NAME "ragephoto"
)
target_compile_definitions(ragephoto-wasm PRIVATE
LIBRAGEPHOTO_LIBRARY
${LIBRAGEPHOTO_DEFINES}
)
target_link_options(ragephoto-wasm PRIVATE
"SHELL:-O2"
"SHELL:--no-entry"
"SHELL:-s WASM=1"
"SHELL:-s EXPORTED_FUNCTIONS=_free"
"SHELL:-s EXPORTED_RUNTIME_METHODS=ccall,cwrap"
)
target_include_directories(ragephoto-wasm PUBLIC
${ragephoto_BINARY_DIR}/include
${ragephoto_SOURCE_DIR}/src
)
else()
message(WARNING "A useable WebAssembly build needs at least CMake 3.13.0 or newer")
endif()
endif()
# RagePhoto Documentation
option(WITH_DOCUMENTATION "Build libragephoto with documentation" OFF)
@ -124,15 +160,25 @@ else()
option(WITH_EXTRACT "Build libragephoto with ragephoto-extract" OFF)
endif()
if (WITH_EXTRACT)
# RagePhoto-Extract Source files
if (WITH_C_API)
enable_language(C)
set(EXTRACT_SOURCES src/RagePhoto-Extract.c)
else()
set(EXTRACT_SOURCES src/RagePhoto-Extract.cpp)
endif()
add_executable(ragephoto-extract ${RAGEPHOTO_HEADERS} ${EXTRACT_SOURCES})
# RagePhoto-Extract Win32 Shared Resources
if (WIN32)
string(TIMESTAMP ragephoto_BUILD_YEAR "%Y" UTC)
configure_file(src/ragephoto-extract.rc.in resources/ragephoto-extract.rc @ONLY)
list(APPEND EXTRACT_RESOURCES
${ragephoto_BINARY_DIR}/resources/ragephoto-extract.rc
)
endif()
# RagePhoto-Extract Target + Installs
add_executable(ragephoto-extract ${RAGEPHOTO_HEADERS} ${EXTRACT_SOURCES} ${EXTRACT_RESOURCES})
set_target_properties(ragephoto-extract PROPERTIES
INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
)
target_link_libraries(ragephoto-extract PRIVATE ragephoto)
install(TARGETS ragephoto-extract DESTINATION ${CMAKE_INSTALL_BINDIR})

2
doc/Doxyfile.in

@ -1,5 +1,5 @@
PROJECT_NAME = "libragephoto"
PROJECT_NUMBER = "Version: @PROJECT[email protected]"
PROJECT_NUMBER = "Version: @ragephoto[email protected]"
INPUT = "@[email protected]/index.doc" \
"src"
OUTPUT_DIRECTORY = "@[email protected]"

2
src/RagePhoto-Extract.c

@ -17,8 +17,6 @@
*****************************************************************************/
#include "RagePhotoC.h"
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{

1
src/RagePhoto-Extract.cpp

@ -18,7 +18,6 @@
#include "RagePhoto.h"
#include <fstream>
#include <iostream>
int main(int argc, char *argv[])
{

2
src/RagePhoto.h

@ -33,7 +33,7 @@ typedef std::function<bool(const char*, size_t, RagePhotoData*)> RagePhotoLoadFu
/**
* \brief GTA V and RDR 2 Photo Parser.
*/
class LIBRAGEPHOTO_EXPORT RagePhoto
class LIBRAGEPHOTO_CXX_EXPORT RagePhoto
{
public:
/** Default sizes */

1
src/RagePhotoA.h

@ -21,6 +21,7 @@
#ifdef __cplusplus
#include "RagePhotoC.h"
#include <iostream>
/**
* \brief ABI Stable Wrapper for RagePhoto.

64
src/RagePhotoC.h

@ -35,124 +35,124 @@ extern "C" {
typedef void* ragephoto_t;
/** Opens a \p ragephoto_t instance. */
LIBRAGEPHOTO_EXPORT ragephoto_t ragephoto_open();
LIBRAGEPHOTO_C_EXPORT ragephoto_t ragephoto_open();
/** Resets the \p ragephoto_t instance to default values.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_EXPORT void ragephoto_clear(ragephoto_t instance);
LIBRAGEPHOTO_C_EXPORT void ragephoto_clear(ragephoto_t instance);
/** Loads a Photo from a const char*.
* \param instance \p ragephoto_t instance
* \param data Photo data
* \param size Photo data size
*/
LIBRAGEPHOTO_EXPORT int ragephoto_load(ragephoto_t instance, const char *data, size_t size);
LIBRAGEPHOTO_C_EXPORT int ragephoto_load(ragephoto_t instance, const char *data, size_t size);
/** Loads a Photo from a file.
* \param instance \p ragephoto_t instance
* \param filename File to load
*/
LIBRAGEPHOTO_EXPORT int ragephoto_loadfile(ragephoto_t instance, const char *filename);
LIBRAGEPHOTO_C_EXPORT int ragephoto_loadfile(ragephoto_t instance, const char *filename);
/** Returns the last error occurred.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_EXPORT uint8_t ragephoto_error(ragephoto_t instance);
LIBRAGEPHOTO_C_EXPORT uint8_t ragephoto_error(ragephoto_t instance);
/** Returns the GTA V default Photo Buffer Size. */
LIBRAGEPHOTO_EXPORT uint32_t ragephoto_defpbuf_gta5();
LIBRAGEPHOTO_C_EXPORT uint32_t ragephoto_defpbuf_gta5();
/** Returns the RDR 2 default Photo Buffer Size. */
LIBRAGEPHOTO_EXPORT uint32_t ragephoto_defpbuf_rdr2();
LIBRAGEPHOTO_C_EXPORT uint32_t ragephoto_defpbuf_rdr2();
/** Returns the GTA V Photo Format. */
LIBRAGEPHOTO_EXPORT uint32_t ragephoto_format_gta5();
LIBRAGEPHOTO_C_EXPORT uint32_t ragephoto_format_gta5();
/** Returns the RDR 2 Photo Format. */
LIBRAGEPHOTO_EXPORT uint32_t ragephoto_format_rdr2();
LIBRAGEPHOTO_C_EXPORT uint32_t ragephoto_format_rdr2();
/** Returns the Photo description.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_EXPORT const char* ragephoto_getphotodesc(ragephoto_t instance);
LIBRAGEPHOTO_C_EXPORT const char* ragephoto_getphotodesc(ragephoto_t instance);
/** Returns the Photo Format (GTA V or RDR 2).
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_EXPORT uint32_t ragephoto_getphotoformat(ragephoto_t instance);
LIBRAGEPHOTO_C_EXPORT uint32_t ragephoto_getphotoformat(ragephoto_t instance);
/** Returns the Photo JPEG data.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_EXPORT const char* ragephoto_getphotojpeg(ragephoto_t instance);
LIBRAGEPHOTO_C_EXPORT const char* ragephoto_getphotojpeg(ragephoto_t instance);
/** Returns the Photo JSON data.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_EXPORT const char* ragephoto_getphotojson(ragephoto_t instance);
LIBRAGEPHOTO_C_EXPORT const char* ragephoto_getphotojson(ragephoto_t instance);
/** Returns the Photo header.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_EXPORT const char* ragephoto_getphotoheader(ragephoto_t instance);
LIBRAGEPHOTO_C_EXPORT const char* ragephoto_getphotoheader(ragephoto_t instance);
/** Returns the Photo JPEG data size.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_EXPORT uint32_t ragephoto_getphotosize(ragephoto_t instance);
LIBRAGEPHOTO_C_EXPORT uint32_t ragephoto_getphotosize(ragephoto_t instance);
/** Returns the Photo title.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_EXPORT const char* ragephoto_getphototitle(ragephoto_t instance);
LIBRAGEPHOTO_C_EXPORT const char* ragephoto_getphototitle(ragephoto_t instance);
/** Returns the Photo save file size.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_EXPORT size_t ragephoto_getsavesize(ragephoto_t instance);
LIBRAGEPHOTO_C_EXPORT size_t ragephoto_getsavesize(ragephoto_t instance);
/** Returns the Photo save file size.
* \param instance \p ragephoto_t instance
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_EXPORT size_t ragephoto_getsavesizef(ragephoto_t instance, uint32_t photoFormat);
LIBRAGEPHOTO_C_EXPORT size_t ragephoto_getsavesizef(ragephoto_t instance, uint32_t photoFormat);
/** Saves a Photo to a char*.
* \param instance \p ragephoto_t instance
* \param data Photo data
*/
LIBRAGEPHOTO_EXPORT int ragephoto_save(ragephoto_t instance, char *data);
LIBRAGEPHOTO_C_EXPORT int ragephoto_save(ragephoto_t instance, char *data);
/** Saves a Photo to a char*.
* \param instance \p ragephoto_t instance
* \param data Photo data
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_EXPORT int ragephoto_savef(ragephoto_t instance, char *data, uint32_t photoFormat);
LIBRAGEPHOTO_C_EXPORT int ragephoto_savef(ragephoto_t instance, char *data, uint32_t photoFormat);
/** Saves a Photo to a file.
* \param instance \p ragephoto_t instance
* \param filename File to save
*/
LIBRAGEPHOTO_EXPORT int ragephoto_savefile(ragephoto_t instance, const char *filename);
LIBRAGEPHOTO_C_EXPORT int ragephoto_savefile(ragephoto_t instance, const char *filename);
/** Saves a Photo to a file.
* \param instance \p ragephoto_t instance
* \param filename File to save
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_EXPORT int ragephoto_savefilef(ragephoto_t instance, const char *filename, uint32_t photoFormat);
LIBRAGEPHOTO_C_EXPORT int ragephoto_savefilef(ragephoto_t instance, const char *filename, uint32_t photoFormat);
/** Sets all cross-format Buffer to default size.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_EXPORT void ragephoto_setbufferdefault(ragephoto_t instance);
LIBRAGEPHOTO_C_EXPORT void ragephoto_setbufferdefault(ragephoto_t instance);
/** Moves all Buffer offsets to correct position.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_EXPORT void ragephoto_setbufferoffsets(ragephoto_t instance);
LIBRAGEPHOTO_C_EXPORT void ragephoto_setbufferoffsets(ragephoto_t instance);
/** Sets the Photo description.
* \param instance \p ragephoto_t instance
@ -161,13 +161,13 @@ LIBRAGEPHOTO_EXPORT void ragephoto_setbufferoffsets(ragephoto_t instance);
*
* Default bufferSize: 256UL
*/
LIBRAGEPHOTO_EXPORT void ragephoto_setphotodesc(ragephoto_t instance, const char *description, uint32_t bufferSize);
LIBRAGEPHOTO_C_EXPORT void ragephoto_setphotodesc(ragephoto_t instance, const char *description, uint32_t bufferSize);
/** Sets the Photo Format (GTA V or RDR 2).
* \param instance \p ragephoto_t instance
* \param photoFormat Photo Format (GTA V or RDR 2)
*/
LIBRAGEPHOTO_EXPORT void ragephoto_setphotoformat(ragephoto_t instance, uint32_t photoFormat);
LIBRAGEPHOTO_C_EXPORT void ragephoto_setphotoformat(ragephoto_t instance, uint32_t photoFormat);
/** Sets the Photo JPEG data.
* \param instance \p ragephoto_t instance
@ -177,7 +177,7 @@ LIBRAGEPHOTO_EXPORT void ragephoto_setphotoformat(ragephoto_t instance, uint32_t
*
* Default bufferSize: ragephoto_defpbuf_gta5() or ragephoto_defpbuf_rdr2()
*/
LIBRAGEPHOTO_EXPORT int ragephoto_setphotojpeg(ragephoto_t instance, const char *data, uint32_t size, uint32_t bufferSize);
LIBRAGEPHOTO_C_EXPORT int ragephoto_setphotojpeg(ragephoto_t instance, const char *data, uint32_t size, uint32_t bufferSize);
/** Sets the Photo JSON data.
* \param instance \p ragephoto_t instance
@ -186,10 +186,10 @@ LIBRAGEPHOTO_EXPORT int ragephoto_setphotojpeg(ragephoto_t instance, const char
*
* Default bufferSize: 3072UL
*/
LIBRAGEPHOTO_EXPORT void ragephoto_setphotojson(ragephoto_t instance, const char *json, uint32_t bufferSize);
LIBRAGEPHOTO_C_EXPORT void ragephoto_setphotojson(ragephoto_t instance, const char *json, uint32_t bufferSize);
/** Sets the Photo header. (EXPERT ONLY) */
LIBRAGEPHOTO_EXPORT void ragephoto_setphotoheader(ragephoto_t instance, const char *header, uint32_t headerSum);
LIBRAGEPHOTO_C_EXPORT void ragephoto_setphotoheader(ragephoto_t instance, const char *header, uint32_t headerSum);
/** Sets the Photo title.
* \param instance \p ragephoto_t instance
@ -198,15 +198,15 @@ LIBRAGEPHOTO_EXPORT void ragephoto_setphotoheader(ragephoto_t instance, const ch
*
* Default bufferSize: 256UL
*/
LIBRAGEPHOTO_EXPORT void ragephoto_setphototitle(ragephoto_t instance, const char *title, uint32_t bufferSize);
LIBRAGEPHOTO_C_EXPORT void ragephoto_setphototitle(ragephoto_t instance, const char *title, uint32_t bufferSize);
/** Closes a \p ragephoto_t instance.
* \param instance \p ragephoto_t instance
*/
LIBRAGEPHOTO_EXPORT void ragephoto_close(ragephoto_t instance);
LIBRAGEPHOTO_C_EXPORT void ragephoto_close(ragephoto_t instance);
/** Returns the library version. */
LIBRAGEPHOTO_EXPORT const char* ragephoto_version();
LIBRAGEPHOTO_C_EXPORT const char* ragephoto_version();
#ifdef __cplusplus
}

2
src/RagePhotoData.h

@ -24,7 +24,7 @@
#include <iostream>
#include <cstdint>
struct LIBRAGEPHOTO_EXPORT RagePhotoData
struct LIBRAGEPHOTO_CXX_EXPORT RagePhotoData
{
bool photoLoaded;
char* photoData;

18
src/libragephoto_global.h.in

@ -32,15 +32,25 @@
#ifdef _WIN32
#ifndef LIBRAGEPHOTO_STATIC
#ifdef LIBRAGEPHOTO_LIBRARY
#define LIBRAGEPHOTO_EXPORT __declspec(dllexport)
#define LIBRAGEPHOTO_C_EXPORT __declspec(dllexport)
#define LIBRAGEPHOTO_CXX_EXPORT __declspec(dllexport)
#else
#define LIBRAGEPHOTO_EXPORT __declspec(dllimport)
#define LIBRAGEPHOTO_C_EXPORT __declspec(dllimport)
#define LIBRAGEPHOTO_CXX_EXPORT __declspec(dllimport)
#endif // LIBRAGEPHOTO_LIBRARY
#else
#define LIBRAGEPHOTO_EXPORT
#define LIBRAGEPHOTO_C_EXPORT
#define LIBRAGEPHOTO_CXX_EXPORT
#endif // LIBRAGEPHOTO_STATIC
#else
#define LIBRAGEPHOTO_EXPORT
#ifdef __EMSCRIPTEN__
#include <emscripten/emscripten.h>
#define LIBRAGEPHOTO_C_EXPORT EMSCRIPTEN_KEEPALIVE
#define LIBRAGEPHOTO_CXX_EXPORT
#else
#define LIBRAGEPHOTO_C_EXPORT
#define LIBRAGEPHOTO_CXX_EXPORT
#endif // __EMSCRIPTEN__
#endif // _WIN32
/* RAGEPHOTO LIBRARY EXPORT END */

29
src/ragephoto-extract.rc.in

@ -0,0 +1,29 @@
#include <windows.h>
VS_VERSION_INFO VERSIONINFO
FILEVERSION @[email protected], @[email protected], @[email protected], 0
PRODUCTVERSION @[email protected], @[email protected], @[email protected], 0
FILEFLAGSMASK 0x3fL
FILEFLAGS 0
FILEOS VOS_NT_WINDOWS32
FILETYPE VFT_APP
FILESUBTYPE VFT2_UNKNOWN
BEGIN
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0809, 1200
END
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "Syping"
VALUE "FileDescription", "RAGE Photo Extract Tool for GTA V and RDR 2"
VALUE "FileVersion", "@[email protected]"
VALUE "InternalName", "ragephoto-extract"
VALUE "LegalCopyright", "Copyright © @[email protected] Syping"
VALUE "OriginalFilename", "ragephoto-extract.exe"
VALUE "ProductName", "ragephoto-extract"
VALUE "ProductVersion", "@[email protected]"
END
END
END

4
src/ragephoto.rc.in

@ -10,14 +10,14 @@ FILESUBTYPE VFT2_UNKNOWN
BEGIN
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0809, 1200
VALUE "Translation", 0x0, 1200
END
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", "Syping"
VALUE "FileDescription", "Open Source RAGE Photo Parser for GTA V and RDR 2"
VALUE "FileDescription", "RAGE Photo Parser for GTA V and RDR 2"
VALUE "FileVersion", "@[email protected]"
VALUE "InternalName", "libragephoto"
VALUE "LegalCopyright", "Copyright © @[email protected] Syping"

Loading…
Cancel
Save