Finished standard lib implement

> static and dynamic linking... Need proper dynamic config
> Standalone app basis... Need more rework
> CMake proper install
This commit is contained in:
JackCarterSmith 2022-08-12 17:58:49 +02:00
parent 5922c3ec6a
commit e10e74b8a1
Signed by: JackCarterSmith
GPG Key ID: 832E52F4E23F8F24
16 changed files with 144 additions and 59 deletions

2
.gitignore vendored
View File

@ -15,7 +15,7 @@
# Precompiled Headers
*.gch
*.pch
src/config.h
config.h
# Libraries
*.lib

4
.gitmodules vendored
View File

@ -1,3 +1,3 @@
[submodule "RSEModel/rlk"]
path = RSEModel/rlk
[submodule "RSEModel/src/rlk"]
path = RSEModel/src/rlk
url = https://github.com/rlk/obj.git

View File

@ -18,20 +18,26 @@ endif()
# Project definition
if(DEFINED ENV{CI}) # Jenkins CI integration mode
project(rse-model VERSION $ENV{CI_VERSION}.$ENV{CI_BUILD_NUMBER} DESCRIPTION "RogueSquadron Extractor - Model" LANGUAGES C)
set(RSE_MODEL_NAME $ENV{CI_OUTPUT_NAME}_${PROJECT_VERSION})
set(RSE_MODEL_NAME $ENV{CI_OUTPUT_NAME})
else() # Standalone project mode, should not be used for release.
project(rse-model VERSION 1.0.0 DESCRIPTION "RogueSquadron Extractor - Model" LANGUAGES C)
set(RSE_MODEL_NAME RSEModel_${PROJECT_VERSION})
set(RSE_MODEL_NAME RSEModel)
endif()
set(RSP_MODEL_LIB_NAME RSPModel${PROJECT_VERSION_MAJOR}${PROJECT_VERSION_MINOR})
# Push compile infos to source
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/RSPModelLib/src/config.h @ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/RSEModel/src/config.h @ONLY)
# The project is divided in two parts:
# - RSPModelLib is the parser library for model type data, it's take HOB file as input and output extracted datas.
# It is intended to be used by others apps like rendering engine or others.
# - RSEModel is the standalone application of the library, take HOB file in argument and output OBJ/MTL file.
# Artists or users can directly use this program to retrieve data in common datas format.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
add_subdirectory(RSPModelLib)
add_subdirectory(RSEModel)
@ -48,6 +54,16 @@ add_subdirectory(RSEModel)
# Install project executable
install(TARGETS rse-model
RUNTIME DESTINATION bin
)
set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers")
install(TARGETS rse-model rsp-model-lib rsp-model-libstatic
RUNTIME DESTINATION ${INSTALL_BIN_DIR}
LIBRARY DESTINATION ${INSTALL_LIB_DIR}
ARCHIVE DESTINATION ${INSTALL_LIB_DIR}
)
# Install library includes
install(FILES ${RSP_PUBLIC_HRDS} DESTINATION ${INSTALL_INC_DIR})
# Install dependancies
install(FILES ${PROJECT_BINARY_DIR}/bin/glew32.dll
DESTINATION ${INSTALL_BIN_DIR})

View File

