Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/cppcommon #3224

Merged
merged 20 commits into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions recipes/cppcommon/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.4)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

if(WIN32 AND BUILD_SHARED_LIBS)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()

add_subdirectory(source_subfolder)
17 changes: 17 additions & 0 deletions recipes/cppcommon/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
sources:
"1.0.0.0":
url: "https://github.com/chronoxor/CppCommon/archive/1.0.0.0.tar.gz"
sha256: "d6124dd4cd430e5f10c2942ff02a95636369875b652e66a499b01f1fb3ecfd6d"
"cci.20201104":
url: "https://github.com/chronoxor/CppCommon/archive/cacfa9554d367467808663d9d5a695933ae566bb.tar.gz"
sha256: "d2e717798e1668c831ee977763eaff7413ef48e6e0914a6322c9918016092048"

patches:
"1.0.0.0":
- patch_file: "patches/00001-update-cmakelists.patch"
base_path: "source_subfolder"
- patch_file: "patches/00002-fix-cross-platform-issues.patch"
base_path: "source_subfolder"
"cci.20201104":
- patch_file: "patches/00001-update-cmakelists.patch"
base_path: "source_subfolder"
99 changes: 99 additions & 0 deletions recipes/cppcommon/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import os
import glob


class CppCommon(ConanFile):
name = "cppcommon"
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/chronoxor/CppCommon"
description = "C++ Common Library contains reusable components and patterns" \
" for error and exceptions handling, filesystem manipulations, math," \
" string format and encoding, shared memory, threading, time management" \
" and others."
topics = ("conan", "utils", "library")
settings = "os", "compiler", "build_type", "arch"
options = {"fPIC": [True, False], "shared": [True, False]}
default_options = {"fPIC": True, "shared": False}
exports_sources = ["patches/**", "CMakeLists.txt"]
generators = "cmake", "cmake_find_package"
_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

@property
def _compilers_minimum_version(self):
return {
"apple-clang": 10,
"clang": 6,
"gcc": 7,
"Visual Studio": 16,
}

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

def configure(self):
if self.settings.compiler == "Visual Studio" and self.settings.arch == "x86":
raise ConanInvalidConfiguration("Visual Studio x86 builds are not supported.")

if self.options.shared:
del self.options.fPIC

if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, "17")

minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version:
if tools.Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration("cppcommon requires C++17, which your compiler does not support.")
else:
self.output.warn("cppcommon requires C++17. Your compiler is unknown. Assuming it supports C++17.")

def requirements(self):
self.requires("fmt/7.1.2")
if self.settings.os == "Linux":
self.requires("libuuid/1.0.3")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = glob.glob("CppCommon-*")[0]
os.rename(extracted_dir, self._source_subfolder)

def _configure_cmake(self):
if not self._cmake:
self._cmake = CMake(self)
self._cmake.definitions["CPPCOMMON_MODULE"] = "OFF"
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
cmake.build()

def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()
self.copy(pattern="*.h", dst="include", src=os.path.join(self._source_subfolder, "include"))
self.copy(pattern="*.inl", dst="include", src=os.path.join(self._source_subfolder, "include"))
self.copy(pattern="*.h", dst=os.path.join("include", "plugins"), src=os.path.join(self._source_subfolder, "plugins"))

def package_info(self):
self.cpp_info.libs = tools.collect_libs(self)
self.cpp_info.includedirs.append(os.path.join("include", "plugins"))
if self.settings.os == "Linux":
self.cpp_info.system_libs = ["pthread", "rt", "dl", "m"]
if self.settings.os == "Windows":
self.cpp_info.system_libs = ["userenv", "rpcrt4"]
128 changes: 128 additions & 0 deletions recipes/cppcommon/all/patches/00001-update-cmakelists.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index dcd57785b..2dde9577f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -18,13 +18,13 @@ if(DOXYGEN_FOUND)
endif()

# CMake module path
-set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
+# set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

# Compiler features
-include(SetCompilerFeatures)
-include(SetCompilerWarnings)
-include(SetPlatformFeatures)
-include(SystemInformation)
+# include(SetCompilerFeatures)
+# include(SetCompilerWarnings)
+# include(SetPlatformFeatures)
+# include(SystemInformation)

