Skip to content

Commit

Permalink
Merge pull request #1 from uilianries/b64-2.0.0.1
Browse files Browse the repository at this point in the history
B64 - use cmake and new repo
  • Loading branch information
KGrzeg authored Apr 19, 2023
2 parents 1e3a41d + 5574b37 commit 4e767cd
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 79 deletions.
20 changes: 20 additions & 0 deletions recipes/b64/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.15)
project(b64 LANGUAGES C CXX)

set(BASE64_APP base64)
file(GLOB HEADER_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/include/b64/*.h")
add_library(${PROJECT_NAME} "${CMAKE_CURRENT_SOURCE_DIR}/src/src/cdecode.c" "${CMAKE_CURRENT_SOURCE_DIR}/src/src/cencode.c" ${HEADER_FILES})
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/include")
set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER "${HEADER_FILES}" WINDOWS_EXPORT_ALL_SYMBOLS TRUE)

add_executable(${BASE64_APP} "${CMAKE_CURRENT_SOURCE_DIR}/src/base64/base64.cc")
target_include_directories(${BASE64_APP} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/include")
target_link_libraries(${BASE64_APP} PRIVATE ${PROJECT_NAME})
target_compile_definitions(${BASE64_APP} PRIVATE BUFFERSIZE=16777216)

install(TARGETS ${PROJECT_NAME} ${BASE64_APP}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/b64"
)
6 changes: 3 additions & 3 deletions recipes/b64/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sources:
"1.2.1":
url: "https://sourceforge.net/projects/libb64/files/latest/download"
sha256: "20106f0ba95cfd9c35a13c71206643e3fb3e46512df3e2efb2fdbf87116314b2"
"2.0.0.1":
url: "https://github.com/libb64/libb64/archive/refs/tags/v2.0.0.1.tar.gz"
sha256: "ce8e578a953a591bd4a6f157eec310b9a4c2e6f10ade2fdda6ae6bafaf798b98"
98 changes: 23 additions & 75 deletions recipes/b64/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from conan import ConanFile
from conan.tools.files import get, copy, chdir, replace_in_file
from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps
from conan.tools.microsoft import is_msvc, MSBuild, MSBuildToolchain
from conan.tools.layout import basic_layout
from conan.tools.files import get, copy
from conan.tools.cmake import cmake_layout, CMakeToolchain, CMake
import os


Expand All @@ -16,100 +14,50 @@ class B64Conan(ConanFile):
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://libb64.sourceforge.net/"
topics = ("base64", "codec", "encoder", "decoder")
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"static": [True, False],
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"static": False,
"shared": False,
"fPIC": True,
}

@property
def _msvc_platform(self):
return {
"x86": "Win32",
"x86_64": "Win32",
}[str(self.settings.arch)]

@property
def _msbuild_configuration(self):
return "Debug" if self.settings.build_type == "Debug" else "Release"

@property
def _msvc_directory(self):
return os.path.join(self.source_folder, "base64", "VisualStudioProject");

def _patch_sources_msvc(self):
toolset = MSBuildToolchain(self).toolset
replace_in_file(
self,
os.path.join(self._msvc_directory, "base64.vcxproj"),
"<CharacterSet>Unicode</CharacterSet>",
f"<CharacterSet>Unicode</CharacterSet>\n<PlatformToolset>{toolset}</PlatformToolset>",
)
replace_in_file(
self,
os.path.join(self._msvc_directory, "base64.vcxproj"),
"H:\\builds\\libb64\\working.libb64\\include",
os.path.join(self.source_folder, "include"),
)
def export_sources(self):
copy(self, "CMakeLists.txt", src=self.recipe_folder, dst=self.export_sources_folder)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")
if self.options.shared:
self.options.rm_safe("fPIC")

def layout(self):
basic_layout(self, src_folder="src")
cmake_layout(self, src_folder="src")

def source(self):
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
if is_msvc(self):
tc = MSBuildToolchain(self)
tc.configuration = self._msbuild_configuration
tc.generate()
else:
tc = AutotoolsToolchain(self)
tc.generate()
tc = CMakeToolchain(self)
tc.generate()

def build(self):
if is_msvc(self):
self._patch_sources_msvc()

msbuild = MSBuild(self)
msbuild.platform = self._msvc_platform
msbuild.build_type = self._msbuild_configuration
msbuild.build(os.path.join(self._msvc_directory, "base64.sln"))
else:
with chdir(self, self.source_folder):
autotools = Autotools(self)
autotools.make(target="all_src")
cmake = CMake(self)
cmake.configure(build_script_folder=os.path.join(self.source_folder, os.pardir))
cmake.build()

def package(self):
copy(self, pattern="LICENSE", dst=os.path.join(
self.package_folder, "licenses"), src=self.source_folder)
copy(self, "*.h",
dst=os.path.join(self.package_folder, "include"),
src=os.path.join(self.source_folder, "include"))
copy(self, "*.a",
dst=os.path.join(self.package_folder, "lib"),
src=self.source_folder, keep_path=False)
copy(self, "*.lib",
dst=os.path.join(self.package_folder, "lib"),
src=self.source_folder, keep_path=False)
copy(self, "*.dll",
dst=os.path.join(self.package_folder, "bin"),
src=self.source_folder, keep_path=False)


copy(self, pattern="LICENSE.md", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()

def package_info(self):
self.cpp_info.libs = ["b64"]

# TODO: Only for Conan 1.x legacy - Remove after running Conan 2.x only
self.env_info.PATH = os.path.join(self.package_folder, "bin")
2 changes: 1 addition & 1 deletion recipes/b64/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
versions:
"1.2.1":
"2.0.0.1":
folder: all

0 comments on commit 4e767cd

Please sign in to comment.