@ -16,28 +16,30 @@ add_definitions(-DCONF_NO_GL) # Used for obj-lib to not compile GL part
#find_package(GLEW REQUIRED) # Enable when GL rendering is ready
#include_directories(${GLEW_INCLUDE_DIR})
# Push compile infos to source
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/config.h @ONLY)
# Define src/headers files
FILE(GLOB_RECURSE RSE_MOD_SOURCES ./*.c)
SOURCE_GROUP("Source Files" FILES ${RSE_MOD_SOURCES})
file(GLOB_RECURSE RSE_MOD_SOURCES ./src/*.c)
source_group("Source Files" FILES ${RSE_MOD_SOURCES})
# Building instructions for RSE-Model
if(DEFINED ENV{CI})
set(CMAKE_BUILD_TYPE RELEASE)
endif()
# Declare standalone application
add_executable(rse-model ${RSE_MOD_SOURCES})
set_property(TARGET rse-model PROPERTY C_STANDARD 90)
target_include_directories(rse-model PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
#target_include_directories(rse-model PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
set_target_properties(rse-model PROPERTIES OUTPUT_NAME ${RSE_MODEL_NAME})
# Link externals libraries to the linker
if(MSVC)
# msvc does not append 'lib' - do it here to have consistent name
set_target_properties(rse-model PROPERTIES IMPORT_PREFIX "lib")
target_link_libraries(rse-model PRIVATE ${GLEW_LIBRARIES} rsp-model-lib)
target_link_libraries(rse-model PRIVATE rsp-model-libstatic ${GLEW_LIBRARIES})
else()
target_link_libraries(rse-model PRIVATE ${GLEW_LIBRARIES} m rsp-model-lib)
target_link_libraries(rse-model PRIVATE rsp-model-libstatic ${GLEW_LIBRARIES} m)
endif()

View File

@ -1 +0,0 @@
#define VERSION "1.0.0"

View File

@ -1 +0,0 @@
#define VERSION "@PROJECT_VERSION@"

View File

@ -15,11 +15,10 @@
#include <sys/types.h>
#include <sys/stat.h>
#endif
#include <RSPLib_errors.h>
#include <hob_struct.h>
#include <hob_parser.h>
#include "config.h"
#include "options.h"
#include <RSPModel.h>
#include <RSPModel_errordefs.h>
#include "obj_exporter.h"
@ -31,7 +30,7 @@
static unsigned int mainProcess(int args_cnt, char* args_value[], T_PROG_OPTIONS* opt_ptr);
static void createSubDir(char *dirName);
static unsigned char checkInputArgs(T_PROG_OPTIONS* opt_ptr, int p_arg_nbr, char* p_args[]);
static void cleanUpMemory(T_HOB* hobStruct);
static void cleanUpMemory(T_RSPMODEL_HOB* hobStruct);
static void dispHelp();
@ -43,19 +42,19 @@ int main(int argc, char *argv[]) {
unsigned char p;
// Hello world!
printf("\n*** RogueSquadron Extractor (RSE) - MODEL module - v%s ***\n", VERSION);
printf("\n*** RogueSquadron Extractor (RSE) - MODEL module - v%s ***\n", PRG_VERSION);
// Check for arguments
if (argc < 2) {
printf("\n[ERR] No input file/commands specified!\n");
dispHelp();
return ERROR_ARGS_NULL;
return RSPLIB_ERROR_ARGS_NULL;
}
// Create options for programs according to user's arguments.
p = checkInputArgs(&_opts, argc, argv);
if ( p == ERROR_GENERIC ) return NO_ERROR;
else if ( p != NO_ERROR ) return p;
if ( p == RSPLIB_ERROR_GENERIC ) return RSPLIB_SUCCESS;
else if ( p != RSPLIB_SUCCESS ) return p;
return mainProcess(argc, argv, &_opts);
}
@ -67,26 +66,26 @@ int main(int argc, char *argv[]) {
static unsigned int mainProcess(int args_cnt, char* args_value[], T_PROG_OPTIONS* p_opts) {
unsigned short file_index;
T_HOB* hobStruct = NULL;
T_RSPMODEL_HOB* hobStruct = NULL;
int i;
// Manage multiple inputs files
for ( file_index = p_opts->input_files_cnt; file_index < args_cnt; file_index++)
{
printf("\n=============================================\n[INFO] - Parsing file: %s ...\n", args_value[file_index]);
hobStruct = calloc(1, sizeof(T_HOB));
hobStruct = calloc(1, sizeof(T_RSPMODEL_HOB));
// Parse data from HOB file and put in T_HOB structure.
if (RSP_ModelLib_ParseHOBFile(args_value[file_index], hobStruct, p_opts) != NO_ERROR) {
if (RSPModel_processHOBFile(hobStruct, args_value[file_index]) != RSPLIB_SUCCESS) {
printf("[ERR] Failed to parse datas from %s\n", args_value[file_index]);
free(hobStruct);
return ERROR_PROCESS;
return RSPLIB_ERROR_PROCESS;
}
if (hobStruct->obj_count > 0) {
if (p_opts->output_dir) createSubDir(args_value[file_index]);
for ( i = 0; i < hobStruct->obj_count; i++ ) {
if (exportOBJModel(&(hobStruct->objects[i]), args_value[file_index], p_opts) != NO_ERROR)
if (exportOBJModel(&(hobStruct->objects[i]), args_value[file_index], p_opts) != RSPLIB_SUCCESS)
printf("[ERR] Failed to export %s object in OBJ format!\n", hobStruct->objects[i].name);
else
printf("[INFO] Successfully exported %s object in OBJ format.\n", hobStruct->objects[i].name);
@ -96,7 +95,7 @@ static unsigned int mainProcess(int args_cnt, char* args_value[], T_PROG_OPTIONS
cleanUpMemory(hobStruct);
return NO_ERROR;
return RSPLIB_SUCCESS;
}
static unsigned char checkInputArgs(T_PROG_OPTIONS* opt_ptr, int p_arg_nbr, char* p_args[]) {
@ -114,7 +113,7 @@ static unsigned char checkInputArgs(T_PROG_OPTIONS* opt_ptr, int p_arg_nbr, char
if (p_args[i][0] != '-') break;
if (strcmp(p_args[i], "-h") == 0) {
dispHelp();
return ERROR_GENERIC;
return RSPLIB_ERROR_GENERIC;
} else if (strcmp(p_args[i], "-v") == 0) {
opt_ptr->verbose_mode = 1;
printf("[OPTN] Verbose enabled.\n");
@ -130,7 +129,7 @@ static unsigned char checkInputArgs(T_PROG_OPTIONS* opt_ptr, int p_arg_nbr, char
} else if (strcmp(p_args[i], "-no-subdir") == 0) {
opt_ptr->output_dir = 0;
printf("[OPTN] Export to current directory.\n");
} else if (strcmp(p_args[i], "-mtl") == 0) {
} else if (strcmp(p_args[i], "-no-mtl") == 0) {
opt_ptr->export_mtl = 0;
printf("[OPTN] No materials datas.\n");
} else {
@ -139,10 +138,10 @@ static unsigned char checkInputArgs(T_PROG_OPTIONS* opt_ptr, int p_arg_nbr, char
}
opt_ptr->input_files_cnt = i;
return NO_ERROR;
return RSPLIB_SUCCESS;
}
return ERROR_ARGS_NULL;
return RSPLIB_ERROR_ARGS_NULL;
}
static void createSubDir(char *dirName) {
@ -158,7 +157,7 @@ static void createSubDir(char *dirName) {
#endif
}
static void cleanUpMemory(T_HOB* hobStruct) {
static void cleanUpMemory(T_RSPMODEL_HOB* hobStruct) {
int i,j;
for ( i=0; i<hobStruct->obj_count; i++ ) {
@ -182,6 +181,6 @@ static void dispHelp() {
printf(" -no-subdir Export models inside current folder\n");
printf(" -no-mtl Disable materials datas export with model\n");
printf("\n");
printf("Usage: RSE-Model_%s [options] <hob files...>\n", VERSION);
printf("Usage: RSE-Model_%s [options] <hob files...>\n", PRG_VERSION);
printf("\n");
}

View File

@ -9,16 +9,16 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <hob_struct.h>
#include <RSPLib_errors.h>
#include "options.h"
#include <RSPModel_datatypes.h>
#include <RSPModel_errordefs.h>
#include "rlk/obj.h"
#include "obj_exporter.h"
static void mtlPathPatch(const char* out_file, const char* obj_name) ;
unsigned char exportOBJModel(T_HOB_OBJECT* hob_objects, const char *out_path, T_PROG_OPTIONS* p_opts) {
unsigned char exportOBJModel(T_RSPMODEL_OBJECT* hob_objects, const char *out_path, T_PROG_OPTIONS* p_opts) {
char objExport_path[128];
char mtlExport_path[128];
obj* objConstruct = NULL;
@ -29,7 +29,7 @@ unsigned char exportOBJModel(T_HOB_OBJECT* hob_objects, const char *out_path, T_
int indicesBuff[3] = {0};
if (hob_objects == NULL || out_path == NULL)
return ERROR_ARGS_NULL;
return RSPLIB_ERROR_ARGS_NULL;
if (p_opts->output_dir) {
strcpy(objExport_path, out_path);

View File

@ -16,6 +16,6 @@ typedef struct t_material {
unsigned int gl_tex_id;
} T_MATERIAL;
unsigned char exportOBJModel(T_HOB_OBJECT* hob_objects, const char *out_path, T_PROG_OPTIONS* p_opts);
unsigned char exportOBJModel(T_RSPMODEL_OBJECT* hob_objects, const char *out_path, T_PROG_OPTIONS* p_opts);
#endif /* SRC_OBJ_EXPORTER_H_ */

View File

@ -14,25 +14,52 @@ endif()
include(CheckIncludeFile)
include(CheckCSourceCompiles)
# Push compile infos to source
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/config.h @ONLY)
# Define src/headers files
FILE(GLOB_RECURSE RSP_MOD_SOURCES ./src/*.c)
SOURCE_GROUP("Source Files" FILES ${RSP_MOD_SOURCES})
file(GLOB_RECURSE RSP_MOD_SOURCES ./src/*.c)
source_group("Source Files" FILES ${RSP_MOD_SOURCES})
file(GLOB RSP_PUBLIC_HRDS ./include/*.h)
set(RSP_PUBLIC_HRDS ${RSP_PUBLIC_HRDS} PARENT_SCOPE)
# Building instructions for RSE-Model
if(DEFINED ENV{CI})
set(CMAKE_BUILD_TYPE RELEASE)
endif()
add_library(rsp-model-lib ${RSP_MOD_SOURCES})
# Declare the shared library instance
add_library(rsp-model-lib SHARED ${RSP_MOD_SOURCES})
set_property(TARGET rsp-model-lib PROPERTY C_STANDARD 90)
target_include_directories(rsp-model-lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
set_target_properties(rsp-model-lib PROPERTIES OUTPUT_NAME ${RSP_MODEL_LIB_NAME})
# Link externals libraries to the linker
set_target_properties(rsp-model-lib PROPERTIES DEFINE_SYMBOL RSPMODEL_DLL)
if(MSVC)
# msvc does not append 'lib' - do it here to have consistent name
set_target_properties(rsp-model-lib PROPERTIES PREFIX "lib")
set_target_properties(rsp-model-lib PROPERTIES IMPORT_PREFIX "lib")
endif()
# Declare the static library instance
add_library(rsp-model-libstatic STATIC ${RSP_MOD_SOURCES})
set_property(TARGET rsp-model-libstatic PROPERTY C_STANDARD 90)
target_include_directories(rsp-model-libstatic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
if(NOT MSVC)
set_target_properties(rsp-model-libstatic PROPERTIES OUTPUT_NAME "${RSP_MODEL_LIB_NAME}")
set_target_properties(rsp-model-libstatic PROPERTIES CLEAN_DIRECT_OUTPUT 1)
else()
set_target_properties(rsp-model-libstatic PROPERTIES OUTPUT_NAME "${RSP_MODEL_LIB_NAME}_static")
set_target_properties(rsp-model-libstatic PROPERTIES CLEAN_DIRECT_OUTPUT 1)
endif()
if(MSVC)
# msvc does not append 'lib' - do it here to have consistent name
set_target_properties(rsp-model-libstatic PROPERTIES PREFIX "lib")
set_target_properties(rsp-model-libstatic PROPERTIES IMPORT_PREFIX "lib")
endif()

View File

@ -13,6 +13,30 @@
#ifndef RSPMODEL_H_
#define RSPMODEL_H_
#if defined(RSPMODEL_SHARED) || defined(RSPMODEL_DLL)
# if defined(_MSC_VER)
# define RSPMODEL_ABI_EXPORT __declspec(dllexport)
# define RSPMODEL_ABI_IMPORT __declspec(dllimport)
# elif __GNUC__ >= 4
# define RSPMODEL_ABI_EXPORT __attribute__ ((visibility("default")))
# define RSPMODEL_ABI_IMPORT __attribute__ ((visibility("default")))
# else
# define RSPMODEL_ABI_EXPORT
# define RSPMODEL_ABI_IMPORT
# endif
# if defined(WINDOWS) || defined(WIN32)
# ifdef RSPMODEL_DLL
# define RSPMODEL_EXTERN extern RSPMODEL_ABI_EXPORT
# else
# define RSPMODEL_EXTERN extern RSPMODEL_ABI_IMPORT
# endif
# endif
#else
# define RSPMODEL_EXTERN extern
#endif
#ifdef __cplusplus
extern "C" {
#endif
@ -25,7 +49,7 @@ extern "C" {
* @brief Get the current library version.
* @return Char array of the version, escape char included.
*/
char* RSPModel_getVersion( void );
RSPMODEL_EXTERN char* RSPModel_getVersion( void );
/**
* @brief Run model parser for the specified file in file system.
@ -37,7 +61,7 @@ char* RSPModel_getVersion( void );
*
* @return Error status, return RSPLIB_SUCCESS in nominal case.
*/
unsigned short RSPModel_processHOBFileMemory( T_RSPMODEL_HOB* hob, const char* const filePath );
RSPMODEL_EXTERN unsigned short RSPModel_processHOBFile( T_RSPMODEL_HOB* hob, const char* const filePath );
/**
* @brief Run model parser for the specified file in memory.
@ -51,7 +75,7 @@ unsigned short RSPModel_processHOBFileMemory( T_RSPMODEL_HOB* hob, const char* c
*
* @return Error status, return RSPLIB_SUCCESS in nominal case.
*/
unsigned short RSPModel_processHOBFile( T_RSPMODEL_HOB* hob, const void* const memFilePtr, const long memFileSize );
RSPMODEL_EXTERN unsigned short RSPModel_processHOBFileMemory( T_RSPMODEL_HOB* hob, const void* const memFilePtr, const long memFileSize );
/**
* @brief Convert HOB's object datas to GL compatible format.
@ -62,7 +86,7 @@ unsigned short RSPModel_processHOBFile( T_RSPMODEL_HOB* hob, const void* const m
*
* @return Error status, return RSPLIB_SUCCESS in nominal case.
*/
unsigned short RSPModel_objectToGL( const T_RSPMODEL_OBJECT* objStruct, void* glObj );
RSPMODEL_EXTERN unsigned short RSPModel_objectToGL( const T_RSPMODEL_OBJECT* objStruct, void* glObj );
/**
* @brief Convert HOB's object datas to Direct3D compatible format.
@ -73,7 +97,7 @@ unsigned short RSPModel_objectToGL( const T_RSPMODEL_OBJECT* objStruct, void* gl
*
* @return Error status, return RSPLIB_SUCCESS in nominal case.
*/
unsigned short RSPModel_objectToD3D( const T_RSPMODEL_OBJECT* objStruct, void* D3DObj );
RSPMODEL_EXTERN unsigned short RSPModel_objectToD3D( const T_RSPMODEL_OBJECT* objStruct, void* D3DObj );
#ifdef __cplusplus
}

