Skip to content

Commit

Permalink
Merge pull request hyperrealm#181 from Lukas-Heiligenbrunner/conanpac…
Browse files Browse the repository at this point in the history
…kage

Conan package build
  • Loading branch information
hyperrealm authored Oct 1, 2021
2 parents e9f8a6a + 23d9cb4 commit 98a52a4
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 12 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/conan.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: build conan package
on: [push, pull_request]
jobs:
build_conan:
strategy:
matrix:
os: [ windows-latest, ubuntu-latest, macos-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.x'
architecture: 'x64'
# install dependencies
- name: install conan
run: pip3 install conan
- name: setup conan
run: |
conan profile new default --detect --force # Generates default profile detecting GCC and sets old ABI
# new ABI version needs to be set on GCC >= 5
- name: set ABI
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
conan profile update settings.compiler.libcxx=libstdc++11 default # Sets libcxx to C++11 ABI
- name: build conan package
run: |
conan create .
70 changes: 70 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from conans import ConanFile, CMake, tools
import os
import re
import textwrap


class LibconfigConan(ConanFile):
name = "libconfig"
license = "GNU LESSER GENERAL PUBLIC LICENSE"
author = """Mark Lindner - Lead developer & maintainer.
Daniel Marjamäki - Enhancements & bugfixes.
Andrew Tytula - Windows port.
Glenn Herteg - Enhancements, bugfixes, documentation corrections.s
Matt Renaud - Enhancements & bugfixes.
JoseLuis Tallon - Enhancements & bugfixes"""
url = "hyperrealm.github.io/libconfig/"
description = "Libconfig is a simple library for processing structured configuration files. " \
"This file format is more compact and more readable than XML. And unlike XML, it is type-aware, " \
"so it is not necessary to do string parsing in application code."
topics = ("libconfig", "structured", "configuration", "xml", "type")
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": False}
generators = "cmake"
exports_sources = "*"
no_copy_source = True

def set_version(self):
configure_ac = tools.load(os.path.join(self.recipe_folder, "configure.ac"))
self.version = next(re.finditer(r"AC_INIT\(libconfig,[ \t]+([0-9.]+),.*", configure_ac)).group(1)

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

def configure(self):
if self.options.shared:
del self.options.fPIC

def build(self):
tools.save(os.path.join(self.build_folder, "CMakeLists.txt"), textwrap.dedent("""\
cmake_minimum_required(VERSION 2.8.12)
project(cmake_wrapper)
include("{}/conanbuildinfo.cmake")
conan_basic_setup()
add_subdirectory("{}" libconfig)
""").format(self.install_folder.replace("\\","/"), self.source_folder.replace("\\","/")))
cmake = CMake(self)
cmake.configure(source_folder=self.build_folder)
cmake.build()

def package(self):
cmake = CMake(self)
cmake.install()

def package_info(self):
# FIXME: `libconfig` is `libconfig::libconfig` in `libconfigConfig.cmake`
# FIXME: `libconfig++` is `libconfig::libconfig++` in `libconfig++Config.cmake`
self.cpp_info.components["libconfig_c"].libs = ["libconfig" if self.settings.compiler == "Visual Studio" else "config"]
if not self.options.shared:
self.cpp_info.components["libconfig_c"].defines = ["LIBCONFIG_STATIC"]
self.cpp_info.components["libconfig_c"].names["cmake_find_package"] = ["libconfig"]
self.cpp_info.components["libconfig_c"].names["cmake_find_package_multi"] = ["libconfig"]
self.cpp_info.components["libconfig_c"].names["pkg_config"] = "libconfig"
self.cpp_info.components["libconfig_cpp"].libs = ["libconfig++" if self.settings.compiler == "Visual Studio" else "config++"]
if not self.options.shared:
self.cpp_info.components["libconfig_cpp"].defines = ["LIBCONFIGXX_STATIC"]
self.cpp_info.components["libconfig_cpp"].names["cmake_find_package"] = ["libconfig++"]
self.cpp_info.components["libconfig_cpp"].names["cmake_find_package_multi"] = ["libconfig++"]
self.cpp_info.components["libconfig_cpp"].names["pg_config"] = "libconfig++"
5 changes: 0 additions & 5 deletions examples/c++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ add_executable(c++_example2 example2.cpp )
add_executable(c++_example3 example3.cpp )
add_executable(c++_example4 example4.cpp )

target_include_directories(c++_example1 PRIVATE ${CMAKE_SOURCE_DIR}/lib)
target_include_directories(c++_example2 PRIVATE ${CMAKE_SOURCE_DIR}/lib)
target_include_directories(c++_example3 PRIVATE ${CMAKE_SOURCE_DIR}/lib)
target_include_directories(c++_example4 PRIVATE ${CMAKE_SOURCE_DIR}/lib)

target_link_libraries(c++_example1 ${libname}++ )
target_link_libraries(c++_example2 ${libname}++ )
target_link_libraries(c++_example3 ${libname}++ )
Expand Down
4 changes: 0 additions & 4 deletions examples/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ add_executable(c_example1 example1.c )
add_executable(c_example2 example2.c )
add_executable(c_example3 example3.c )

target_include_directories(c_example1 PRIVATE ${CMAKE_SOURCE_DIR}/lib)
target_include_directories(c_example2 PRIVATE ${CMAKE_SOURCE_DIR}/lib)
target_include_directories(c_example3 PRIVATE ${CMAKE_SOURCE_DIR}/lib)

target_link_libraries(c_example1 ${libname} )
target_link_libraries(c_example2 ${libname} )
target_link_libraries(c_example3 ${libname} )
8 changes: 8 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ endif()
add_library(${libname} ${libsrc} ${libinc})
add_library(${libname}++ ${libsrc_cpp} ${libinc_cpp})

target_include_directories(${libname} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

target_include_directories(${libname}++ PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

set_target_properties(${libname}
PROPERTIES LINKER_LANGUAGE C
SOVERSION "${libconfig_VERSION_MAJOR}"
Expand Down
4 changes: 1 addition & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ else()
set(libname "config")
endif()

include_directories(${CMAKE_SOURCE_DIR}/lib)

add_executable(libconfig_tests
tests.c
)
Expand All @@ -18,5 +16,5 @@ target_link_libraries(libconfig_tests
add_test(
NAME libconfig_tests
COMMAND libconfig_tests
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/tests
)

0 comments on commit 98a52a4

Please sign in to comment.