Final work on Conan v2 support
This commit is contained in:
parent
0c8282ab5d
commit
e03f3436a6
31
README.md
31
README.md
@ -44,26 +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.
|
||||
|
||||
- [zlib](https://www.zlib.net/) (1.2.13)
|
||||
- [libpng](http://www.libpng.org/pub/png/libpng.html) (1.6.40)
|
||||
- [zlib](https://www.zlib.net/) (1.3.1)
|
||||
- [libpng](http://www.libpng.org/pub/png/libpng.html) (1.6.43)
|
||||
|
||||
### Compiling
|
||||
|
||||
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 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).
|
||||
|
||||
```shell
|
||||
conan install -of build . --build=missing -pr:b=default -pr:h=default
|
||||
cd build
|
||||
cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles"
|
||||
cmake --build .
|
||||
conan install . -of build -b missing -s build_type=Release -o tools=True -pr:b=default -pr:h=default
|
||||
cmake --preset conan-release -G "Unix Makefiles"
|
||||
cmake --build --preset conan-release
|
||||
```
|
||||
|
||||
If your CMake<3.23, you should use this command for generation instead of preset one:
|
||||
|
||||
`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"`
|
||||
|
||||
Beware to use the same release/debug configuration with CMake using Conan! Adjust CMake preset or Conan configuration if necessary.
|
||||
|
||||
On Windows environment, you can use MinGW `-G "MinGW Makefiles"` or Ninja `-G "Ninja"` as CMake generator.
|
||||
|
||||
### Compiling (HARDCORE)
|
||||
### Compiling (options)
|
||||
|
||||
There are a few configurable build options:
|
||||
|
||||
- RSPTEXTURE_SHARED Enable the build of shared version of the library ("shared" conan option)
|
||||
- RSPTEXTURE_STATIC Enable the build of static version of the library ("shared" conan option)
|
||||
- BUILD_TOOLS Enable the build of the standalone tools (necessary to use the lib directly) ("tools" conan option)
|
||||
|
||||
### Compiling (old-way)
|
||||
|
||||
If you want to do it manually without Conan, you will probably need to specify the dependency flags for CMake. Ex:
|
||||
|
||||
`cmake.exe -D"ZLIB_INCLUDE_DIR=zlib/1.2.13/include" -D"ZLIB_LIBRARY=zlib/1.2.13/lib/libzlib.dll.a" -D"PNG_PNG_INCLUDE_DIR=libpng/1.6.40/include" -D"PNG_LIBRARY=libpng/1.6.40/lib/libpng.dll.a" . -G "MinGW Makefiles"`
|
||||
`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.
|
||||
|
120
conanfile.py
Normal file
120
conanfile.py
Normal file
@ -0,0 +1,120 @@
|
||||
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 = "RSETexture"
|
||||
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 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", "RSPTexture")
|
||||
self.cpp_info.set_property("cmake_target_name", "RSPTexture")
|
||||
self.cpp_info.set_property("cmake_module_target_name", "RSPTexture::RSPTexture")
|
||||
self.cpp_info.set_property("cmake_find_mode", "both")
|
||||
|
||||
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 = ["{}RSPTexture{}{}".format(prefix, major_min_version, suffix)]
|
@ -1,13 +0,0 @@
|
||||
[requires]
|
||||
zlib/1.2.13
|
||||
libpng/1.6.40
|
||||
|
||||
[generators]
|
||||
CMakeDeps
|
||||
CMakeToolchain
|
||||
|
||||
[options]
|
||||
libpng/*:shared=True
|
||||
|
||||
[imports]
|
||||
bin, *.dll -> ./bin
|
Loading…
x
Reference in New Issue
Block a user