Skip to content

Commit

Permalink
init (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
liss-h authored Sep 7, 2023
1 parent 0b4d740 commit a88058c
Show file tree
Hide file tree
Showing 14 changed files with 595 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/publish-conan-branch-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Publish Conan branch package
on: [ push ]

concurrency:
group: publish-conan-branch-package-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
publish-conan-branch-package:
uses: dice-group/cpp-conan-release-reusable-workflow/.github/workflows/publish-conan-branch-package.yml@main
with:
public_artifactory: true
os: ubuntu-22.04
compiler: clang-14
cmake-version: 3.22.6
conan-options: -o boost:header_only=True
secrets:
CONAN_USER: ${{ secrets.CONAN_USER }}
CONAN_PW: ${{ secrets.CONAN_PW }}
26 changes: 26 additions & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Publish Release

on:
workflow_run:
workflows: [ "Publish Conan branch package" ]
branches: [ main ]
types:
- completed


concurrency:
group: publish-release-${{ github.workflow }}-${{ github.ref }}

jobs:
publish-release:
uses: dice-group/cpp-conan-release-reusable-workflow/.github/workflows/publish-release.yml@main
with:
public_artifactory: false
os: ubuntu-22.04
compiler: clang-14
cmake-version: 3.22.6
conan-version: 1.59
conan-options: -o boost:header_only=True
secrets:
CONAN_USER: ${{ secrets.CONAN_USER }}
CONAN_PW: ${{ secrets.CONAN_PW }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/
cmake-build*
58 changes: 58 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
cmake_minimum_required(VERSION 3.17)
project(metall-ffi VERSION 0.1.0)

include(cmake/boilerplate_init.cmake)
boilerplate_init()

OPTION(USE_CONAN "If available, use conan to retrieve dependencies." ON)
if (IS_TOP_LEVEL AND USE_CONAN)
include(cmake/conan_cmake.cmake)
if (PROJECT_IS_TOP_LEVEL AND BUILD_TESTING)
set(CONAN_HYPERTRIE_WITH_TEST_DEPS "True")
else()
set(CONAN_HYPERTRIE_WITH_TEST_DEPS "False")
endif()
set(CONAN_OPTIONS "with_test_deps=${CONAN_HYPERTRIE_WITH_TEST_DEPS}")
install_packages_via_conan("${CMAKE_SOURCE_DIR}/conanfile.py" "${CONAN_OPTIONS};boost:header_only=True")
endif ()

find_package(Metall REQUIRED)
find_package(dice-sparse-map REQUIRED)

add_library(metall-ffi
src/dice/ffi/metall.cpp
)

add_library(metall-ffi::metall-ffi ALIAS metall-ffi)

target_include_directories(
metall-ffi
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
)

target_link_libraries(metall-ffi
PUBLIC
Metall::Metall
dice-sparse-map::dice-sparse-map
)

set_target_properties(metall-ffi PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
CXX_STANDARD 20
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
)

if (IS_TOP_LEVEL)
include(cmake/install_library.cmake)
install_cpp_library(metall-ffi src)
endif ()

if (BUILD_TESTING AND IS_TOP_LEVEL)
message("Tests are configured to be build.")
include(CTest)
enable_testing()
add_subdirectory(tests)
endif ()
35 changes: 35 additions & 0 deletions cmake/boilerplate_init.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
macro(boilerplate_init)
## enforce standard compliance
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_EXTENSIONS OFF)

## C++ compiler flags
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Wall")
else ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wold-style-cast -Wcast-qual")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")

if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# -Wdangling-reference seems to have false positives atm
# We run sanitizers in the CI anyway, so should be fine
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-dangling-reference")
endif ()
endif ()

## C++ language visibility configuration
if (NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET AND
NOT DEFINED CMAKE_VISIBILITY_INLINES_HIDDEN)
set(CMAKE_CXX_VISIBILITY_PRESET default)
set(CMAKE_VISIBILITY_INLINES_HIDDEN NO)
endif ()