# External packages
find_package(Threads REQUIRED)
@@ -32,16 +32,15 @@ if(UNIX AND NOT APPLE AND NOT MSYS)
find_package(LibBFD)
find_package(LibDL)
find_package(LibRT)
- find_package(LibUUID)
+ find_package(libuuid) #FIXME: CCI does not generate correctly #3441
endif()
if(WIN32 OR MSYS)
find_package(DbgHelp)
find_package(RPC)
- find_package(Userenv)
endif()

# Modules
-add_subdirectory("modules")
+# add_subdirectory("modules")

# Link libraries
list(APPEND LINKLIBS Threads::Threads)
@@ -49,17 +48,18 @@ if(UNIX AND NOT APPLE AND NOT MSYS)
list(APPEND LINKLIBS ${LIBBFD_LIBRARIES})
list(APPEND LINKLIBS ${LIBDL_LIBRARIES})
list(APPEND LINKLIBS ${LIBRT_LIBRARIES})
- list(APPEND LINKLIBS ${LIBUUID_LIBRARIES})
+ list(APPEND LINKLIBS CONAN_PKG::libuuid)
endif()
if(WIN32 OR MSYS)
list(APPEND LINKLIBS ${DBGHELP_LIBRARIES})
list(APPEND LINKLIBS ${RPC_LIBRARIES})
- list(APPEND LINKLIBS ${USERENV_LIBRARIES})
+ list(APPEND LINKLIBS userenv)
+ list(APPEND LINKLIBS rpcrt4)
list(APPEND LINKLIBS ${LIBVLD_LIBRARIES})
endif()

