diff --git a/CHANGELOG b/CHANGELOG index 9792eb1ad..fbfb4172b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -11,6 +11,7 @@ Current head v.2.1.0 rc - CMake * Remove dead code (#15) * Install external headers due of inline headers (zpp_bits, serializer, std_any) (#34) + * Fix install from external project (#49) - Licensing * Added license and readme to externals (#18) * License headers with MPL 2.0 (#19) diff --git a/CMakeLists.txt b/CMakeLists.txt index 267bdc514..ee8c44d0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -211,7 +211,10 @@ if(HUB_ENABLE_EXAMPLES) add_subdirectory(examples) endif() -add_subdirectory(bin) +option(HUB_ENABLE_BINS "Enable binaries" ON) +if(HUB_ENABLE_BINS) + add_subdirectory(bin) +endif() if(NOT WIN32) # Todo check if cppCheck exe exists on current system diff --git a/bin/CMakeLists.txt b/bin/CMakeLists.txt index d5582f008..6119ca966 100644 --- a/bin/CMakeLists.txt +++ b/bin/CMakeLists.txt @@ -4,30 +4,38 @@ project(bin LANGUAGES CXX) if(TARGET hub) - set(bin_srcs) - foreach(HUB_MODULE ${HUB_MODULES}) - file(GLOB_RECURSE bin_src ${CMAKE_CURRENT_SOURCE_DIR}/${HUB_MODULE}/*.cpp) - list(APPEND bin_srcs ${bin_src}) - endforeach() - - string(REPLACE ".cpp" "" SOURCES_BASENAME "${bin_srcs}") - set(SOURCES_BASENAME ${SOURCES_BASENAME}) - - foreach(name ${SOURCES_BASENAME}) - get_filename_component(basename ${name} NAME) - STRING(REPLACE "bin-" "" basename ${basename}) - set(TARGET_NAME hub-${basename}) - add_executable(${TARGET_NAME} ${name}.cpp) - target_link_libraries(${TARGET_NAME} hub) - - if(WIN32) - if(HUB_BUILD_SHARED AND NOT HUB_BUILD_STATIC) - add_custom_command( - TARGET ${TARGET_NAME} - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ $) + + set(bin_srcs) + foreach(HUB_MODULE ${HUB_MODULES}) + file(GLOB_RECURSE bin_src ${CMAKE_CURRENT_SOURCE_DIR}/${HUB_MODULE}/*.cpp) + list(APPEND bin_srcs ${bin_src}) + endforeach() + + string(REPLACE ".cpp" "" SOURCES_BASENAME "${bin_srcs}") + set(SOURCES_BASENAME ${SOURCES_BASENAME}) + + foreach(name ${SOURCES_BASENAME}) + get_filename_component(basename ${name} NAME) + STRING(REPLACE "bin-" "" basename ${basename}) + set(TARGET_NAME hub-${basename}) + add_executable(${TARGET_NAME} ${name}.cpp) + target_link_libraries(${TARGET_NAME} hub) + + if(WIN32) + if(HUB_BUILD_SHARED AND NOT HUB_BUILD_STATIC) + add_custom_command( + TARGET ${TARGET_NAME} + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ $) + endif() endif() - endif() - endforeach() + + install( + TARGETS ${TARGET_NAME} + EXPORT ${TARGET_NAME} + DESTINATION ${ARCHITECTURE}/bin) + + endforeach() + endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 64fa767b7..6dfeaad43 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.8) find_package(Git) include(GetVersionFromGitTag) +set(HUB_LIBRARIES) set(REQUIRED_LIBS ${HUB_TBB_TARGET}) message(STATUS "${HEADER_MSG} Version: ${${PROJECT_NAME}_VERSION}") @@ -20,7 +21,8 @@ endif() option(HUB_BUILD_STATIC "Build static library" ON) option(HUB_BUILD_SHARED "Build shared library" ON) -# ######################## OS specifics +########################## OS/Compiler Specifics ########################### + if(MINGW) if(CLANG) set(THREADS_PREFER_PTHREAD_FLAG ON) @@ -64,7 +66,8 @@ elseif(UNIX) if(Clang) elseif(GCC) - message(FATAL_ERROR "not supported") + message(WARNING "not tested") + elseif(GNU) else() @@ -79,33 +82,33 @@ if (REQUIRED_LIBS) message(STATUS "${HEADER_MSG} Dependencies: ${REQUIRED_LIBS}") endif() -file(# GLOB - GLOB_RECURSE external_sources ${HUB_EXTERNAL_DIR}/*.cpp ${HUB_EXTERNAL_DIR}/*.c) -file(# GLOB - GLOB_RECURSE external_headers ${HUB_EXTERNAL_DIR}/*.hpp ${HUB_EXTERNAL_DIR}/*.h) +############################# Compile Externals ################################# + +file(GLOB_RECURSE external_sources ${HUB_EXTERNAL_DIR}/*.cpp ${HUB_EXTERNAL_DIR}/*.c) +file(GLOB_RECURSE external_headers ${HUB_EXTERNAL_DIR}/*.hpp ${HUB_EXTERNAL_DIR}/*.h) if(NOT HUB_USE_ZPP_BITS) list(REMOVE_ITEM external_headers ${HUB_EXTERNAL_DIR}/zpp_bits.h) endif() add_library(external OBJECT ${external_headers} ${external_sources}) -target_include_directories( - external - # PUBLIC $ $ # Version.hpp - PRIVATE # PUBLIC - ${HUB_EXTERNAL_DIR}) +target_include_directories(external PRIVATE ${HUB_EXTERNAL_DIR}) if(UNIX) set_property(TARGET external PROPERTY POSITION_INDEPENDENT_CODE ON) # gltfpack endif() install( - DIRECTORY ${HUB_EXTERNAL_DIR}/ - DESTINATION include/ + DIRECTORY ${HUB_EXTERNAL_DIR}/serializer/ + DESTINATION include/external/serializer/ FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h" - PATTERN "*.inl") + PATTERN "*.inl" +) set(SRC_TARGETS) +list(APPEND SRC_TARGETS "$") + +############################# Compile Modules ################################# if(NOT XCODE) # unable to have object files as native build with Xcode @@ -115,12 +118,11 @@ if(NOT XCODE) # unable to have object files as native build with Xcode string(REPLACE "/" "-" TARGET_NAME "${TARGET_NAME}") set(object_sources) - file(# GLOB - GLOB_RECURSE object_sources ${CMAKE_CURRENT_SOURCE_DIR}/${HUB_MODULE}/*.cpp) + file(GLOB_RECURSE object_sources ${CMAKE_CURRENT_SOURCE_DIR}/${HUB_MODULE}/*.cpp) set(object_headers) - file(# GLOB - GLOB_RECURSE object_headers ${CMAKE_CURRENT_SOURCE_DIR}/${HUB_MODULE}/*.hpp + file(GLOB_RECURSE object_headers ${CMAKE_CURRENT_SOURCE_DIR}/${HUB_MODULE}/*.hpp ${CMAKE_CURRENT_SOURCE_DIR}/${HUB_MODULE}/*.h) + if(object_headers MATCHES "Types.hpp") message(FATAL_ERROR "Types.hpp shallow Radium Core/Types.hpp definitions") endif() @@ -212,63 +214,54 @@ if(HUB_BUILD_STATIC) ${PROJECT_NAME}_static PUBLIC $ $ # Version.hpp + $ $ - # PRIVATE - ${HUB_EXTERNAL_DIR}) + $ + ) endif() # (XCODE) + target_compile_features(${PROJECT_NAME}_static PUBLIC cxx_std_17) target_compile_definitions(${PROJECT_NAME}_static PUBLIC -DSRC_STATIC) - target_link_libraries(${PROJECT_NAME}_static PRIVATE external ${REQUIRED_LIBS}) + target_link_libraries(${PROJECT_NAME}_static PRIVATE ${REQUIRED_LIBS}) - # Todo export static lib - # set_target_properties(${PROJECT_NAME}_static PROPERTIES VERSION ${${PROJECT_NAME}_VERSION} - # SOVERSION ${${PROJECT_NAME}_VERSION_MAJOR}) + set_target_properties(${PROJECT_NAME}_static PROPERTIES + OUTPUT_NAME ${PROJECT_NAME} + ARCHIVE_OUTPUT_DIRECTORY static # conflict rules name with static and shared compilation on windows + ) - install( - TARGETS ${PROJECT_NAME}_static - EXPORT ${PROJECT_NAME}_static - # DESTINATION lib/${ARCHITECTURE} - DESTINATION ${ARCHITECTURE}/lib) if(MSVC) if(${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo") target_compile_options(${PROJECT_NAME}_static PRIVATE /Zi) + # Tell linker to include symbol data - set_target_properties(${PROJECT_NAME}_static PROPERTIES LINK_FLAGS - "/INCREMENTAL:NO /DEBUG /OPT:REF /OPT:ICF") + set_target_properties(${PROJECT_NAME}_static PROPERTIES + LINK_FLAGS "/INCREMENTAL:NO /DEBUG /OPT:REF /OPT:ICF") # Set file name & location - set_target_properties( - ${PROJECT_NAME}_static - PROPERTIES # COMPILE_PDB_NAME ${PROJECT_NAME}${CMAKE_POSTFIX} - COMPILE_PDB_NAME ${PROJECT_NAME} COMPILE_PDB_OUTPUT_DIR ${CMAKE_BINARY_DIR} - # DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX}" + set_target_properties(${PROJECT_NAME}_static PROPERTIES + COMPILE_PDB_NAME ${PROJECT_NAME}_static + COMPILE_PDB_OUTPUT_DIR ${CMAKE_BINARY_DIR} ) endif() + endif() - if(NOT ${CMAKE_BUILD_TYPE} STREQUAL "Release") - install( - FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}${CMAKE_POSTFIX}.pdb - DESTINATION ${ARCHITECTURE}/lib - OPTIONAL) - install( - FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${PROJECT_NAME}${CMAKE_POSTFIX}.pdb - DESTINATION ${ARCHITECTURE}/lib - OPTIONAL) - endif() - endif() # MSVC + ################################ INSTALL ################################### - # Todo export static lib - # install( - # EXPORT ${PROJECT_NAME}_static - # FILE ${PROJECT_NAME}Targets.cmake - # # DESTINATION lib/cmake/${PROJECT_NAME}) - # DESTINATION share/${PROJECT_NAME}/cmake) - # export(EXPORT ${PROJECT_NAME}_static FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake") + ################################ EXPORT #################################### + install( + TARGETS ${PROJECT_NAME}_static + EXPORT ${PROJECT_NAME}_static + DESTINATION ${ARCHITECTURE}/lib + ) - if(UNIX) - set_target_properties(${PROJECT_NAME}_static PROPERTIES OUTPUT_NAME ${PROJECT_NAME}) - endif() + install( + EXPORT ${PROJECT_NAME}_static + FILE ${PROJECT_NAME}StaticTargets.cmake + DESTINATION share/${PROJECT_NAME}/cmake + ) + + list(APPEND HUB_LIBRARIES static) endif() # static library @@ -283,54 +276,63 @@ if(HUB_BUILD_SHARED) PUBLIC $ $ # Version.hpp $ - PRIVATE ${HUB_EXTERNAL_DIR}) - + PRIVATE ${HUB_EXTERNAL_DIR} + ) else() add_library(${PROJECT_NAME}_shared SHARED ${SRC_TARGETS}) target_include_directories( ${PROJECT_NAME}_shared PUBLIC $ $ # Version.hpp + $ $ - # PRIVATE ${HUB_EXTERNAL_DIR} + $ ) endif() # (XCODE) + target_compile_features(${PROJECT_NAME}_shared PUBLIC cxx_std_17) target_compile_definitions(${PROJECT_NAME}_shared PUBLIC -DSRC_EXPORTS) - target_link_libraries(${PROJECT_NAME}_shared PRIVATE external ${REQUIRED_LIBS}) + target_link_libraries(${PROJECT_NAME}_shared PRIVATE ${REQUIRED_LIBS}) - # PUBLIC $ $ # Version.hpp set_target_properties(${PROJECT_NAME}_shared PROPERTIES VERSION ${${PROJECT_NAME}_VERSION} - SOVERSION ${${PROJECT_NAME}_VERSION_MAJOR}) - - install( - TARGETS ${PROJECT_NAME}_shared - EXPORT ${PROJECT_NAME}_shared - DESTINATION ${ARCHITECTURE}/bin # Linux - # DESTINATION ${ARCHITECTURE}/lib) - RUNTIME DESTINATION ${ARCHITECTURE}/bin # Windows + SOVERSION ${${PROJECT_NAME}_VERSION_MAJOR} + OUTPUT_NAME ${PROJECT_NAME} ) + ################################ INSTALL ################################### + if(MSVC) if(NOT ${CMAKE_BUILD_TYPE} STREQUAL "Release") install(FILES $ DESTINATION ${ARCHITECTURE}/bin) endif() endif() + ################################ EXPORT #################################### + + install( + TARGETS ${PROJECT_NAME}_shared + EXPORT ${PROJECT_NAME}_shared + DESTINATION ${ARCHITECTURE}/lib # Linux + RUNTIME DESTINATION ${ARCHITECTURE}/bin # Windows + ) + install( EXPORT ${PROJECT_NAME}_shared - FILE ${PROJECT_NAME}Targets.cmake - # DESTINATION lib/cmake/${PROJECT_NAME}) + FILE ${PROJECT_NAME}SharedTargets.cmake DESTINATION share/${PROJECT_NAME}/cmake) - export(EXPORT ${PROJECT_NAME}_shared FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake") - set_target_properties(${PROJECT_NAME}_shared PROPERTIES OUTPUT_NAME ${PROJECT_NAME}) + list(APPEND HUB_LIBRARIES shared) endif() # (HUB_BUILD_SHARED) +message(STATUS "${HEADER_MSG} Libraries: (${HUB_LIBRARIES})") + +# ########################### ALIAS ################################ + if(HUB_BUILD_SHARED OR HUB_BUILD_STATIC) if(HUB_BUILD_SHARED AND HUB_BUILD_STATIC) add_library(hub ALIAS hub_static) + # add_library(hub ALIAS hub_shared) # hub.lib not found on windows (conflict with shared compilation, dll generate .lib file) elseif(HUB_BUILD_SHARED) add_library(hub ALIAS hub_shared) else() @@ -349,13 +351,11 @@ include(CMakePackageConfigHelpers) configure_package_config_file( ${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" - # INSTALL_DESTINATION "lib/cmake/${PROJECT_NAME}" INSTALL_DESTINATION "share/${PROJECT_NAME}/cmake/" NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO) write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" - # VERSION 1.0.0 VERSION ${${PROJECT_NAME}_VERSION} COMPATIBILITY AnyNewerVersion) diff --git a/src/Config.cmake.in b/src/Config.cmake.in index b9fbd79c6..290f64013 100644 --- a/src/Config.cmake.in +++ b/src/Config.cmake.in @@ -1,7 +1,12 @@ @PACKAGE_INIT@ -include ( "${CMAKE_CURRENT_LIST_DIR}/hubTargets.cmake" ) +if (@HUB_BUILD_STATIC@) + include ( "${CMAKE_CURRENT_LIST_DIR}/hubStaticTargets.cmake" ) +endif() +if (@HUB_BUILD_SHARED@) + include ( "${CMAKE_CURRENT_LIST_DIR}/hubSharedTargets.cmake" ) +endif() set(CMAKE_CXX_STANDARD @CMAKE_CXX_STANDARD@) set(CMAKE_CXX_STANDARD_REQUIRED @CMAKE_CXX_STANDARD_REQUIRED@) @@ -10,21 +15,29 @@ if(UNIX) find_package(Threads REQUIRED) endif() -set(HUB_INCLUDE_DIR ${PACKAGE_PREFIX_DIR}/include) +if (@TBB_FOUND@) + find_package(TBB REQUIRED) +endif() +set(HUB_INCLUDE_DIR ${PACKAGE_PREFIX_DIR}/include) set (HUB_VERSION "@hub_VERSION@") message(STATUS "Found hub: ${PACKAGE_PREFIX_DIR} (version \"${HUB_VERSION}\")") if(TARGET hub_shared OR TARGET hub_static) - if(TARGET hub_shared AND TARGET hub_static) - add_library(hub ALIAS hub_shared) - elseif(TARGET hub_shared) - add_library(hub ALIAS hub_shared) - else() - add_library(hub ALIAS hub_static) - endif() + + if(TARGET hub_shared AND TARGET hub_static) + add_library(hub ALIAS hub_static) + # add_library(hub ALIAS hub_shared) + elseif(TARGET hub_shared) + add_definitions(-DSRC_IMPORTS) # Import dll only for external use + add_library(hub ALIAS hub_shared) + else() + add_library(hub ALIAS hub_static) + endif() else() - message(FATAL_ERROR "static or shared library are not installed") + message(FATAL_ERROR "static or shared library are not installed") endif() + + diff --git a/src/core/Macros.hpp b/src/core/Macros.hpp deleted file mode 100644 index c30ed1517..000000000 --- a/src/core/Macros.hpp +++ /dev/null @@ -1,680 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2021 IRIT, computer science research laboratory, Toulouse, France. -* Please visit https://www.irit.fr/tplay/. -* -* All rights reserved. -* This code belongs to tplay/hub project (https://github.com/T-PLAY/hub). -* -* This Source Code Form is subject to the terms of the Mozilla Public -* License, v. 2.0. If a copy of the MPL was not distributed with this -* file, You can obtain one at https://mozilla.org/MPL/2.0/. -* -* Initial Contributors: -* - Nicolas Mellado (IRIT) -* - Gauthier Bouyjou (IRIT) -*******************************************************************************/ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "Configuration.hpp" - -#ifdef HUB_USE_BOOST -# include -#endif - -namespace hub { - -// Compiler identification - -// OS and architecture identification -#if defined( _WIN32 ) || defined( _WIN64 ) // ------------------------------ Windows - // Shlwapi.h also define this macro -# ifndef OS_WINDOWS -# define OS_WINDOWS -# endif -# if defined( _M_X64 ) || defined( __x86_64__ ) -# define ARCH_X64 -# elif defined( i386 ) || defined( __i386__ ) || defined( __i386 ) || defined( _M_IX86 ) -# define ARCH_X86 -# elif defined( __arm__ ) || defined( __arm ) || defined( _M_ARM ) -# define ARCH_ARM32 -# elif defined( __aarch64__ ) || defined( _M_ARM64 ) -# define ARCH_ARM64 -# else -# error unsupported arch -# endif -#elif defined( __APPLE__ ) || defined( __MACH__ ) // ------------------------ Mac OS -# define OS_MACOS -#elif defined( __linux__ ) || defined( __CYGWIN__ ) // ---------------------- Linux -# define OS_LINUX -#else -#ifndef CPP_CHECK -# error unsupported OS -#endif -#endif - -#if defined( __GNUC__ ) - -#define COMPILER_GCC -#define GCC_VERSION __GNUC__ - -#elif defined( __clang__ ) -# define COMPILER_CLANG -# define CLANG_VERSION __clang_major__ - -#elif defined( _MSC_VER ) -//#if _MSC_VER >= 1900 -# define COMPILER_MSVC -# define _USE_MATH_DEFINES -#else -#ifndef CPP_CHECK -# error unsupported compiler -#endif -#endif - - -// Check arch for macos and linux -#if defined( OS_MACOS ) || defined( OS_LINUX ) -# if defined( __i386__ ) -# define ARCH_X86 -# elif defined( __x86_64__ ) || defined( __x86_64 ) -# define ARCH_X64 -# elif defined( __arm__ ) || defined( __arm ) -# define ARCH_ARM32 -# elif defined( __aarch64__ ) || defined( __aarch64 ) -# define ARCH_ARM64 -# else -# error unsupported arch -# endif -#endif - -// Todo : endianness, pointer sixe - -// Build configuration - -// This tells apart between debug and release builds : -// DEBUG is defined in debug builds and RELEASE in release builds. -// Additionally REL_DEB is defined on release build with debug info -// Also the macro ON_DEBUG() can be used to execute an expression only on debug. -// By default, debug has assert macros enabled. In release builds - -//// Make sure all "debug" macros are defined - -// Explicit compiler warning disables. - -#if defined( COMPILER_GCC ) -#endif -#if defined( COMPILER_MSVC ) -# pragma warning( disable : 4244 ) // Conversion from double to float loses data. -# pragma warning( disable : 4251 ) // stl dllexports -# pragma warning( disable : 4267 ) // conversion from size_t to uint -# pragma warning( disable : 4018 ) // signed/unsigned mismatch -// DLL-interface class 'class_2' #pragma warning(disable: 4577) // noexcept used with no -# ifndef NOMINMAX -# define NOMINMAX -# endif -#endif - -// Debug log message. - -#define ENABLE_DEBUG_MSG - -#if defined( ENABLE_DEBUG_MSG ) && defined( DEBUG ) -# define DEBUG_MSG( str ) \ - do { \ - std::cout << str << std::endl; \ - } while ( false ) - -#else -# define DEBUG_MSG( str ) \ - do { \ - } while ( false ) -#endif - -// Dll import/export. -// You must define SRC_STATIC to force static link for external use (.lib) - -//#ifndef SRC_STATIC -//#define SRC_STATIC -//#endif - -#ifdef OS_WINDOWS -# if defined SRC_STATIC -# define SRC_API - -# elif defined SRC_EXPORTS -# define SRC_API __declspec( dllexport ) - -# else -# error "unable to import from build environment" -# define SRC_API __declspec( dllimport ) -# endif - -#else // unix -# define SRC_API -#endif - -#ifdef WIN32 -# define CPLUSPLUS_VERSION _MSVC_LANG -#else -# define CPLUSPLUS_VERSION __cplusplus -#endif - -#if ( CPLUSPLUS_VERSION >= 202001L ) -# define CPP_VERSION 20 -# define CONSTEXPR17 constexpr -# define CONSTEXPR20 constexpr -# define CONSTEXPR constexpr -#elif ( CPLUSPLUS_VERSION >= 201703L ) -# define CPP_VERSION 17 -# define CONSTEXPR17 constexpr -# define CONSTEXPR20 -# define CONSTEXPR constexpr -#elif ( CPLUSPLUS_VERSION >= 201402L ) -# define CPP_VERSION 14 -# define CONSTEXPR17 -# define CONSTEXPR20 -# define CONSTEXPR constexpr -#else -# define CPP_VERSION 14 -# define CONSTEXPR17 -# define CONSTEXPR20 -# define CONSTEXPR const -#endif - -// #define HUB_DEBUG_INPUT_OUTPUT -#ifdef HUB_DEBUG_INPUT_OUTPUT -# define HUB_DEBUG_INPUT -# define HUB_DEBUG_OUTPUT - -#endif - -#ifdef WIN32 -# define FILE_NAME \ - std::string( "/\\" __FILE__ ) \ - .substr( std::max( std::string( "/\\" __FILE__ ).find_last_of( '\\' ), \ - std::string( "/\\" __FILE__ ).find_last_of( '/' ) ) + \ - 1 ) - -#else // unix system -# ifdef COMPILER_GCC - -# if GCC_VERSION < 12 -# define FILE_NAME \ - std::string( "/\\" __FILE__ ) \ - .substr( std::max( std::string( "/\\" __FILE__ ).find_last_of( '\\' ), \ - std::string( "/\\" __FILE__ ).find_last_of( '/' ) ) + \ - 1 ) -# else -# define FILE_NAME std::string( __FILE_NAME__ ) -# endif - -# else -# define FILE_NAME std::string( __FILE_NAME__ ) -# endif - -#endif - -#define FILE_NAME_WITHOUT_EXTENSION FILE_NAME.substr( 0, FILE_NAME.find_first_of( '.' ) ) - -#define HEADER \ - "\033[" << std::to_string( 31 + reinterpret_cast( this ) % 7 ) << "m[" \ - << FILE_NAME_WITHOUT_EXTENSION << ":" << (uintptr_t)this % 100 << "]\033[0m " - -#ifdef WIN32 -# define MAX_STACK_SIZE 100'000 -#else -# define MAX_STACK_SIZE 100'000 // 100Ko -#endif - -} // namespace hub - -/////////////////////////////////////////////////////////////////////////////////// - -#if CPP_VERSION <= 14 -# include "traits/std_any.hpp" -#else -# include -#endif - -namespace std { - -#if CPP_VERSION < 20 - -template -struct remove_cvref : std::remove_cv> {}; - -template -using remove_cvref_t = typename remove_cvref::type; - -#endif - -////////////////////////////////// - -#if CPP_VERSION < 17 - -template -static constexpr auto is_same_v = is_same::value; - -template -static constexpr bool is_arithmetic_v = is_arithmetic::value; - -template -static constexpr bool is_array_v = is_array::value; - -#endif - -#if CPP_VERSION <= 14 // std::void_t not supported by AppleClang (c++14) - -using string_view = string; - -template -static constexpr bool is_enum_v = is_enum::value; - -template -static constexpr bool is_pointer_v = is_pointer::value; - -template -static constexpr bool is_base_of_v = is_base_of::value; - -#endif - -#if defined( OS_MACOS ) && CPP_VERSION <= 14 // std::void_t not supported by AppleClang (c++14) - -template -struct make_void { - typedef void type; -}; - -template -using void_t = typename make_void::type; - -#endif - -} // namespace std - -/////////////////////////////////////////////////////////////////////////////////// - -namespace hub { - -#if CPP_VERSION >= 20 - -template -concept isContainer = !std::is_same() && requires( T t ) { - t.begin(); - t.end(); - // std::begin( t ); - // std::end( t ); -}; - -#else -template -using has_begin_t = decltype( std::begin( std::declval() ) ); - -template > -struct has_begin : std::false_type {}; - -template -struct has_begin>> : std::true_type {}; - -template -static constexpr bool has_begin_v = has_begin::value; - -//////////// - -template -using has_end_t = decltype( std::end( std::declval() ) ); - -template > -struct has_end : std::false_type {}; - -template -struct has_end>> : std::true_type {}; - -template -static constexpr bool has_end_v = has_end::value; -template -constexpr bool isContainer = !std::is_same() && has_begin_v && has_end_v; -#endif - -static_assert( isContainer> ); -static_assert( isContainer> ); -static_assert( !isContainer ); -static_assert( !isContainer ); - -////////////////////////////////////////////////////////// TYPE_NAME -////////////////////////////////////////// - -template -using has_name_t = decltype( T::name() ); - -template > -struct has_name : std::false_type {}; - -template -struct has_name>> : std::true_type {}; - -template -static constexpr bool has_name_v = has_name::value; - -////////////// - -template -using nameable_t = decltype( name( std::declval() ) ); - -template > -struct nameable : std::false_type {}; - -template -struct nameable>> : std::true_type {}; - -template -static constexpr bool nameable_v = nameable::value; - -template -static typename std::enable_if_t && !has_name_v, std::string> -typeName( const T& ) { -#ifdef HUB_USE_BOOST - return boost::typeindex::type_id().pretty_name(); -#else - return typeid( T ).name(); -#endif -} - -template -static typename std::enable_if_t && has_name_v, std::string> -typeName( const T& ) { - return T::name(); -} - -template -static typename std::enable_if_t, std::string> typeName( const T& t ) { - static_assert( !has_name_v ); - return name( t ); -} - -static std::string typeName( const std::string& ) { - return "string"; -} -static std::string typeName( int ) { - return "int"; -} -static std::string typeName( double ) { - return "double"; -} -static std::string typeName( bool ) { - return "bool"; -} -static std::string typeName( float ) { - return "float"; -} -static std::string typeName( char ) { - return "char"; -} -static std::string typeName( unsigned char ) { - return "uchar"; -} -static std::string typeName( const char* ) { - return "cstr"; -} -static std::string typeName( long long ) { - return "long long"; -} - -template -static std::string typeName( const std::vector& ) { - return "vector<" + typeName( T() ) + ">"; -} - -template -static std::string typeName( const std::set& ) { - return "set<" + typeName( T() ) + ">"; -} - -template -static std::string typeName( const std::pair& ) { - return "pair<" + typeName( First() ) + ", " + typeName( Second() ) + ">"; -} - -template -static std::string typeName( const std::map& ) { - return "map<" + typeName( Key() ) + ", " + typeName( Value() ) + ">"; -} - -template -static void typeName_recurse( std::string& str ) { - str += ", " + typeName( T() ); - if CONSTEXPR17 ( sizeof...( Ts ) > 0 ) { typeName_recurse( str ); } -} - -template -static std::string typeName( const std::tuple& ) { - std::string str = "tuple<"; - str += typeName( T() ); -#if CPP_VERSION > 14 - if CONSTEXPR17 ( sizeof...( Ts ) > 0 ) { typeName_recurse( str ); } -#endif - str += ">"; - return str; -} - -template -static std::string typeName() { - std::string str; - str += typeName( T() ); - if constexpr ( sizeof...( Ts ) > 0 ) { str += ", " + typeName(); } - return str; -} - -// U>>, - -#define TYPE_NAME( _Type_ ) hub::typeName( _Type_ ) - -/////////////////////////////////////////// TYPE_ID //////////////////////////////////////////////// - -using TypeId_t = int; - -template -using has_id_t = decltype( T::id ); - -template > -struct has_id : std::false_type {}; - -template -struct has_id>> : std::true_type {}; - -template -static constexpr bool has_id_v = has_id::value; - -namespace Types { -enum Cpp : TypeId_t { NONE = 0, INT /* 1 */, BOOL /* 2 */, Cpp_Count /* 3 */ }; -} -static_assert( Types::Cpp_Count == 3 ); - -template -static constexpr typename std::enable_if_t, TypeId_t> getTypeId( const T& ) { - return T::id; -} - -template -static constexpr typename std::enable_if_t, TypeId_t> getTypeId( const T& ) { - return typeid( T ).hash_code(); -} - -constexpr auto getTypeId( int ) -> TypeId_t { - return Types::Cpp::INT; -} - -constexpr auto getTypeId( bool ) -> TypeId_t { - return Types::Cpp::BOOL; -} - -#define TYPE_ID( _Type_ ) hub::getTypeId( _Type_() ) - -#if CPP_VERSION >= 20 -# define REQUIRES( _CONST_, _COND_, _TYPE_ ) requires( _COND_ ) _CONST_ _TYPE_ -#else -# define REQUIRES( _CONST_, _COND_, _TYPE_ ) \ - _CONST_ typename std::enable_if_t<( _COND_ ), _TYPE_> -#endif - -////#undef assert - -using Data_t = unsigned char; -using Datas_t = std::vector; -using Size_t = uint64_t; // max = 18'446'744'073'709'551'616 ~= 18 exa - -#if CPP_VERSION >= 20 -template -constexpr auto sizeOf() { - if constexpr ( requires { T::Size; } ) { return T::Size; } - else { - return sizeof( T ); - } -} - -template -requires( sizeof...( Ts ) > 1 ) constexpr auto sizeOf() { - return ( sizeOf() + ... ); -} - -#else - -template -using has_Size_t = decltype( T::Size ); - -template > -struct has_Size : std::false_type {}; - -template -struct has_Size>> : std::true_type {}; - -template -static constexpr bool has_Size_v = has_Size::value; - -//////////////////////// - -template -using has_size_t = decltype( std::declval().size() ); - -template > -struct has_size : std::false_type {}; - -template -struct has_size>> : std::true_type {}; - -template -static constexpr bool has_size_v = has_size::value; - -template -REQUIRES( static constexpr, has_Size_v, decltype( sizeof( int ) ) ) -sizeOf() { - return T::Size; -} -template -REQUIRES( static constexpr, !has_Size_v, decltype( sizeof( int ) ) ) -sizeOf() { - return sizeof( T ); -} - -template -REQUIRES( constexpr, sizeof...( Ts ) > 1, decltype( sizeof( int ) ) ) -sizeOf() { - static_assert( sizeof...( Ts ) > 1 ); - return ( sizeOf() + ... ); -} - -template -REQUIRES( static constexpr, has_size_v, decltype( sizeof( int ) ) ) -sizeOf( const T& t ) { - return t.size(); -} - -template -REQUIRES( constexpr, sizeof...( Ts ) > 0, decltype( sizeof( int ) ) ) -sizeOf( const T& t, const Ts&... ts ) { - - if constexpr ( sizeof...( Ts ) > 0 ) { return sizeOf( t ) + sizeOf( ts... ); } - else { - return sizeOf( t ); - } -} - -#endif - -/////////////////////////////////////////////// PRETTY BYTES -///////////////////////////////////////////////// - -//// source : https://www.mbeckler.org/blog/?p=114 -//// Prints to the provided buffer a nice number of bytes (KB, MB, GB, etc) -/// \brief pretty_bytes -static std::string pretty_bytes( hub::Size_t bytes ) { - // std::string str; - - constexpr auto buffSize = 32; - char buff[buffSize] { 0 }; - static CONSTEXPR17 std::string_view suffixes[] { "Bytes", "Ko", "Mo", "Go", "To", "Po", "Eo" }; - uint64_t s = 0; // which suffix to use - double count = bytes; - constexpr auto kilo = 1'000; - - while ( count >= kilo && s < 7 ) { - s++; - count /= kilo; - } - - /// \brief count - if ( count - floor( count ) == 0.0 ) { -#ifdef WIN32 - snprintf( buff, buffSize, "%d %s", (int)count, suffixes[s].data() ); -#else -# ifdef OS_MACOS - snprintf( buff, buffSize, "%d %s", (int)count, suffixes[s].data() ); -# else - sprintf( buff, "%d %s", (int)count, suffixes[s].data() ); -# endif -#endif - } - /// \brief else - else - { -#ifdef WIN32 - snprintf( buff, buffSize, "%.1f %s", count, suffixes[s].data() ); -#else -# ifdef OS_MACOS - snprintf( buff, buffSize, "%.1f %s", count, suffixes[s].data() ); -# else - sprintf( buff, "%.1f %s", count, suffixes[s].data() ); -# endif -#endif - } - - // return std::string( buff ); - /// \brief return - return buff; -} -#define PRETTY_BYTES( t ) hub::pretty_bytes( t ) - -/////////////////////////////////////////////// STATIC WARNING -///////////////////////////////////////////////// - -//// Note: using STATIC_WARNING_TEMPLATE changes the meaning of a program in a small way. -//// It introduces a member/variable declaration. This means at least one byte of space -//// in each structure/class instantiation. STATIC_WARNING should be preferred in any -//// non-template situation. -//// 'token' must be a program-wide unique identifier. -// STATIC_WARNING(cond, msg) PP_CAT(PP_CAT(_localvar_, token),__LINE__) - -} // namespace hub diff --git a/src/core/base/Macros.hpp b/src/core/base/Macros.hpp index 5a0797b09..a525f8222 100644 --- a/src/core/base/Macros.hpp +++ b/src/core/base/Macros.hpp @@ -152,6 +152,9 @@ namespace hub { # if defined SRC_STATIC # define SRC_API +# elif defined SRC_IMPORTS +# define SRC_API __declspec( dllimport ) + # elif defined SRC_EXPORTS # define SRC_API __declspec( dllexport ) diff --git a/src/core/base/traits/SizeOf.hpp b/src/core/base/traits/SizeOf.hpp index d252b24ee..a47be9e0e 100644 --- a/src/core/base/traits/SizeOf.hpp +++ b/src/core/base/traits/SizeOf.hpp @@ -143,7 +143,7 @@ sizeOf( const T& t, const Ts&... ts ) { /// \param bytes /// \return /// -std::string pretty_bytes( hub::Size_t bytes ); +std::string SRC_API pretty_bytes( hub::Size_t bytes ); #define PRETTY_BYTES( t ) hub::pretty_bytes( t ) }