# conan requires cmake build type to be specified and it is generally a good idea
if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/CMakeCache.txt)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
endif ()
endif ()

string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" IS_TOP_LEVEL)
endmacro()
26 changes: 26 additions & 0 deletions cmake/conan_cmake.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
macro(install_packages_via_conan conanfile conan_options)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})


if (NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/0.18.1/conan.cmake"
"${CMAKE_BINARY_DIR}/conan.cmake"
TLS_VERIFY ON)
endif ()
include(${CMAKE_BINARY_DIR}/conan.cmake)

conan_cmake_autodetect(settings)
conan_check(VERSION 1 DETECT_QUIET)
if (CONAN_CMD)
conan_cmake_install(PATH_OR_REFERENCE ${conanfile}
BUILD missing
SETTINGS ${settings}
OPTIONS "${conan_options}"
ENV_HOST "CC=${CMAKE_C_COMPILER};CXX=${CMAKE_CXX_COMPILER}")
else ()
message(WARNING "No conan executable was found. Dependency retrieval via conan is disabled. System dependencies will be used if available.")
endif ()
endmacro()
46 changes: 46 additions & 0 deletions cmake/install_library.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

function(install_cpp_library TARGET_NAME INCLUDE_PATH)
if (NOT ${ARGC} GREATER_EQUAL 2)
message(
FATAL_ERROR
"you did not specify the target and the include path in the parameter!")
endif ()

target_include_directories(
${TARGET_NAME} PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

install(TARGETS ${TARGET_NAME} ${ARGN}
EXPORT ${TARGET_NAME}-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

write_basic_package_version_file("${TARGET_NAME}-config-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY ExactVersion)

configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/lib-config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
# here we have two possibilities: either CMAKE_INSTALL_DATAROOTDIR (share) or CMAKE_INSTALL_LIBDIR (lib/lib64)
# we just have to be consistent for one target

install(
EXPORT ${PROJECT_NAME}-targets
FILE ${PROJECT_NAME}-targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)

install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${INCLUDE_PATH}/
DESTINATION include
FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h")
endfunction()
4 changes: 4 additions & 0 deletions cmake/lib-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
check_required_components("@PROJECT_NAME@")
67 changes: 67 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import os
import re

from conan.tools.cmake import CMake

from conan import ConanFile

from conan.tools.files import load, copy, rmdir


class Recipe(ConanFile):
name = "metall-ffi"
version = None

author = "https://github.com/dice-group/metall-ffi"
url = "https://github.com/dice-group/metall-ffi"
description = "FFI for the metall libary"
topics = ("FFI", "persistent memory")

# Binary configuration
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False], "with_test_deps": [True, False]}
default_options = {"shared": False, "fPIC": True, "with_test_deps": False}
exports = "LICENSE",
exports_sources = "src/*", "CMakeLists.txt", "cmake/*"

generators = ("CMakeDeps", "CMakeToolchain")

def requirements(self):
self.requires("metall/0.21")
self.requires("dice-sparse-map/0.2.4")
self.requires("boost/1.81.0") # override to fix dependencies

if self.options.with_test_deps:
self.requires("doctest/2.4.11")


def set_version(self):
if not hasattr(self, 'version') or self.version is None:
cmake_file = load(self, os.path.join(self.recipe_folder, "CMakeLists.txt"))
self.version = re.search(r"project\([^)]*VERSION\s+(\d+\.\d+.\d+)[^)]*\)", cmake_file).group(1)

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

_cmake = None

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.configure(variables={"USE_CONAN": False})

return self._cmake

def build(self):
self._configure_cmake().build()

def package(self):
self._configure_cmake().install()
rmdir(self, os.path.join(self.package_folder, "cmake"))
rmdir(self, os.path.join(self.package_folder, "share"))
copy(self, "LICENSE", src=self.recipe_folder, dst="licenses")

def package_info(self):
self.cpp_info.libs = ["metall-ffi"]
Loading

0 comments on commit a88058c

Please sign in to comment.