# System directories
-include_directories(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/modules")
+# include_directories(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/modules")
include_directories(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/plugins")

# Library
@@ -68,8 +68,9 @@ file(GLOB_RECURSE LIB_INLINE_FILES "include/*.inl")
file(GLOB_RECURSE LIB_SOURCE_FILES "source/*.cpp")
add_library(cppcommon ${LIB_HEADER_FILES} ${LIB_INLINE_FILES} ${LIB_SOURCE_FILES})
set_target_properties(cppcommon PROPERTIES COMPILE_FLAGS "${PEDANTIC_COMPILE_FLAGS}" FOLDER "libraries")
-target_include_directories(cppcommon PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" PUBLIC ${vld})
-target_link_libraries(cppcommon ${LINKLIBS} fmt)
+target_include_directories(cppcommon PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
+target_compile_features(cppcommon PUBLIC cxx_std_17)
+target_link_libraries(cppcommon PUBLIC ${LINKLIBS} CONAN_PKG::fmt)
list(APPEND INSTALL_TARGETS cppcommon)
list(APPEND LINKLIBS cppcommon)

@@ -91,7 +92,7 @@ if(NOT CPPCOMMON_MODULE)
list(APPEND INSTALL_TARGETS_PDB ${PLUGIN_TARGET})
endforeach()

- # Examples
+if(FALSE)
file(GLOB EXAMPLE_HEADER_FILES "examples/*.h")
file(GLOB EXAMPLE_INLINE_FILES "examples/*.inl")
file(GLOB EXAMPLE_SOURCE_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/examples" "examples/*.cpp")
@@ -105,8 +106,8 @@ if(NOT CPPCOMMON_MODULE)
list(APPEND INSTALL_TARGETS ${EXAMPLE_TARGET})
list(APPEND INSTALL_TARGETS_PDB ${EXAMPLE_TARGET})
endforeach()
-
- # Benchmarks
+endif()
+if(FALSE)
file(GLOB BENCHMARK_HEADER_FILES "performance/*.h")
file(GLOB BENCHMARK_INLINE_FILES "performance/*.inl")
file(GLOB BENCHMARK_SOURCE_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/performance" "performance/*.cpp")
@@ -120,8 +121,8 @@ if(NOT CPPCOMMON_MODULE)
list(APPEND INSTALL_TARGETS ${BENCHMARK_TARGET})
list(APPEND INSTALL_TARGETS_PDB ${BENCHMARK_TARGET})
endforeach()
-
- # Tests
+endif()
+if(FALSE)
file(GLOB TESTS_HEADER_FILES "tests/*.h")
file(GLOB TESTS_INLINE_FILES "tests/*.inl")
file(GLOB TESTS_SOURCE_FILES "tests/*.cpp")
@@ -136,15 +137,15 @@ if(NOT CPPCOMMON_MODULE)
# CTest
enable_testing()
add_test(cppcommon-tests cppcommon-tests --durations yes --order lex)
-
+endif()
# Install
install(TARGETS ${INSTALL_TARGETS}
- RUNTIME DESTINATION "${PROJECT_SOURCE_DIR}/bin"
- LIBRARY DESTINATION "${PROJECT_SOURCE_DIR}/bin"
- ARCHIVE DESTINATION "${PROJECT_SOURCE_DIR}/bin")
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib)

# Install *.pdb files
- if(MSVC)
+ if(FALSE)
foreach(INSTALL_TARGET_PDB ${INSTALL_TARGETS_PDB})
install(FILES $<TARGET_PDB_FILE:${INSTALL_TARGET_PDB}> DESTINATION "${PROJECT_SOURCE_DIR}/bin")
endforeach()
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
diff --git a/include/errors/exceptions_handler.h b/include/errors/exceptions_handler.h
index b17e843d2..79ae0fe9b 100644
--- a/include/errors/exceptions_handler.h
+++ b/include/errors/exceptions_handler.h
@@ -69,7 +69,7 @@ private:
const Impl& impl() const noexcept { return reinterpret_cast<Impl const&>(_storage); }

static const size_t StorageSize = 72;
-#if defined(__APPLE__)
+#if defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
static const size_t StorageAlign = 16;
#else
static const size_t StorageAlign = 8;
diff --git a/include/math/math.h b/include/math/math.h
index e40c02330..2178e75f3 100644
--- a/include/math/math.h
+++ b/include/math/math.h
@@ -55,7 +55,10 @@ public:
\param divider - Divider
\return Calculated value of (operant * multiplier / divider) expression
*/
+#if defined(__GNUC__) && defined(__SIZEOF_INT128__) || defined(_MSC_VER)
static uint64_t MulDiv64(uint64_t operant, uint64_t multiplier, uint64_t divider);
+#endif
+
};

/*! \example math_math.cpp Math example */
diff --git a/source/errors/exceptions_handler.cpp b/source/errors/exceptions_handler.cpp
index f16c566c1..cf5eeb02e 100644
--- a/source/errors/exceptions_handler.cpp
+++ b/source/errors/exceptions_handler.cpp
@@ -637,7 +637,7 @@ ExceptionsHandler::ExceptionsHandler()
{
// Check implementation storage parameters
static_assert((sizeof(Impl) <= StorageSize), "ExceptionsHandler::StorageSize must be increased!");
- static_assert((alignof(Impl) == StorageAlign), "ExceptionsHandler::StorageAlign must be adjusted!");
+ static_assert((StorageAlign % alignof(Impl) == 0), "ExceptionsHandler::StorageAlign must be adjusted!");

// Create the implementation instance
new(&_storage)Impl();
diff --git a/source/math/math.cpp b/source/math/math.cpp
index 32c9a9dd1..42818b9ef 100644
--- a/source/math/math.cpp
+++ b/source/math/math.cpp
@@ -14,9 +14,10 @@

namespace CppCommon {

+#if defined(__GNUC__) && defined(__SIZEOF_INT128__) || defined(_MSC_VER)
uint64_t Math::MulDiv64(uint64_t operant, uint64_t multiplier, uint64_t divider)
{
-#if defined(__GNUC__)
+#if defined(__GNUC__) && defined(__SIZEOF_INT128__)
__uint128_t a = operant;
__uint128_t b = multiplier;
__uint128_t c = divider;
@@ -308,5 +309,6 @@ done:
#error MulDiv64 is no supported!
#endif
}
+#endif

} // namespace CppCommon
10 changes: 10 additions & 0 deletions recipes/cppcommon/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.1)
tarc marked this conversation as resolved.
Show resolved Hide resolved
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(${PROJECT_NAME} test_package.cpp)
conan_target_link_libraries(${PROJECT_NAME})

target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17)
16 changes: 16 additions & 0 deletions recipes/cppcommon/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from conans import ConanFile, CMake, tools
import os

class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)