diff --git a/CMakeLists.txt b/CMakeLists.txt index d3d07ff..0c16ed9 100644 --- a/CMakeLists.txt +++ b/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}) diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in index 920c622..2090626 100644 --- a/doc/Doxyfile.in +++ b/doc/Doxyfile.in @@ -1,5 +1,5 @@ PROJECT_NAME = "libragephoto" -PROJECT_NUMBER = "Version: @PROJECT_VERSION@" +PROJECT_NUMBER = "Version: @ragephoto_VERSION@" INPUT = "@CMAKE_CURRENT_SOURCE_DIR@/index.doc" \ "src" OUTPUT_DIRECTORY = "@CMAKE_CURRENT_BINARY_DIR@" diff --git a/src/RagePhoto-Extract.c b/src/RagePhoto-Extract.c index bce46c3..9391c04 100644 --- a/src/RagePhoto-Extract.c +++ b/src/RagePhoto-Extract.c @@ -17,8 +17,6 @@ *****************************************************************************/ #include "RagePhotoC.h" -#include -#include int main(int argc, char *argv[]) { diff --git a/src/RagePhoto-Extract.cpp b/src/RagePhoto-Extract.cpp index bbb124f..7299be3 100644 --- a/src/RagePhoto-Extract.cpp +++ b/src/RagePhoto-Extract.cpp @@ -18,7 +18,6 @@ #include "RagePhoto.h" #include -#include int main(int argc, char *argv[]) { diff --git a/src/RagePhoto.h b/src/RagePhoto.h index cc49b7e..56aebef 100644 --- a/src/RagePhoto.h +++ b/src/RagePhoto.h @@ -33,7 +33,7 @@ typedef std::function RagePhotoLoadFu /** * \brief GTA V and RDR 2 Photo Parser. */ -class LIBRAGEPHOTO_EXPORT RagePhoto +class LIBRAGEPHOTO_CXX_EXPORT RagePhoto { public: /** Default sizes */ diff --git a/src/RagePhotoA.h b/src/RagePhotoA.h index e6bde1a..6553d25 100644 --- a/src/RagePhotoA.h +++ b/src/RagePhotoA.h @@ -21,6 +21,7 @@ #ifdef __cplusplus #include "RagePhotoC.h" +#include /** * \brief ABI Stable Wrapper for RagePhoto. diff --git a/src/RagePhotoC.h b/src/RagePhotoC.h index 6b6fa00..7b0afb4 100644 --- a/src/RagePhotoC.h +++ b/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 } diff --git a/src/RagePhotoData.h b/src/RagePhotoData.h index e674164..b6fdfc0 100644 --- a/src/RagePhotoData.h +++ b/src/RagePhotoData.h @@ -24,7 +24,7 @@ #include #include -struct LIBRAGEPHOTO_EXPORT RagePhotoData +struct LIBRAGEPHOTO_CXX_EXPORT RagePhotoData { bool photoLoaded; char* photoData; diff --git a/src/libragephoto_global.h.in b/src/libragephoto_global.h.in index be3b55f..bd5dc4b 100644 --- a/src/libragephoto_global.h.in +++ b/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 +#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 */ diff --git a/src/ragephoto-extract.rc.in b/src/ragephoto-extract.rc.in new file mode 100644 index 0000000..d412d76 --- /dev/null +++ b/src/ragephoto-extract.rc.in @@ -0,0 +1,29 @@ +#include +VS_VERSION_INFO VERSIONINFO +FILEVERSION @ragephoto_VERSION_MAJOR@, @ragephoto_VERSION_MINOR@, @ragephoto_VERSION_PATCH@, 0 +PRODUCTVERSION @ragephoto_VERSION_MAJOR@, @ragephoto_VERSION_MINOR@, @ragephoto_VERSION_PATCH@, 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", "@ragephoto_VERSION@" + VALUE "InternalName", "ragephoto-extract" + VALUE "LegalCopyright", "Copyright © @ragephoto_BUILD_YEAR@ Syping" + VALUE "OriginalFilename", "ragephoto-extract.exe" + VALUE "ProductName", "ragephoto-extract" + VALUE "ProductVersion", "@ragephoto_VERSION@" + END + END +END diff --git a/src/ragephoto.rc.in b/src/ragephoto.rc.in index 12ea103..f92c2db 100644 --- a/src/ragephoto.rc.in +++ b/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", "@ragephoto_VERSION@" VALUE "InternalName", "libragephoto" VALUE "LegalCopyright", "Copyright © @ragephoto_BUILD_YEAR@ Syping"