Compare commits

...

12 Commits

Author SHA1 Message Date
19c544441b
Conan asspain
All checks were successful
JCS-Prod/RSE-Texture/pipeline/head This commit looks good
2024-09-22 15:39:05 +02:00
94d2cb6e56
Finalize package export
All checks were successful
JCS-Prod/RSE-Texture/pipeline/head This commit looks good
2024-09-22 13:01:07 +02:00
42de1f7dad
Jenkins script update
All checks were successful
JCS-Prod/RSE-Texture/pipeline/pr-master This commit looks good
JCS-Prod/RSE-Texture/pipeline/head This commit looks good
2024-09-22 12:35:28 +02:00
e03f3436a6
Final work on Conan v2 support 2024-09-22 11:41:42 +02:00
0c8282ab5d
Validated conan v2 migration
All checks were successful
JCS-Prod/RSE-Texture/pipeline/pr-master This commit looks good
JCS-Prod/RSE-Texture/pipeline/head This commit looks good
2024-05-19 10:08:10 +02:00
d302d7ebd5
Pre-migration of conan manager to v2 2023-09-29 16:03:50 +02:00
d6b94f8c79
Patched library garbage
All checks were successful
JCS-Prod/RSE-Texture/pipeline/pr-master This commit looks good
JCS-Prod/RSE-Texture/pipeline/head This commit looks good
2022-09-18 16:01:18 +02:00
49fa1278ad
DLL export patch
All checks were successful
JCS-Prod/RSE-Texture/pipeline/pr-master This commit looks good
JCS-Prod/RSE-Texture/pipeline/head This commit looks good
2022-09-14 19:59:20 +02:00
e2b5f4c841
Added conan package support
All checks were successful
JCS-Prod/RSE-Texture/pipeline/pr-master This commit looks good
JCS-Prod/RSE-Texture/pipeline/head This commit looks good
2022-09-14 19:15:32 +02:00
4e8da870d9
Reviewed material resolver
All checks were successful
JCS-Prod/RSE-Texture/pipeline/pr-master This commit looks good
JCS-Prod/RSE-Texture/pipeline/head This commit looks good
2022-09-04 13:19:23 +02:00
3ffc546e1e
Linked datas to export 2022-09-01 18:52:42 +02:00
6fa5719957
Prototype of dll material interface 2022-09-01 18:47:50 +02:00
16 changed files with 511 additions and 167 deletions

5
.gitignore vendored
View File

@ -15,8 +15,8 @@
# Precompiled Headers # Precompiled Headers
*.gch *.gch
*.pch *.pch
RSPTerrainLib/src/config.h RSPTextureLib/src/config.h
RSETerrain/src/config.h RSETexture/src/config.h
# Libraries # Libraries
*.lib *.lib
@ -75,3 +75,4 @@ install_manifest.txt
compile_commands.json compile_commands.json
CTestTestfile.cmake CTestTestfile.cmake
_deps _deps
CMakeUserPresets.json

View File

