diff --git a/.gitignore b/.gitignore index 2c74351..cd6b464 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,7 @@ # Precompiled Headers *.gch *.pch -src/config.h +config.h # Libraries *.lib diff --git a/.gitmodules b/.gitmodules index 5b2ac1a..b20867d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index e5b8488..3c268bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 -) \ No newline at end of file +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}) diff --git a/RSEModel/CMakeLists.txt b/RSEModel/CMakeLists.txt index 843e9b1..d58b1f9 100644 --- a/RSEModel/CMakeLists.txt +++ b/RSEModel/CMakeLists.txt @@ -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() diff --git a/RSEModel/config.h b/RSEModel/config.h deleted file mode 100644 index bc0d1b1..0000000 --- a/RSEModel/config.h +++ /dev/null @@ -1 +0,0 @@ -#define VERSION "1.0.0" diff --git a/RSEModel/config.h.in b/RSEModel/config.h.in deleted file mode 100644 index 32f49cf..0000000 --- a/RSEModel/config.h.in +++ /dev/null @@ -1 +0,0 @@ -#define VERSION "@PROJECT_VERSION@" diff --git a/RSEModel/Model-Extractor.c b/RSEModel/src/Model-Extractor.c similarity index 84% rename from RSEModel/Model-Extractor.c rename to RSEModel/src/Model-Extractor.c index 06894f6..4dcdd18 100644 --- a/RSEModel/Model-Extractor.c +++ b/RSEModel/src/Model-Extractor.c @@ -15,11 +15,10 @@ #include #include #endif -#include -#include -#include #include "config.h" #include "options.h" +#include +#include #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; iobj_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] \n", VERSION); + printf("Usage: RSE-Model_%s [options] \n", PRG_VERSION); printf("\n"); } diff --git a/RSEModel/obj_exporter.c b/RSEModel/src/obj_exporter.c similarity index 96% rename from RSEModel/obj_exporter.c rename to RSEModel/src/obj_exporter.c index 94faac0..f2464a6 100644 --- a/RSEModel/obj_exporter.c +++ b/RSEModel/src/obj_exporter.c @@ -9,16 +9,16 @@ #include #include #include -#include -#include #include "options.h" +#include +#include #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); diff --git a/RSEModel/obj_exporter.h b/RSEModel/src/obj_exporter.h similarity index 76% rename from RSEModel/obj_exporter.h rename to RSEModel/src/obj_exporter.h index d0f7b30..df1ec34 100644 --- a/RSEModel/obj_exporter.h +++ b/RSEModel/src/obj_exporter.h @@ -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_ */ diff --git a/RSEModel/options.h b/RSEModel/src/options.h similarity index 100% rename from RSEModel/options.h rename to RSEModel/src/options.h diff --git a/RSEModel/rlk b/RSEModel/src/rlk similarity index 100% rename from RSEModel/rlk rename to RSEModel/src/rlk diff --git a/RSPModelLib/CMakeLists.txt b/RSPModelLib/CMakeLists.txt index fbe24d2..52fd59e 100644 --- a/RSPModelLib/CMakeLists.txt +++ b/RSPModelLib/CMakeLists.txt @@ -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() diff --git a/RSPModelLib/include/RSPModel.h b/RSPModelLib/include/RSPModel.h index 70f81c5..dd0cac9 100644 --- a/RSPModelLib/include/RSPModel.h +++ b/RSPModelLib/include/RSPModel.h @@ -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 } diff --git a/RSPModelLib/src/RSPModel.c b/RSPModelLib/src/RSPModel.c index 2dc0263..ec9e26a 100644 --- a/RSPModelLib/src/RSPModel.c +++ b/RSPModelLib/src/RSPModel.c @@ -7,21 +7,34 @@ * */ +#include #include #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; } diff --git a/conanfile.txt b/conanfile.txt index 6c8fd0c..9052a4d 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -9,4 +9,4 @@ cmake_find_package glew:shared=True [imports] -bin, *.dll -> . \ No newline at end of file +bin, *.dll -> ./bin \ No newline at end of file diff --git a/config.h.in b/config.h.in new file mode 100644 index 0000000..3f2e0c4 --- /dev/null +++ b/config.h.in @@ -0,0 +1,6 @@ +#ifndef CONFIG_H_ +#define CONFIG_H_ + +#define PRG_VERSION "@PROJECT_VERSION@" + +#endif /* CONFIG_H_ */