add version features

This commit is contained in:
Syping 2021-11-03 10:54:35 +01:00
parent 1be4ae5e4a
commit 2fcc5b0ba7
4 changed files with 48 additions and 6 deletions

View file

@ -17,7 +17,7 @@
****************************************************************************]]
cmake_minimum_required(VERSION 3.7)
project(ragephoto VERSION 0.1 LANGUAGES CXX)
project(ragephoto VERSION 0.1.0 LANGUAGES CXX)
include(GNUInstallDirs)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
@ -25,7 +25,7 @@ set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
message("-- Testing codecvt")
try_run(CODECVT_RUN CODECVT_COMPILE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/tests/CodecvtTest.cpp)
try_run(CODECVT_RUN CODECVT_COMPILE ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/tests/CodecvtTest.cpp)
if (CODECVT_COMPILE AND CODECVT_RUN EQUAL 0)
list(APPEND LIBRAGEPHOTO_DEFINES
CODECVT_COMPATIBLE
@ -36,7 +36,7 @@ else()
endif()
message("-- Testing iconv")
try_run(ICONV_RUN ICONV_COMPILE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/tests/IconvTest.cpp)
try_run(ICONV_RUN ICONV_COMPILE ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/tests/IconvTest.cpp)
if (ICONV_COMPILE AND ICONV_RUN EQUAL 0)
list(APPEND LIBRAGEPHOTO_DEFINES
ICONV_COMPATIBLE
@ -81,7 +81,7 @@ endif()
configure_file(src/libragephoto_global.h.in include/libragephoto_global.h @ONLY)
list(APPEND RAGEPHOTO_HEADERS
${CMAKE_CURRENT_BINARY_DIR}/include/libragephoto_global.h
${PROJECT_BINARY_DIR}/include/libragephoto_global.h
)
configure_file(src/ragephoto.pc.in pkgconfig/ragephoto.pc @ONLY)
target_compile_definitions(ragephoto PRIVATE
@ -89,11 +89,11 @@ target_compile_definitions(ragephoto PRIVATE
${LIBRAGEPHOTO_DEFINES}
)
target_include_directories(ragephoto PUBLIC
${CMAKE_CURRENT_BINARY_DIR}/include
${PROJECT_BINARY_DIR}/include
)
install(TARGETS ragephoto DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${RAGEPHOTO_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/RagePhoto)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/ragephoto.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(FILES ${PROJECT_BINARY_DIR}/pkgconfig/ragephoto.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
option(WITH_DOCUMENTATION "Build libragephoto with documentation" OFF)
if (WITH_DOCUMENTATION)

View file

@ -457,6 +457,11 @@ const std::string& RagePhoto::title() const
return m_data.title;
}
const char* RagePhoto::version()
{
return RAGEPHOTO_VERSION;
}
bool RagePhoto::save(char *data, uint32_t photoFormat)
{
if (photoFormat == PhotoFormat::GTA5 || photoFormat == PhotoFormat::RDR2) {
@ -916,6 +921,12 @@ int ragephoto_load(ragephoto_t instance, const char *data, size_t size)
return ragePhoto->load(data, size);
}
int ragephoto_loadfile(ragephoto_t instance, const char *filename)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->loadFile(filename);
}
uint8_t ragephoto_error(ragephoto_t instance)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
@ -996,6 +1007,12 @@ int ragephoto_save(ragephoto_t instance, char *data)
return ragePhoto->save(data);
}
int ragephoto_savefile(ragephoto_t instance, const char *filename)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
return ragePhoto->saveFile(filename);
}
void ragephoto_setbufferdefault(ragephoto_t instance)
{
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
@ -1049,4 +1066,9 @@ void ragephoto_close(ragephoto_t instance)
RagePhoto *ragePhoto = static_cast<RagePhoto*>(instance);
delete ragePhoto;
}
const char* ragephoto_version()
{
return RAGEPHOTO_VERSION;
}
#endif

View file

@ -116,6 +116,7 @@ public:
const std::string& json() const; /**< Returns the Photo JSON data. */
const std::string& header() const; /**< Returns the Photo header. */
const std::string& title() const; /**< Returns the Photo title. */
static const char* version(); /**< Returns the library version. */
/** Saves a Photo to a char*.
* \param data Photo data
* \param photoFormat Photo Format (GTA V or RDR 2)
@ -196,6 +197,12 @@ LIBRAGEPHOTO_EXPORT ragephoto_t ragephoto_open();
*/
LIBRAGEPHOTO_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);
/** Returns the last error occurred.
* \param instance \p ragephoto_t instance
*/
@ -259,6 +266,12 @@ LIBRAGEPHOTO_EXPORT size_t ragephoto_getsavesize(ragephoto_t instance);
*/
LIBRAGEPHOTO_EXPORT int ragephoto_save(ragephoto_t instance, char *data);
/** 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);
/** Sets all cross-format Buffer to default size.
* \param instance \p ragephoto_t instance
*/
@ -312,6 +325,9 @@ LIBRAGEPHOTO_EXPORT void ragephoto_setphototitle(ragephoto_t instance, const cha
*/
LIBRAGEPHOTO_EXPORT void ragephoto_close(ragephoto_t instance);
/** Returns the library version. */
LIBRAGEPHOTO_EXPORT const char* ragephoto_version();
#ifdef __cplusplus
}
#endif

View file

@ -22,6 +22,10 @@
/* CMAKE CONFIG BEGIN */
#define @LIBRAGEPHOTO_API@
#define @LIBRAGEPHOTO_LIBTYPE@
#define RAGEPHOTO_VERSION "@PROJECT_VERSION@"
#define RAGEPHOTO_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
#define RAGEPHOTO_VERSION_MINOR @PROJECT_VERSION_MINOR@
#define RAGEPHOTO_VERSION_PATCH @PROJECT_VERSION_PATCH@
/* CMAKE CONFIG END */
/* RAGEPHOTO LIBRARY EXPORT BEGIN */