@ -7,8 +7,8 @@
# CMake requirement and general configuration # CMake requirement and general configuration
cmake_minimum_required(VERSION 3.12) cmake_minimum_required(VERSION 3.15)
cmake_policy(VERSION 3.12) cmake_policy(VERSION 3.15)
set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR}) set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
if(DEFINED ENV{MS_COMPATIBLE}) if(DEFINED ENV{MS_COMPATIBLE})
set(CMAKE_GNUtoMS ON) # Enable compatibility level to exported libraries set(CMAKE_GNUtoMS ON) # Enable compatibility level to exported libraries
@ -20,14 +20,20 @@ if(DEFINED ENV{CI}) # Jenkins CI integration mode
project(rse-texture VERSION $ENV{CI_VERSION}.$ENV{CI_BUILD_NUMBER} DESCRIPTION "RogueSquadron Extractor - Texture" LANGUAGES C) project(rse-texture VERSION $ENV{CI_VERSION}.$ENV{CI_BUILD_NUMBER} DESCRIPTION "RogueSquadron Extractor - Texture" LANGUAGES C)
set(RSE_TEXTURE_NAME $ENV{CI_OUTPUT_NAME}) set(RSE_TEXTURE_NAME $ENV{CI_OUTPUT_NAME})
else() # Standalone project mode, should not be used for release. else() # Standalone project mode, should not be used for release.
project(rse-texture VERSION 2.0.0 DESCRIPTION "RogueSquadron Extractor - Texture" LANGUAGES C) project(rse-texture VERSION 2.1.0 DESCRIPTION "RogueSquadron Extractor - Texture" LANGUAGES C)
set(RSE_TEXTURE_NAME RSETexture) set(RSE_TEXTURE_NAME RSETexture)
endif() endif()
set(RSP_TEXTURE_LIB_NAME RSPTexture${PROJECT_VERSION_MAJOR}${PROJECT_VERSION_MINOR}) set(RSP_TEXTURE_LIB_NAME RSPTexture${PROJECT_VERSION_MAJOR}${PROJECT_VERSION_MINOR})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
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")
# Compilation option # Compilation option
option(RSPTEXTURE_SHARED "Build shared lib" ON) option(RSPTEXTURE_SHARED "Build shared lib" ON)
option(RSPTEXTURE_STATIC "Build static lib" ON)
option(BUILD_TOOLS "Build lib tools" ON)
# Push compile infos to source # Push compile infos to source
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/RSPTextureLib/src/config.h @ONLY) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/RSPTextureLib/src/config.h @ONLY)
@ -42,8 +48,24 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DI
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
unset(RSE_TEXTURE_TARGETS_LIST)
add_subdirectory(RSPTextureLib) add_subdirectory(RSPTextureLib)
add_subdirectory(RSETexture) add_subdirectory(RSETexture)
if(RSPTEXTURE_SHARED)
list(APPEND RSE_TEXTURE_TARGETS_LIST rsp-texture-lib)
endif()
if(RSPTEXTURE_STATIC)
list(APPEND RSE_TEXTURE_TARGETS_LIST rsp-texture-libstatic)
endif()
if(NOT RSE_TEXTURE_TARGETS_LIST)
message(SEND_ERROR
"No library variant selected to build. "
"Please enable at least one of the following options: "
"RSPTEXTURE_STATIC, RSPTEXTURE_SHARED")
endif()
if(BUILD_TOOLS)
list(APPEND RSE_TEXTURE_TARGETS_LIST rse-texture)
endif()
# GPG signature custom command # GPG signature custom command
@ -57,22 +79,16 @@ add_subdirectory(RSETexture)
#) #)
# Install project executable # Install dependancies
set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables") install(FILES ${PROJECT_BINARY_DIR}/bin/libpng16.dll
set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries") DESTINATION ${INSTALL_BIN_DIR})
set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers")
if(RSPTEXTURE_SHARED) # Install library includes
set(RSE_TEXTURE_TARGETS_LIST rse-texture rsp-texture-lib rsp-texture-libstatic) install(FILES ${RSP_PUBLIC_HRDS} DESTINATION ${INSTALL_INC_DIR})
else()
set(RSE_TEXTURE_TARGETS_LIST rse-texture rsp-texture-libstatic) # Install project artifacts
endif()
install(TARGETS ${RSE_TEXTURE_TARGETS_LIST} install(TARGETS ${RSE_TEXTURE_TARGETS_LIST}
RUNTIME DESTINATION ${INSTALL_BIN_DIR} RUNTIME DESTINATION ${INSTALL_BIN_DIR}
LIBRARY DESTINATION ${INSTALL_LIB_DIR} LIBRARY DESTINATION ${INSTALL_LIB_DIR}
ARCHIVE 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/libpng16.dll
DESTINATION ${INSTALL_BIN_DIR})

15
Jenkinsfile vendored
View File

@ -5,14 +5,13 @@ pipeline {
} }
environment { environment {
CI_OUTPUT_NAME = "RSETexture" CI_OUTPUT_NAME = "RSETexture"
CI_VERSION = "2.0.1" CI_VERSION = "2.1.0"
CI_BUILD_NUMBER = "$BUILD_NUMBER" CI_BUILD_NUMBER = "$BUILD_NUMBER"
} }
stages { stages {
stage('Prepare') { stage('Prepare') {
steps { steps {
cleanWs() cleanWs()
rtConanClient(id: "conan", userHome: "/home/jackcartersmith")
} }
} }
stage('Build') { stage('Build') {
@ -22,20 +21,16 @@ pipeline {
dir("linux") { dir("linux") {
checkout([$class: 'GitSCM', branches: [[name: '**']], browser: [$class: 'GiteaBrowser', repoUrl: 'https://git.jcsmith.fr/JCS-Prod/RSE-Texture'], extensions: [], userRemoteConfigs: [[credentialsId: 'jenkins-ssh', url: 'ssh://git@git.jcsmith.fr:2322/JCS-Prod/RSE-Texture.git']]]) checkout([$class: 'GitSCM', branches: [[name: '**']], browser: [$class: 'GiteaBrowser', repoUrl: 'https://git.jcsmith.fr/JCS-Prod/RSE-Texture'], extensions: [], userRemoteConfigs: [[credentialsId: 'jenkins-ssh', url: 'ssh://git@git.jcsmith.fr:2322/JCS-Prod/RSE-Texture.git']]])
sh 'git submodule update --init --recursive' sh 'git submodule update --init --recursive'
dir("build") { sh 'conan install . -of build -s build_type=Release -o "&:tools=True" -pr:b=default -pr:h=default --build=missing'
rtConanRun(clientId: "conan", command: "install .. --build=missing") cmakeBuild buildDir: 'build', cmakeArgs: '-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DRSPTEXTURE_SHARED=ON -DRSPTEXTURE_STATIC=OFF -DBUILD_TOOLS=ON -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=Release', installation: 'latest', steps: [[args: 'all']]
}
cmakeBuild buildDir: 'build', installation: 'latest', steps: [[args: 'all']]
} }
}, },
windows: { windows: {
dir("windows") { dir("windows") {
checkout([$class: 'GitSCM', branches: [[name: '**']], browser: [$class: 'GiteaBrowser', repoUrl: 'https://git.jcsmith.fr/JCS-Prod/RSE-Terrain'], extensions: [], userRemoteConfigs: [[credentialsId: 'jenkins-ssh', url: 'ssh://git@git.jcsmith.fr:2322/JCS-Prod/RSE-Texture.git']]]) checkout([$class: 'GitSCM', branches: [[name: '**']], browser: [$class: 'GiteaBrowser', repoUrl: 'https://git.jcsmith.fr/JCS-Prod/RSE-Terrain'], extensions: [], userRemoteConfigs: [[credentialsId: 'jenkins-ssh', url: 'ssh://git@git.jcsmith.fr:2322/JCS-Prod/RSE-Texture.git']]])
sh 'git submodule update --init --recursive' sh 'git submodule update --init --recursive'
dir("build") { sh 'conan install . -of build -s build_type=Release -o "&:tools=True" -pr:b=default -pr:h=windows --build=missing'
rtConanRun(clientId: "conan", command: "install .. -pr:b=default -pr:h=windows --build=missing") cmakeBuild buildDir: 'build', cmakeArgs: '-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DRSPTEXTURE_SHARED=ON -DRSPTEXTURE_STATIC=OFF -DBUILD_TOOLS=ON -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=Release -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc -DCMAKE_RC_COMPILER=x86_64-w64-mingw32-windres', installation: 'latest', steps: [[args: 'all']]
}
cmakeBuild buildDir: 'build', cmakeArgs: '-DGNU_HOST=x86_64-w64-mingw32 -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw_cross_toolchain.cmake', installation: 'latest', steps: [[args: 'all']]
} }
} }
) )

View File

@ -44,45 +44,39 @@ Due to issue with copyrights, I can't provide samples... You need to extract HMT
Necessary libs (provided only in windows release) for running and for compiling. Necessary libs (provided only in windows release) for running and for compiling.
- libpng (1.6.37) - [zlib](https://www.zlib.net/) (1.3.1)
- [libpng](http://www.libpng.org/pub/png/libpng.html) (1.6.43)
### Compiling ### Compiling
You can compile on both Windows (MinGW) or native Linux system thanks to CMake, you only need to adjust your dependencies on Windows or use Conan packages manager (https://conan.io). I've a preference for compiling libraries by hand, mainly for backward compatibility, but I recommend using Conan packages manager (https://conan.io) for simplicity (I've abandonned the support for conan v1 as it's now considered as deprecated).
libpng16-dev distrib package can be used on debian/ubuntu.
To compile, just clone and launch cmake:
```shell ```shell
cmake . conan install . -of build -b missing -s build_type=Release -o tools=True -pr:b=default -pr:h=default
make cmake --preset conan-release -G "Unix Makefiles"
make install cmake --build --preset conan-release
``` ```
On Windows system, I can suggest you to use Conan support to help you with dependencies: If your CMake<3.23, you should use this command for generation instead of preset one:
```shell `cmake . -S build -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DRSPTEXTURE_SHARED=ON -DRSPTEXTURE_STATIC=OFF -DBUILD_TOOLS=ON -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles"`
mkdir build
cd build
conan install .. --build=missing
cmake .. -G "MinGW Makefiles"
make
```
If you want to do it manually without Conan support, you will probably need to specify the dependency flags for CMake. Ex: Beware to use the same release/debug configuration with CMake using Conan! Adjust CMake preset or Conan configuration if necessary.
`cmake.exe -D"ZLIB_INCLUDE_DIR=zlib/1.2.12/include" -D"ZLIB_LIBRARY=zlib/1.2.12/lib/libzlib.dll.a" -D"PNG_PNG_INCLUDE_DIR=libpng/1.6.37/include" -D"PNG_LIBRARY=libpng/1.6.37/lib/libpng.dll.a" . -G "MinGW Makefiles"` On Windows environment, you can use MinGW `-G "MinGW Makefiles"` or Ninja `-G "Ninja"` as CMake generator.
We can also use cross-compilation (after installing `mingw64` and `cmake` packages on your distrib): ### Compiling (options)
```shell There are a few configurable build options:
mkdir build && cd build
cmake -DGNU_HOST=x86_64-w64-mingw32 \ - RSPTEXTURE_SHARED Enable the build of shared version of the library ("shared" conan option)
-DCMAKE_TOOLCHAIN_FILE=../mingw_cross_toolchain.cmake \ - RSPTEXTURE_STATIC Enable the build of static version of the library ("shared" conan option)
-D"ZLIB_INCLUDE_DIR=zlib/1.2.12/include" \ - BUILD_TOOLS Enable the build of the standalone tools (necessary to use the lib directly) ("tools" conan option)
-D"ZLIB_LIBRARY=zlib/1.2.12/lib/libzlib.dll.a" \
-D"PNG_PNG_INCLUDE_DIR=libpng/1.6.37/include" \ ### Compiling (old-way)
-D"PNG_LIBRARY=libpng/1.6.37/lib/libpng.dll.a" \
.. If you want to do it manually without Conan, you will probably need to specify the dependency flags for CMake. Ex:
cmake --build .
``` `cmake.exe -D"ZLIB_INCLUDE_DIR=zlib/1.3.1/include" -D"ZLIB_LIBRARY=zlib/1.3.1/lib/libzlib.dll.a" -D"PNG_PNG_INCLUDE_DIR=libpng/1.6.43/include" -D"PNG_LIBRARY=libpng/1.6.43/lib/libpng.dll.a" -DRSPTEXTURE_SHARED=ON -DRSPTEXTURE_STATIC=OFF -DBUILD_TOOLS=ON . -G "MinGW Makefiles"`
I've tested cross-compilation too, but since I want to check that Conan is working properly at each release, I've integrated it into the Jenkins flow using Conan for the cross-abstraction.

View File

@ -10,34 +10,41 @@
include(CheckIncludeFile) include(CheckIncludeFile)
include(CheckCSourceCompiles) include(CheckCSourceCompiles)
# Import needed packages and references their include path if(BUILD_TOOLS)
find_package(PNG 1.6.37 REQUIRED) # Import needed packages and references their include path
include_directories(${PNG_INCLUDE_DIR}) find_package(PNG 1.6.40 REQUIRED)
include_directories(${PNG_INCLUDE_DIR})
# Define src/headers files # Define src/headers files
file(GLOB_RECURSE RSE_TEXTURE_SOURCES ./src/*.c) file(GLOB_RECURSE RSE_TEXTURE_SOURCES ./src/*.c)
source_group("Source Files" FILES ${RSE_TEXTURE_SOURCES}) source_group("Source Files" FILES ${RSE_TEXTURE_SOURCES})
# Building instructions for RSE-Texture # Building instructions for RSE-Texture
if(DEFINED ENV{CI}) if(DEFINED ENV{CI})
set(CMAKE_BUILD_TYPE RELEASE) set(CMAKE_BUILD_TYPE RELEASE)
endif() endif()
# Declare standalone application # Declare standalone application
add_executable(rse-texture ${RSE_TEXTURE_SOURCES}) add_executable(rse-texture ${RSE_TEXTURE_SOURCES})
set_property(TARGET rse-texture PROPERTY C_STANDARD 90) set_property(TARGET rse-texture PROPERTY C_STANDARD 90)
#target_include_directories(rse-texture PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src) #target_include_directories(rse-texture PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
set_target_properties(rse-texture PROPERTIES OUTPUT_NAME ${RSE_TEXTURE_NAME}) set_target_properties(rse-texture PROPERTIES OUTPUT_NAME ${RSE_TEXTURE_NAME})
# Link externals libraries to the linker if(MSVC)
if(MSVC) # msvc does not append 'lib' - do it here to have consistent name
# msvc does not append 'lib' - do it here to have consistent name set_target_properties(rse-texture PROPERTIES IMPORT_PREFIX "lib")
set_target_properties(rse-texture PROPERTIES IMPORT_PREFIX "lib") endif()
target_link_libraries(rse-texture PRIVATE rsp-texture-libstatic ${PNG_LIBRARIES})
else() # Link externals libraries to the linker
target_link_libraries(rse-texture PRIVATE rsp-texture-libstatic ${PNG_LIBRARIES}) if (TARGET PNG::PNG)
if(RSPTEXTURE_SHARED)
target_link_libraries(rse-texture PRIVATE rsp-texture-lib PNG::PNG)
elseif(RSPTEXTURE_STATIC)
target_link_libraries(rse-texture PRIVATE rsp-texture-libstatic PNG::PNG)
endif()
endif()
endif() endif()

View File

@ -32,14 +32,18 @@ endif()
if(RSPTEXTURE_SHARED) if(RSPTEXTURE_SHARED)
add_library(rsp-texture-lib SHARED ${RSP_TEXTURE_SOURCES}) add_library(rsp-texture-lib SHARED ${RSP_TEXTURE_SOURCES})
set_property(TARGET rsp-texture-lib PROPERTY C_STANDARD 90) set_property(TARGET rsp-texture-lib PROPERTY C_STANDARD 90)
set_target_properties(rsp-texture-lib PROPERTIES VERSION 2.1.0)
target_include_directories(rsp-texture-lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) target_include_directories(rsp-texture-lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
set_target_properties(rsp-texture-lib PROPERTIES OUTPUT_NAME ${RSP_TEXTURE_LIB_NAME}) set_target_properties(rsp-texture-lib PROPERTIES OUTPUT_NAME "${RSP_TEXTURE_LIB_NAME}")
set_target_properties(rsp-texture-lib PROPERTIES DEFINE_SYMBOL RSPTEXTURE_DLL)
if(WIN32)
set_target_properties(rsp-texture-lib PROPERTIES DEFINE_SYMBOL RSPTEXTURE_DLL)
endif()
if(MSVC) # msvc does not append 'lib' - do it here to have consistent name
# msvc does not append 'lib' - do it here to have consistent name if(MSVC)
set_target_properties(rsp-texture-lib PROPERTIES PREFIX "lib") set_target_properties(rsp-texture-lib PROPERTIES PREFIX "lib")
set_target_properties(rsp-texture-lib PROPERTIES IMPORT_PREFIX "lib") set_target_properties(rsp-texture-lib PROPERTIES IMPORT_PREFIX "lib")
endif() endif()
@ -47,21 +51,52 @@ endif()
# Declare the static library instance # Declare the static library instance
add_library(rsp-texture-libstatic STATIC ${RSP_TEXTURE_SOURCES}) if(RSPTEXTURE_STATIC)
set_property(TARGET rsp-texture-libstatic PROPERTY C_STANDARD 90) add_library(rsp-texture-libstatic STATIC ${RSP_TEXTURE_SOURCES})
set_property(TARGET rsp-texture-libstatic PROPERTY C_STANDARD 90)
target_include_directories(rsp-texture-libstatic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) target_include_directories(rsp-texture-libstatic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
# MSVC doesn't use a different file extension for shared vs. static
# libs. We are able to change OUTPUT_NAME to remove the _static
# for all other platforms.
if(NOT MSVC)
set_target_properties(rsp-texture-libstatic PROPERTIES OUTPUT_NAME "${RSP_TEXTURE_LIB_NAME}")
set_target_properties(rsp-texture-libstatic PROPERTIES CLEAN_DIRECT_OUTPUT 1)
else()
set_target_properties(rsp-texture-libstatic PROPERTIES OUTPUT_NAME "${RSP_TEXTURE_LIB_NAME}_static")
set_target_properties(rsp-texture-libstatic PROPERTIES CLEAN_DIRECT_OUTPUT 1)
endif()
if(NOT MSVC) # MSVC does not append 'lib' - do it here to have consistent name
set_target_properties(rsp-texture-libstatic PROPERTIES OUTPUT_NAME "${RSP_TEXTURE_LIB_NAME}") if(MSVC)
set_target_properties(rsp-texture-libstatic PROPERTIES CLEAN_DIRECT_OUTPUT 1) set_target_properties(rsp-texture-libstatic PROPERTIES PREFIX "lib")
else() endif()
set_target_properties(rsp-texture-libstatic PROPERTIES OUTPUT_NAME "${RSP_TEXTURE_LIB_NAME}_static")
set_target_properties(rsp-texture-libstatic PROPERTIES CLEAN_DIRECT_OUTPUT 1)
endif() endif()
if(MSVC)
# msvc does not append 'lib' - do it here to have consistent name include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/create_symlink.cmake)
set_target_properties(rsp-texture-libstatic PROPERTIES PREFIX "lib")
set_target_properties(rsp-texture-libstatic PROPERTIES IMPORT_PREFIX "lib") # Install libraries with OS specific name fix
if(RSPTEXTURE_SHARED)
# Create a symlink for libRSPTexture.dll.a => libRSPTextureXX.dll.a on Cygwin/MinGW
if(CYGWIN OR MINGW)
create_lib_symlink(libRSPTexture${CMAKE_IMPORT_LIBRARY_SUFFIX} TARGET rsp-texture-lib)
install(FILES $<TARGET_LINKER_FILE_DIR:rsp-texture-lib>/libRSPTexture${CMAKE_IMPORT_LIBRARY_SUFFIX}
DESTINATION ${INSTALL_LIB_DIR})
endif()
if(NOT WIN32)
create_lib_symlink(libRSPTexture${CMAKE_SHARED_LIBRARY_SUFFIX} TARGET rsp-texture-lib)
install(FILES $<TARGET_LINKER_FILE_DIR:rsp-texture-lib>/libRSPTexture${CMAKE_SHARED_LIBRARY_SUFFIX}
DESTINATION ${INSTALL_LIB_DIR})
endif()
endif()
if(RSPTEXTURE_STATIC)
if(NOT WIN32 OR CYGWIN OR MINGW)
create_lib_symlink(libRSPTexture${CMAKE_STATIC_LIBRARY_SUFFIX} TARGET rsp-texture-libstatic)
install(FILES $<TARGET_LINKER_FILE_DIR:rsp-texture-libstatic>/libRSPTexture${CMAKE_STATIC_LIBRARY_SUFFIX}
DESTINATION ${INSTALL_LIB_DIR})
endif()
endif() endif()

View File

@ -1,6 +1,6 @@
/** /**
* @file RSPTexture.h * @file RSPTexture.h
* @date 25/08/2022 * @date 14/09/2022
* @author JackCarterSmith * @author JackCarterSmith
* @copyright GPL-v3.0 * @copyright GPL-v3.0
* @brief Rogue Squadron Parser texture library, used to decode HMT datas * @brief Rogue Squadron Parser texture library, used to decode HMT datas
@ -54,6 +54,12 @@ extern "C" {
*/ */
RSPTEXTURE_EXTERN char* RSPTexture_getVersion( void ); RSPTEXTURE_EXTERN char* RSPTexture_getVersion( void );
/**
* @brief Constructor for T_RSPTEXTURE_HMT struct
* @return Pointer to a new T_RSPTEXTURE_HMT struct.
*/
RSPTEXTURE_EXTERN T_RSPTEXTURE_HMT* RSPTexture_createHMT( void );
/** /**
* @brief Run texture parser for the specified file in file system. * @brief Run texture parser for the specified file in file system.
* @details Texture library can process HMT file from file system. It's a easy * @details Texture library can process HMT file from file system. It's a easy
@ -88,6 +94,40 @@ RSPTEXTURE_EXTERN unsigned short RSPTexture_processHMTFileMemory(
const RSPTEXTURE_PARAMETERS params const RSPTEXTURE_PARAMETERS params
); );
/**
* @brief Parse HMT materials for specific ID.
* @pre HMT structure should be processed with RSPTexture_processHMTFile()
* or RSPTexture_processHMTMemFile() before.
*
* @param[in] pHmt HMT texture structure to be analyzed.
* @param[in] mat_id ID of the material.
*
* @return Pointer to T_RSPTEXTURE_MATERIAL if found or NULL otherwise.
*/
RSPTEXTURE_EXTERN T_RSPTEXTURE_MATERIAL* RSPTexture_getMaterialFromID(
const T_RSPTEXTURE_HMT* pHmt, const unsigned short mat_id
);
/**
* @brief Retrieve material name of a T_RSPTEXTURE_MATERIAL structure.
* @return '0' terminated name string (max: 16 chars).
*/
RSPTEXTURE_EXTERN char* RSPTexture_getMaterialName( const T_RSPTEXTURE_MATERIAL* mat );
/**
* @brief Retrieve opacity value from T_RSPTEXTURE_MATERIAL structure.
* @return Float opacity value.
* @warning Experimental method.
*/
RSPTEXTURE_EXTERN float RSPTexture_getMaterialOpacity( const T_RSPTEXTURE_MATERIAL* mat );
/**
* @brief Retrieve ambient light value from T_RSPTEXTURE_MATERIAL structure.
* @return Float ambient light value.
* @warning Experimental method.
*/
RSPTEXTURE_EXTERN float RSPTexture_getMaterialAmbient( const T_RSPTEXTURE_MATERIAL* mat );
/** /**
* @brief Clean HMT object and it's childrens from memory. * @brief Clean HMT object and it's childrens from memory.
* @param[in] hmtStruct Pointer to data to be cleaned up. * @param[in] hmtStruct Pointer to data to be cleaned up.

View File

@ -34,25 +34,28 @@ typedef union u_rsptexture_parameters {
// Lib's structure definitions // Lib's structure definitions
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#ifndef MEMFILE #ifndef MEMFILE_DEF
typedef char* MEMFILE; typedef char* MEMFILE;
#define MEMFILE_DEF
#endif #endif
#ifndef T_R8G8B8
#ifndef T_R8G8B8_DEF
typedef struct r8g8b8 { unsigned char r,g,b; } T_R8G8B8; typedef struct r8g8b8 { unsigned char r,g,b; } T_R8G8B8;
#define T_R8G8B8_DEF
#endif #endif
#ifndef T_R8G8B8A8
#ifndef T_R8G8B8A8_DEF
typedef struct r8g8b8a8 { unsigned char r,g,b,a; } T_R8G8B8A8; typedef struct r8g8b8a8 { unsigned char r,g,b,a; } T_R8G8B8A8;
#define T_R8G8B8A8_DEF
#endif #endif
typedef enum e_mat_type {
RSPTEX_MAT_TYPE_TEXTURED = 1,
RSPTEX_MAT_TYPE_SOLID = 2
} RSPTEX_MAT_TYPE;
typedef unsigned char T_SAMPLE; typedef unsigned char T_SAMPLE;
typedef struct rsptexture_material {
unsigned char name[17]; // 16 + 1 string ending \0
unsigned short type;
unsigned short texture_index; //TODO: pointer to a T_RSPTEXTURE_TEXTURE element?
} T_RSPTEXTURE_MATERIAL;
typedef struct rsptexture_texture { typedef struct rsptexture_texture {
unsigned char name[17]; // 16 + 1 string ending \0 unsigned char name[17]; // 16 + 1 string ending \0
unsigned short width; unsigned short width;
@ -61,15 +64,22 @@ typedef struct rsptexture_texture {
unsigned char type; unsigned char type;
unsigned char sample_bits; unsigned char sample_bits;
unsigned int palette_entries; unsigned int palette_entries;
T_R8G8B8A8 alpha_color; T_R8G8B8A8 alpha_color;
unsigned int palette_offset; //TODO: useless?
unsigned int pixels_offset; //TODO: useless?
T_R8G8B8A8* pixels; T_R8G8B8A8* pixels;
} T_RSPTEXTURE_TEXTURE; } T_RSPTEXTURE_TEXTURE;
typedef struct rsptexture_material {
unsigned short id;
unsigned char name[17]; // 16 + 1 string ending \0
RSPTEX_MAT_TYPE type;
float opacity; //TODO: temporary, need to be defined
float ambient; //TODO: temporary, need to be defined
T_RSPTEXTURE_TEXTURE* texture;
} T_RSPTEXTURE_MATERIAL;
typedef struct rsptexture_hmt { typedef struct rsptexture_hmt {
unsigned int materials_count; unsigned int materials_count;
unsigned int textures_count; unsigned int textures_count;

View File

@ -1,12 +1,16 @@
/** /**
* @file RSPTexture.c * @file RSPTexture.c
* @date 25/08/2022 * @date 14/09/2022
* @author JackCarterSmith * @author JackCarterSmith
* @copyright GPL-v3.0 * @copyright GPL-v3.0
* @brief HMT textures datas parser and export to PNG format. * @brief HMT textures datas parser and export to PNG format.
* *
*/ */
#if defined(RSPTEXTURE_DLL)
# define RSPTEXTURE_DLLBUILD
#endif
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -17,10 +21,20 @@
#include "RSPTexture.h" #include "RSPTexture.h"
/*
* Libs interface
*/
inline char* RSPTexture_getVersion( void ) { inline char* RSPTexture_getVersion( void ) {
return PRG_VERSION; return PRG_VERSION;
} }
/*
* HMT parser
*/
T_RSPTEXTURE_HMT* RSPTexture_createHMT( void ) {
return calloc(1, sizeof(T_RSPTEXTURE_HMT));
}
unsigned short RSPTexture_processHMTFile( T_RSPTEXTURE_HMT* hmtStruct, const char* const filePath, unsigned short RSPTexture_processHMTFile( T_RSPTEXTURE_HMT* hmtStruct, const char* const filePath,
const RSPTEXTURE_PARAMETERS params ) { const RSPTEXTURE_PARAMETERS params ) {
@ -37,7 +51,35 @@ unsigned short RSPTexture_processHMTFileMemory( T_RSPTEXTURE_HMT* hmtStruct, con
return RSP_TextureLib_ParseHMTMemFile((MEMFILE)memFilePtr, hmtStruct, &params); return RSP_TextureLib_ParseHMTMemFile((MEMFILE)memFilePtr, hmtStruct, &params);
} }
void RSPTexture_freeHMT(T_RSPTEXTURE_HMT* hmtStruct) { /*
* Material utilities
*/
T_RSPTEXTURE_MATERIAL* RSPTexture_getMaterialFromID( const T_RSPTEXTURE_HMT* pHmt, const unsigned short mat_id ) {
if ( pHmt == NULL ) return NULL;
if ( pHmt->materials == NULL ) return NULL;
return &(pHmt->materials[mat_id]);
}
inline char* RSPTexture_getMaterialName( const T_RSPTEXTURE_MATERIAL* mat ) {
if ( mat == NULL ) return NULL;
return (char*)mat->name;
}
inline float RSPTexture_getMaterialOpacity( const T_RSPTEXTURE_MATERIAL* mat ) {
if ( mat == NULL ) return 1.0;
return mat->opacity;
}
inline float RSPTexture_getMaterialAmbient( const T_RSPTEXTURE_MATERIAL* mat ) {
if ( mat == NULL ) return 1.0;
return mat->ambient;
}
void RSPTexture_freeHMT( T_RSPTEXTURE_HMT* hmtStruct ) {
unsigned int i; unsigned int i;
if (hmtStruct == NULL) return; if (hmtStruct == NULL) return;

View File

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

View File

@ -117,14 +117,15 @@ static unsigned short ExtractTextureHMT(T_RSPTEXTURE_HMT* pHmtStruct, const MEMF
if (pParams->verbose_mode) printf("[DBG] > Texture offset: 0x%X\n", pHmtStruct->texture_offset); if (pParams->verbose_mode) printf("[DBG] > Texture offset: 0x%X\n", pHmtStruct->texture_offset);
printf("\n"); printf("\n");
// Get materials if any
if (pHmtStruct->materials_count > 0)
errorCode |= ExtractMaterials(pHmtStruct, pMemfile, pParams);
// Get textures if any // Get textures if any
if (pHmtStruct->textures_count > 0) if (pHmtStruct->textures_count > 0)
errorCode |= ExtractTextures(pHmtStruct, pMemfile, pParams); errorCode |= ExtractTextures(pHmtStruct, pMemfile, pParams);
// Get materials if any and link them to texture
if (pHmtStruct->materials_count > 0)
errorCode |= ExtractMaterials(pHmtStruct, pMemfile, pParams);
return errorCode; return errorCode;
} }
@ -156,19 +157,35 @@ static unsigned short ExtractMaterials(T_RSPTEXTURE_HMT* pHmt, const MEMFILE pMe
// Get material datas // Get material datas
pHmt->materials[i].type = ((T_HMTFILE_MATERIAL *)(pMemfile + pHmt->materials[i].type = ((T_HMTFILE_MATERIAL *)(pMemfile +
sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->type; sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->type;
pHmt->materials[i].texture_index = ((T_HMTFILE_MATERIAL *)(pMemfile + pHmt->materials[i].id = ((T_HMTFILE_MATERIAL *)(pMemfile +
sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->texture_index; // Texture index is only for texture "type" (1) sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->texture_index;
// If material is textured, the linked texture correspond to tex_index in textures array.
if (pHmt->materials[i].type == RSPTEX_MAT_TYPE_TEXTURED) pHmt->materials[i].texture = pHmt->textures + pHmt->materials[i].id;
else pHmt->materials[i].texture = NULL;
pHmt->materials[i].opacity = ((T_HMTFILE_MATERIAL *)(pMemfile +
sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->reserved1;
pHmt->materials[i].ambient = ((T_HMTFILE_MATERIAL *)(pMemfile +
sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->reserved0;
if (pParams->verbose_mode) { if (pParams->verbose_mode) {
printf("[INFO] > Material name: %s\n", pHmt->materials[i].name); printf("[INFO] > Material name: %s\n", pHmt->materials[i].name);
printf("[INFO] > Material type: %d\n", pHmt->materials[i].type); printf("[INFO] > Material type: %d\n", pHmt->materials[i].type);
printf("[INFO] > Material text. index: %d (valid if type == 1)\n", pHmt->materials[i].texture_index); printf("[INFO] > Material id: %d\n", pHmt->materials[i].id);
printf("[INFO] > Material text. index: %d\n", i);
if (pHmt->materials[i].type == RSPTEX_MAT_TYPE_TEXTURED)
printf("[INFO] > Linked texture name: %s (should correspond to material name)\n", pHmt->materials[i].texture->name);
} }
/*
* Unassigned generic material datas :
* - Transparent
* - Ambient (global)
* - Diffuse (environnement)
* - Specular (self)
*/
if (pParams->debug_mode) { if (pParams->debug_mode) {
printf("[DBG] > Material reserved0: %.8f\n", ((T_HMTFILE_MATERIAL *)(pMemfile + printf("[DBG] > Material reserved0: %.8f\n", pHmt->materials[i].ambient);
sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->reserved0); printf("[DBG] > Material reserved1: %.8f\n", pHmt->materials[i].opacity);
printf("[DBG] > Material reserved1: %.8f\n", ((T_HMTFILE_MATERIAL *)(pMemfile +
sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->reserved1);
printf("[DBG] > Material reserved2 (zero): 0x%X\n", ((T_HMTFILE_MATERIAL *)(pMemfile + printf("[DBG] > Material reserved2 (zero): 0x%X\n", ((T_HMTFILE_MATERIAL *)(pMemfile +
sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->reserved2); sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->reserved2);
printf("[DBG] > Material reserved3 (0xA): 0x%X\n", ((T_HMTFILE_MATERIAL *)(pMemfile + printf("[DBG] > Material reserved3 (0xA): 0x%X\n", ((T_HMTFILE_MATERIAL *)(pMemfile +
@ -193,6 +210,7 @@ static unsigned short ExtractMaterials(T_RSPTEXTURE_HMT* pHmt, const MEMFILE pMe
static unsigned short ExtractTextures(T_RSPTEXTURE_HMT* pHmt, const MEMFILE pMemfile, const RSPTEXTURE_PARAMETERS* pParams) { static unsigned short ExtractTextures(T_RSPTEXTURE_HMT* pHmt, const MEMFILE pMemfile, const RSPTEXTURE_PARAMETERS* pParams) {
T_R8G8B8* _palette = NULL; T_R8G8B8* _palette = NULL;
T_SAMPLE* _samples = NULL; T_SAMPLE* _samples = NULL;
unsigned int palette_offset, pixels_offset;
unsigned int i; unsigned int i;
if (pHmt == NULL || pMemfile == NULL) return RSPLIB_ERROR_ARGS_NULL; if (pHmt == NULL || pMemfile == NULL) return RSPLIB_ERROR_ARGS_NULL;
@ -245,9 +263,9 @@ static unsigned short ExtractTextures(T_RSPTEXTURE_HMT* pHmt, const MEMFILE pMem
sizeof(T_HMTFILE_HEADER2) + sizeof(T_HMTFILE_TEXTURE_HEADER) * i))->tex_format.transparent_color, sizeof(T_R8G8B8A8)); sizeof(T_HMTFILE_HEADER2) + sizeof(T_HMTFILE_TEXTURE_HEADER) * i))->tex_format.transparent_color, sizeof(T_R8G8B8A8));
// Get texture datas offsets // Get texture datas offsets
pHmt->textures[i].pixels_offset = ((T_HMTFILE_TEXTURE_HEADER *)(pMemfile + pHmt->texture_offset + pixels_offset = ((T_HMTFILE_TEXTURE_HEADER *)(pMemfile + pHmt->texture_offset +
sizeof(T_HMTFILE_HEADER2) + sizeof(T_HMTFILE_TEXTURE_HEADER) * i))->pixels_offset; sizeof(T_HMTFILE_HEADER2) + sizeof(T_HMTFILE_TEXTURE_HEADER) * i))->pixels_offset;
pHmt->textures[i].palette_offset = ((T_HMTFILE_TEXTURE_HEADER *)(pMemfile + pHmt->texture_offset + palette_offset = ((T_HMTFILE_TEXTURE_HEADER *)(pMemfile + pHmt->texture_offset +
sizeof(T_HMTFILE_HEADER2) + sizeof(T_HMTFILE_TEXTURE_HEADER) * i))->palette_offset; sizeof(T_HMTFILE_HEADER2) + sizeof(T_HMTFILE_TEXTURE_HEADER) * i))->palette_offset;
// Get texture name // Get texture name
@ -268,8 +286,8 @@ static unsigned short ExtractTextures(T_RSPTEXTURE_HMT* pHmt, const MEMFILE pMem
printf("[DBG] > Texture unknown0: 0x%X\n", ((T_HMTFILE_TEXTURE_HEADER *)(pMemfile + pHmt->texture_offset + sizeof(T_HMTFILE_HEADER2) + sizeof(T_HMTFILE_TEXTURE_HEADER) * i))->tex_format.unknown0); printf("[DBG] > Texture unknown0: 0x%X\n", ((T_HMTFILE_TEXTURE_HEADER *)(pMemfile + pHmt->texture_offset + sizeof(T_HMTFILE_HEADER2) + sizeof(T_HMTFILE_TEXTURE_HEADER) * i))->tex_format.unknown0);
if (((T_HMTFILE_TEXTURE_HEADER *)(pMemfile + pHmt->texture_offset + sizeof(T_HMTFILE_HEADER2) + sizeof(T_HMTFILE_TEXTURE_HEADER) * i))->tex_format.reserved0 != 1) if (((T_HMTFILE_TEXTURE_HEADER *)(pMemfile + pHmt->texture_offset + sizeof(T_HMTFILE_HEADER2) + sizeof(T_HMTFILE_TEXTURE_HEADER) * i))->tex_format.reserved0 != 1)
printf("[DBG] > Texture: Always 1 different.\n"); printf("[DBG] > Texture: Always 1 different.\n");
printf("[DBG] > Texture palette offset: 0x%X\n", pHmt->textures[i].palette_offset); printf("[DBG] > Texture palette offset: 0x%X\n", palette_offset);
printf("[DBG] > Texture pixels offset: 0x%X\n", pHmt->textures[i].pixels_offset); printf("[DBG] > Texture pixels offset: 0x%X\n", pixels_offset);
} }
// Retrieve palette datas from HMT file // Retrieve palette datas from HMT file
@ -278,7 +296,7 @@ static unsigned short ExtractTextures(T_RSPTEXTURE_HMT* pHmt, const MEMFILE pMem
case 256: case 256:
_palette = (T_R8G8B8 *)realloc(_palette, sizeof(T_R8G8B8) * pHmt->textures[i].palette_entries); _palette = (T_R8G8B8 *)realloc(_palette, sizeof(T_R8G8B8) * pHmt->textures[i].palette_entries);
if (_palette) if (_palette)
memcpy(_palette, pMemfile + pHmt->textures[i].palette_offset, sizeof(T_R8G8B8) * pHmt->textures[i].palette_entries); memcpy(_palette, pMemfile + palette_offset, sizeof(T_R8G8B8) * pHmt->textures[i].palette_entries);
else return RSPLIB_ERROR_MEMORY; else return RSPLIB_ERROR_MEMORY;
break; break;
default: default:
@ -289,7 +307,7 @@ static unsigned short ExtractTextures(T_RSPTEXTURE_HMT* pHmt, const MEMFILE pMem
//TODO: better approach? //TODO: better approach?
_samples = (T_SAMPLE *)realloc(_samples, pHmt->textures[i].width * pHmt->textures[i].height * pHmt->textures[i].sample_bits / 8); _samples = (T_SAMPLE *)realloc(_samples, pHmt->textures[i].width * pHmt->textures[i].height * pHmt->textures[i].sample_bits / 8);
if (_samples) { if (_samples) {
memcpy(_samples, pMemfile + pHmt->textures[i].pixels_offset, pHmt->textures[i].width * pHmt->textures[i].height * pHmt->textures[i].sample_bits / 8); memcpy(_samples, pMemfile + pixels_offset, pHmt->textures[i].width * pHmt->textures[i].height * pHmt->textures[i].sample_bits / 8);
//if (pHmt->textures[i].type == 2) memcpy(pHmt->textures[i].samples, pMemfile + pHmt->textures[i].pixels_offset, pHmt->textures[i].width * pHmt->textures[i].height * pHmt->textures[i].sample_bits / (8 * 4)); //TODO: manage texture type 2 //if (pHmt->textures[i].type == 2) memcpy(pHmt->textures[i].samples, pMemfile + pHmt->textures[i].pixels_offset, pHmt->textures[i].width * pHmt->textures[i].height * pHmt->textures[i].sample_bits / (8 * 4)); //TODO: manage texture type 2
} else return RSPLIB_ERROR_MEMORY; } else return RSPLIB_ERROR_MEMORY;

View File

@ -46,10 +46,10 @@ typedef struct PACK hmtfile_material {
unsigned short type; // 1 - Material with texture / 2 - Material without texture unsigned short type; // 1 - Material with texture / 2 - Material without texture
unsigned short texture_index; unsigned short texture_index;
float reserved0; // misc. float reserved0; // misc. Diffuse? Transparent?
float reserved1; // Always 1.0f float reserved1; // Always 1.0f Ambient?
unsigned int reserved2; // Zero unsigned int reserved2; // Zero Specular?
unsigned int reserved3; // 0x0A unsigned int reserved3; // 0x0A
unsigned char name[16]; unsigned char name[16];

View File

@ -0,0 +1,87 @@
# Set a variable with CMake code which:
# Creates a symlink from src to dest (if possible) or alternatively
# copies if different.
include(CMakeParseArguments)
function(create_symlink DEST_FILE)
cmake_parse_arguments(S "" "FILE;TARGET" "" ${ARGN})
if(NOT S_TARGET AND NOT S_FILE)
message(FATAL_ERROR "create_symlink: Missing TARGET or FILE argument")
endif()
if(S_TARGET AND S_FILE)
message(FATAL_ERROR "create_symlink: Both source file ${S_FILE} and build target ${S_TARGET} arguments are present; can only have one.")
endif()
if(S_FILE)
# If we don't need to symlink something that's coming from a build target,
# we can go ahead and symlink/copy at configure time.
if(CMAKE_HOST_WIN32 AND NOT CYGWIN)
execute_process(
COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${S_FILE} ${DEST_FILE}
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
else()
execute_process(
COMMAND ${CMAKE_COMMAND} -E create_symlink ${S_FILE} ${DEST_FILE}
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
endif()
endif()
if(S_TARGET)
# We need to use generator expressions, which can be a bit tricky, so for
# simplicity make the symlink a POST_BUILD step and use the TARGET
# signature of add_custom_command.
if(CMAKE_HOST_WIN32 AND NOT CYGWIN)
add_custom_command(TARGET ${S_TARGET} POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy_if_different $<TARGET_LINKER_FILE_NAME:${S_TARGET}> $<TARGET_LINKER_FILE_DIR:${S_TARGET}>/${DEST_FILE})
else()
add_custom_command(TARGET ${S_TARGET} POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E create_symlink $<TARGET_LINKER_FILE_NAME:${S_TARGET}> $<TARGET_LINKER_FILE_DIR:${S_TARGET}>/${DEST_FILE})
endif()
endif()
endfunction()
function(create_lib_symlink DEST_FILE)
cmake_parse_arguments(S "" "FILE;TARGET" "" ${ARGN})
if(NOT S_TARGET AND NOT S_FILE)
message(FATAL_ERROR "create_symlink: Missing TARGET or FILE argument")
endif()
if(S_TARGET AND S_FILE)
message(FATAL_ERROR "create_symlink: Both source file ${S_FILE} and build target ${S_TARGET} arguments are present; can only have one.")
endif()
if(S_FILE)
# If we don't need to symlink something that's coming from a build target,
# we can go ahead and symlink/copy at configure time.
if(CMAKE_HOST_WIN32 AND NOT CYGWIN)
execute_process(
COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${S_FILE} ${DEST_FILE}
WORKING_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
else()
execute_process(
COMMAND ${CMAKE_COMMAND} -E create_symlink ${S_FILE} ${DEST_FILE}
WORKING_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
endif()
endif()
if(S_TARGET)
# We need to use generator expressions, which can be a bit tricky, so for
# simplicity make the symlink a POST_BUILD step and use the TARGET
# signature of add_custom_command.
if(CMAKE_HOST_WIN32 AND NOT CYGWIN)
add_custom_command(TARGET ${S_TARGET} POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/$<TARGET_LINKER_FILE_NAME:${S_TARGET}> $<TARGET_LINKER_FILE_DIR:${S_TARGET}>/${DEST_FILE})
else()
add_custom_command(TARGET ${S_TARGET} POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E create_symlink ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/$<TARGET_LINKER_FILE_NAME:${S_TARGET}> $<TARGET_LINKER_FILE_DIR:${S_TARGET}>/${DEST_FILE})
endif()
endif()
endfunction()

View File

@ -1,8 +0,0 @@
SET(CMAKE_SYSTEM_NAME Windows)
IF("${GNU_HOST}" STREQUAL "")
SET(GNU_HOST i586-mingw32msvc)
ENDIF()
# Prefix detection only works with compiler id "GNU"
SET(CMAKE_C_COMPILER ${GNU_HOST}-gcc)
# CMake doesn't automatically look for prefixed 'windres', do it manually:
SET(CMAKE_RC_COMPILER ${GNU_HOST}-windres)

126
conanfile.py Normal file
View File

@ -0,0 +1,126 @@
import os
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake
from conan.tools.files import copy
from conan.tools.scm import Git, Version
required_conan_version = ">=2.3"
class rse_texture(ConanFile):
name = "rsptexturelib"
package_type = "library"
version = "2.1.0"
revision_mode = "scm"
license = "GPL-3.0"
author = "JackCarterSmith <jackcartersmith@jcsmith.fr>"
url = "https://git.jcsmith.fr/JCS-Prod/RSE-Texture"
description = "Rogue Squadron 3D (PC) game textures files (HMT) extractor"
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps"
options = {
"shared": [True, False],
"tools": [True, False],
"fPIC": [True, False]
}
default_options = {
"shared": True,
"tools": False,
"fPIC": True
}
@property
def _is_msvc(self):
return str(self.settings.compiler) in ["Visual Studio", "msvc"]
#def validate(self):
# if self.settings.os == "Macos":
# raise ConanInvalidConfiguration("MacOS not supported")
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def configure(self):
self.options["libpng"].shared = True
self.options["libpng"].sse = True
if self.options.shared:
self.options.rm_safe("fPIC")
def requirements(self):
if self.options.tools:
self.requires("zlib/1.3.1")
self.requires("libpng/1.6.43")
def source(self):
git = Git(self)
cargs = ['--single-branch', '--recursive', '--depth', '1', '--branch', 'v' + self.version]
git.clone(url="https://git.jcsmith.fr/JCS-Prod/RSE-Texture.git", target=".", args=cargs)
# def _patch(self):
# replace_in_file(self, os.path.join(self.source_folder, "RSPTextureLib", "CMakeLists.txt"),
# 'set_target_properties(rsp-texture-libstatic PROPERTIES OUTPUT_NAME "${RSP_TEXTURE_LIB_NAME}_static")',
# 'set_target_properties(rsp-texture-libstatic PROPERTIES OUTPUT_NAME "${RSP_TEXTURE_LIB_NAME}")')
def export_sources(self):
copy(self, "CMakeLists.txt", self.recipe_folder, self.export_sources_folder)
# def layout(self):
# cmake_layout(self, src_folder='.', build_folder='build')
def generate(self):
tc = CMakeToolchain(self)
tc.cache_variables["RSPTEXTURE_SHARED"] = self.options.shared
tc.cache_variables["RSPTEXTURE_STATIC"] = not self.options.shared
tc.cache_variables["BUILD_TOOLS"] = self.options.tools
#tc.cache_variables["BUILD_DEBUG"] = self.settings.build_type == "Debug"
tc.generate()
#cmdeps = CMakeDeps(self)
#cmpdeps.set_property("zlib", "cmake_find_mode", "both")
#cmpdeps.set_property("libpng", "cmake_find_mode", "both")
#if self.options.shared:
#cmdeps.configuration = "ReleaseShared"
#cmdeps.generate()
for dep in self.dependencies.values():
if len(dep.cpp_info.bindirs) > 0:
if self.settings.os == "Windows":
if self._is_msvc:
copy(self, "*.dll", dep.cpp_info.bindirs[0], os.path.join(self.build_folder, "bin", str(self.settings.build_type)))
else:
copy(self, "*.dll", dep.cpp_info.bindirs[0], os.path.join(self.build_folder, "bin"))
else:
copy(self, "*.so", dep.cpp_info.bindirs[0], os.path.join(self.build_folder, "bin"))
def build(self):
cmbuilder = CMake(self)
#self._patch()
cmbuilder.configure()
cmbuilder.build()
def package(self):
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
copy(self, pattern="*.h", src=os.path.join(self.source_folder, "include"), dst=os.path.join(self.package_folder, "include"))
copy(self, pattern="*.a", src=self.build_folder, dst=os.path.join(self.package_folder, "lib"), keep_path=False)
copy(self, pattern="*.so", src=self.build_folder, dst=os.path.join(self.package_folder, "lib"), keep_path=False)
copy(self, pattern="*.lib", src=self.build_folder, dst=os.path.join(self.package_folder, "lib"), keep_path=False)
copy(self, pattern="*.dll", src=self.build_folder, dst=os.path.join(self.package_folder, "bin"), keep_path=False)
def package_info(self):
self.cpp_info.set_property("cmake_file_name", "RSETexture")
self.cpp_info.set_property("cmake_target_name", "RSETexture")
self.cpp_info.set_property("cmake_module_target_name", "RSETexture::RSETexture")
self.cpp_info.set_property("cmake_find_mode", "both")
self.cpp_info.names["cmake_find_package"] = "RSETexture"
self.cpp_info.names["cmake_find_package_multi"] = "RSETexture"
self.cpp_info.includedirs = ["include"]
prefix = "lib" if self._is_msvc else ""
#suffix = "d" if self.settings.build_type == "Debug" else ""
suffix = ""
major_min_version = f"{Version(self.version).major}{Version(self.version).minor}"
self.cpp_info.libs = ["{}RSETexture{}{}".format(prefix, major_min_version, suffix)]

View File

@ -1,13 +0,0 @@
[requires]
zlib/1.2.12
libpng/1.6.37
[generators]
cmake
cmake_find_package
[options]
libpng:shared=True
[imports]
bin, *.dll -> ./bin