View File

@ -7,21 +7,34 @@
*
*/
#include <stdio.h>
#include <string.h>
#include "config.h"
#include "options.h"
#include "RSPModel_errordefs.h"
#include "hob_parser.h"
#include "RSPModel.h"
char* RSPModel_getVersion( void ) {
return PRG_VERSION;
}
unsigned short RSPModel_processHOBFileMemory( T_RSPMODEL_HOB* hob, const char* const filePath ) {
unsigned short RSPModel_processHOBFile( T_RSPMODEL_HOB* hob, const char* const filePath ) {
if ( hob == NULL || filePath == NULL ) return RSPLIB_ERROR_ARGS_NULL;
T_PROG_OPTIONS canard;
canard.god_mode = 1;
RSP_ModelLib_ParseHOBFile(filePath, hob, &canard);
return RSPLIB_SUCCESS;
}
unsigned short RSPModel_processHOBFile( T_RSPMODEL_HOB* hob, const void* const memFilePtr, const long memFileSize ) {
unsigned short RSPModel_processHOBFileMemory( T_RSPMODEL_HOB* hob, const void* const memFilePtr, const long memFileSize ) {
if ( hob == NULL || memFilePtr == NULL ) return RSPLIB_ERROR_ARGS_NULL;
return RSPLIB_SUCCESS;
}

View File

@ -9,4 +9,4 @@ cmake_find_package
glew:shared=True
[imports]
bin, *.dll -> .
bin, *.dll -> ./bin

6
config.h.in Normal file
View File

@ -0,0 +1,6 @@
#ifndef CONFIG_H_
#define CONFIG_H_
#define PRG_VERSION "@PROJECT_VERSION@"
#endif /* CONFIG_H_ */