diff --git a/recipes/cppcommon/all/CMakeLists.txt b/recipes/cppcommon/all/CMakeLists.txt new file mode 100644 index 0000000000000..6ba47d078b389 --- /dev/null +++ b/recipes/cppcommon/all/CMakeLists.txt @@ -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) diff --git a/recipes/cppcommon/all/conandata.yml b/recipes/cppcommon/all/conandata.yml new file mode 100644 index 0000000000000..05d933207f704 --- /dev/null +++ b/recipes/cppcommon/all/conandata.yml @@ -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" diff --git a/recipes/cppcommon/all/conanfile.py b/recipes/cppcommon/all/conanfile.py new file mode 100644 index 0000000000000..9a7dfdb64411a --- /dev/null +++ b/recipes/cppcommon/all/conanfile.py @@ -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"] diff --git a/recipes/cppcommon/all/patches/00001-update-cmakelists.patch b/recipes/cppcommon/all/patches/00001-update-cmakelists.patch new file mode 100644 index 0000000000000..4429b5fee77ed --- /dev/null +++ b/recipes/cppcommon/all/patches/00001-update-cmakelists.patch @@ -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 $ DESTINATION "${PROJECT_SOURCE_DIR}/bin") + endforeach() diff --git a/recipes/cppcommon/all/patches/00002-fix-cross-platform-issues.patch b/recipes/cppcommon/all/patches/00002-fix-cross-platform-issues.patch new file mode 100644 index 0000000000000..bc6b11ae5e02c --- /dev/null +++ b/recipes/cppcommon/all/patches/00002-fix-cross-platform-issues.patch @@ -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(_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 diff --git a/recipes/cppcommon/all/test_package/CMakeLists.txt b/recipes/cppcommon/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..ba1e21ea8636c --- /dev/null +++ b/recipes/cppcommon/all/test_package/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.1) +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) diff --git a/recipes/cppcommon/all/test_package/conanfile.py b/recipes/cppcommon/all/test_package/conanfile.py new file mode 100644 index 0000000000000..4903f1a7e8fa0 --- /dev/null +++ b/recipes/cppcommon/all/test_package/conanfile.py @@ -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) diff --git a/recipes/cppcommon/all/test_package/test_package.cpp b/recipes/cppcommon/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..a31fc8ff7e3f3 --- /dev/null +++ b/recipes/cppcommon/all/test_package/test_package.cpp @@ -0,0 +1,56 @@ +#include "threads/thread.h" +#include "system/uuid.h" +#include "system/environment.h" +#include "time/timespan.h" +#include "system/dll.h" +#include "system/stack_trace.h" +#include "system/stack_trace_manager.h" + +#include "interface/interface.h" + +#include +#include +#include +#include + +void function1() +{ + std::cout << "Thread Id: " << __THREAD__ << std::endl; + std::cout << "Stack trace: " << std::endl << __STACK__ << std::endl; +} + +void function2() +{ + function1(); +} + +void function3() +{ + function2(); +} + +int main() +{ + // Initialize stack trace manager of the current process + CppCommon::StackTraceManager::Initialize(); + + // Show the stack trace from the main thread + function3(); + + // Show the stack trace from the child thread + std::thread(function3).join(); + + // Cleanup stack trace manager of the current process + CppCommon::StackTraceManager::Cleanup(); + + CppCommon::Thread::Yield(); + CppCommon::UUID id; + CppCommon::Timespan span; + + using namespace CppCommon; + + DLL plugin; + std::cout << std::boolalpha << plugin.IsLoaded() << "\n"; + plugin.Load("plugin-function"); + std::cout << plugin.IsLoaded(); +} diff --git a/recipes/cppcommon/config.yml b/recipes/cppcommon/config.yml new file mode 100644 index 0000000000000..082768aa4dd38 --- /dev/null +++ b/recipes/cppcommon/config.yml @@ -0,0 +1,5 @@ +versions: + "1.0.0.0": + folder: all + "cci.20201104": + folder: all