Merged branch 'master' of https://github.com/Nemo1369/libcds
authorkhizmax <khizmax@gmail.com>
Mon, 16 Jan 2017 09:28:09 +0000 (12:28 +0300)
committerkhizmax <khizmax@gmail.com>
Mon, 16 Jan 2017 09:28:09 +0000 (12:28 +0300)
- CMake-fied boost integration support implemented. macOS RPATH policy
- Buggy CMake try_compile when crosscompiling hacked with optional Threads
- Threads package made totally optional. Would be found when not crosscompiling and would not be when either.
- Crosscompilation target architecture made required to be set explicitly
- Implemented support for ARMv8 (64 bit arm)

CMakeLists.txt
cds/algo/int_algo.h
cds/compiler/gcc/compiler_macro.h
cds/details/defs.h

index dd8778d..6beb15a 100644 (file)
@@ -1,5 +1,8 @@
 cmake_minimum_required(VERSION 2.8.12)
+
 cmake_policy(SET CMP0016 NEW)
+cmake_policy(SET CMP0042 NEW)
+
 set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/build/cmake ${CMAKE_MODULE_PATH})
 include(TargetArch)
 
@@ -13,50 +16,64 @@ option(WITH_TESTS_COVERAGE "Analyze test coverage using gcov (only for gcc)" OFF
 option(WITH_BOOST_ATOMIC "Use boost atomics (only for boost >= 1.54)" OFF)
 option(WITH_ASAN "Build AddressSantinizer instrumented code" OFF)
 option(WITH_TSAN "Build ThreadSantinizer instrumented code" OFF)
+set(CMAKE_TARGET_ARCHITECTURE "" CACHE string "Target build architecture")
 
-find_package(Threads REQUIRED)
-find_package(Boost 1.50 COMPONENTS system thread REQUIRED)
+find_package(Threads)
+
+if(TARGET boost::system AND TARGET boost::thread)
+    link_libraries(boost::system boost::thread)
+else()
+    find_package(Boost 1.50 COMPONENTS system thread)
+endif()
 
 include_directories(${Boost_INCLUDE_DIRS})
 
-target_architecture(CMAKE_TARGET_ARCHITECTURE)
+if(NOT CMAKE_TARGET_ARCHITECTURE)
+    target_architecture(CMAKE_TARGET_ARCHITECTURE)
+endif()
 
 if(WITH_BOOST_ATOMIC)
-  if(${Boost_MINOR_VERSION} GREATER 53)
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCDS_USE_BOOST_ATOMIC")
-    message(STATUS "Boost version allows using of boost.atomic: activated")
-  endif()
+    if(Boost_FOUND)
+        if(${Boost_MINOR_VERSION} GREATER 53)
+            set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCDS_USE_BOOST_ATOMIC")
+            message(STATUS "Boost version allows using of boost.atomic: activated")
+        endif()
+    else()
+        if(TARGET boost::atomic)
+            link_libraries(boost::atomic)
+        endif()
+    endif()
 endif(WITH_BOOST_ATOMIC)
 
 if(WITH_ASAN)
-  if(CMAKE_COMPILER_IS_GNUCXX)
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1 -fPIC -fsanitize=address -g -fno-omit-frame-pointer -fno-optimize-sibling-calls")
-    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O1 -fsanitize=address -g -fno-omit-frame-pointer -fno-optimize-sibling-calls")
-    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address -pie")
-  else()
-    message(WARNING "Compiler does not support AddressSanitizer")
-  endif()
+    if(CMAKE_COMPILER_IS_GNUCXX)
+        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1 -fPIC -fsanitize=address -g -fno-omit-frame-pointer -fno-optimize-sibling-calls")
+        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O1 -fsanitize=address -g -fno-omit-frame-pointer -fno-optimize-sibling-calls")
+        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address -pie")
+    else()
+        message(WARNING "Compiler does not support AddressSanitizer")
+    endif()
 endif(WITH_ASAN)
 
 if(WITH_TSAN)
-  if(CMAKE_COMPILER_IS_GNUCXX)
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1 -fPIC -fsanitize=thread -g -DCDS_THREAD_SANITIZER_ENABLED -fno-omit-frame-pointer")
-    set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -O1 -fPIC -fsanitize=thread -g -DCDS_THREAD_SANITIZER_ENABLED -fno-omit-frame-pointer")
-    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread -pie")
-  else()
-    message(WARNING "Compiler does not support ThreadSanitizer")
-  endif()
+    if(CMAKE_COMPILER_IS_GNUCXX)
+        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1 -fPIC -fsanitize=thread -g -DCDS_THREAD_SANITIZER_ENABLED -fno-omit-frame-pointer")
+        set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -O1 -fPIC -fsanitize=thread -g -DCDS_THREAD_SANITIZER_ENABLED -fno-omit-frame-pointer")
+        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread -pie")
+    else()
+        message(WARNING "Compiler does not support ThreadSanitizer")
+    endif()
 endif(WITH_TSAN)
 
 if(WITH_TESTS_COVERAGE)
-  if(CMAKE_COMPILER_IS_GNUCXX)
-    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
-    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
-    message(STATUS "Test coverage analysis: activated")
-  else()
-    message(WARNING "Compiler is not GNU gcc! Test coverage couldn't be analyzed")
-  endif()  
+    if(CMAKE_COMPILER_IS_GNUCXX)
+        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
+        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
+        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
+        message(STATUS "Test coverage analysis: activated")
+    else()
+        message(WARNING "Compiler is not GNU gcc! Test coverage couldn't be analyzed")
+    endif()
 endif(WITH_TESTS_COVERAGE)
 
 set(CDS_SHARED_LIBRARY ${PROJECT_NAME})
@@ -75,19 +92,19 @@ endif()
 message(STATUS "Binary output path: ${EXECUTABLE_OUTPUT_PATH}")
 
 if(NOT CMAKE_BUILD_TYPE)
-  set(CMAKE_BUILD_TYPE Debug CACHE STRING "Default build type to Debug" FORCE)
+    set(CMAKE_BUILD_TYPE Debug CACHE STRING "Default build type to Debug" FORCE)
 endif()
 
-if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -pedantic -fno-strict-aliasing")  
-  if(CMAKE_TARGET_ARCHITECTURE STREQUAL "x86_64")
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcx16")
-    set(LIB_SUFFIX "64")
-  endif()    
-  if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "7.0.0")
-#   gcc 4.8 - 6: disable noise -Wunused-local-typedefs
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedefs")  
-  endif()
+if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -pedantic -fno-strict-aliasing")
+    if(CMAKE_TARGET_ARCHITECTURE STREQUAL "x86_64")
+        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcx16")
+        set(LIB_SUFFIX "64")
+    endif()
+    if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "7.0.0")
+        #   gcc 4.8 - 6: disable noise -Wunused-local-typedefs
+        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedefs")
+    endif()
 endif()
 
 if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
@@ -98,13 +115,17 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG")
 
 message("Build type -- ${CMAKE_BUILD_TYPE}")
 message("Compiler version: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
-MESSAGE("Target architecture: ${CMAKE_TARGET_ARCHITECTURE}")
-if (CMAKE_BUILD_TYPE STREQUAL "DEBUG")
-  message("Compiler flags: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}")
+message("Target architecture: ${CMAKE_TARGET_ARCHITECTURE}")
+if(CMAKE_BUILD_TYPE STREQUAL "DEBUG")
+    message("Compiler flags: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}")
+else()
+    message("Compiler flags: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}")
+endif()
+if(Boost_FOUND)
+    message("Boost: ${Boost_LIB_VERSION} in ${Boost_INCLUDE_DIRS}, lib ${Boost_LIBRARY_DIRS}")
 else()
-  message("Compiler flags: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}")
+    message("Boost: Using CMake-fied boost")
 endif()
-message("Boost: ${Boost_LIB_VERSION} in ${Boost_INCLUDE_DIRS}, lib ${Boost_LIBRARY_DIRS}")
 
 
 include_directories(${PROJECT_SOURCE_DIR})
@@ -125,8 +146,8 @@ set(SOURCES src/init.cpp
             src/dllmain.cpp)
 
 add_library(${CDS_SHARED_LIBRARY} SHARED ${SOURCES})
-set_target_properties( ${CDS_SHARED_LIBRARY} PROPERTIES VERSION ${PROJECT_VERSION}
-                                                        DEBUG_POSTFIX "_d")
+set_target_properties(${CDS_SHARED_LIBRARY} PROPERTIES VERSION ${PROJECT_VERSION}
+        DEBUG_POSTFIX "_d")
 add_library(${CDS_STATIC_LIBRARY} STATIC ${SOURCES})
 set_target_properties(${CDS_STATIC_LIBRARY} PROPERTIES DEBUG_POSTFIX "_d")
 target_link_libraries(${CDS_SHARED_LIBRARY} PRIVATE ${CMAKE_THREAD_LIBS_INIT})
@@ -138,9 +159,9 @@ install(TARGETS ${CDS_STATIC_LIBRARY} DESTINATION lib${LIB_SUFFIX} COMPONENT ${L
 install(DIRECTORY ${PROJECT_SOURCE_DIR}/cds DESTINATION include COMPONENT ${HEADERS_COMPONENT})
 
 if(WITH_TESTS)
-  enable_testing()
-  add_subdirectory(${PROJECT_SOURCE_DIR}/test)
-  message(STATUS "Build tests: activated")
+    enable_testing()
+    add_subdirectory(${PROJECT_SOURCE_DIR}/test)
+    message(STATUS "Build tests: activated")
 endif(WITH_TESTS)
 
 ### FOR PACKAGING in RPM, TGZ, DEB, NSYS...###############################################################################
@@ -174,7 +195,7 @@ set(CPACK_RPM_devel_PACKAGE_REQUIRES "boost >= 1.50, cds-lib = ${PROJECT_VERSION
 set(CPACK_DEB_COMPONENT_INSTALL ON)
 set(CPACK_DEBIAN_PACKAGE_DEPENDS "boost (>= 1.50)")
 set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/khizmax/libcds")
-set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${PROJECT_SOURCE_DIR}/build/cmake/post_install_script.sh;;${PROJECT_SOURCE_DIR}/build/cmake/post_uninstall_script.sh;" )
+set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${PROJECT_SOURCE_DIR}/build/cmake/post_install_script.sh;;${PROJECT_SOURCE_DIR}/build/cmake/post_uninstall_script.sh;")
 
 # NSYS specific
 set(CPACK_NSIS_PACKAGE_NAME "${CPACK_PACKAGE_NAME}")
index 9fc772a..cc6cfd2 100644 (file)
@@ -34,7 +34,7 @@
 #include <cds/algo/bitop.h>
 
 namespace cds { namespace beans {
-
+#if CDS_BUILD_BITS == 64
     /// Returns largest previous integer for <tt>log2( n )</tt>
     static inline size_t log2floor( size_t n )
     {
@@ -98,36 +98,68 @@ namespace cds { namespace beans {
         return is_power2(n) ? log2floor(n) : 0;
     }
 
-#if CDS_BUILD_BITS == 32
+#elif CDS_BUILD_BITS == 32
     //@cond
     // 64bit specializations
 
+/// Returns largest previous integer for <tt>log2( n )</tt>
     static inline uint64_t log2floor( uint64_t n )
     {
         return n ? cds::bitop::MSBnz( n ) : 0;
     }
 
+/// Returns smallest following integer for <tt>log2( n )</tt>
     static inline uint64_t log2ceil( uint64_t n )
     {
         uint64_t i = log2floor( n );
         return (uint64_t( 1 ) << i) < n ? i + 1 : i;
     }
 
+/// Returns largest previous power of 2 for \p n
+    /**
+        Examples:
+        \code
+        floor2(0) == 1   // !!!
+        floor2(1) == 1
+        floor2(2) == 2
+        floor2(3) == 2
+        floor2(4) == 4
+        floor2(15) == 8
+        floor2(16) == 16
+        floor2(17) == 16
+        \endcode
+    */
     static inline uint64_t floor2( uint64_t n )
     {
         return uint64_t( 1 ) << log2floor( n );
     }
 
+/// Returns smallest following power of 2 for \p n
+    /**
+        Examples:
+        \code
+        ceil2(0) == 1   // !!!
+        ceil2(1) == 1
+        ceil2(2) == 2
+        ceil2(3) == 4
+        ceil2(4) == 4
+        ceil2(15) == 16
+        ceil2(16) == 16
+        ceil2(17) == 32
+        \endcode
+    */
     static inline uint64_t ceil2( uint64_t n )
     {
         return uint64_t( 1 ) << log2ceil( n );
     }
 
+/// Checks if \p n is power of 2
     CDS_CONSTEXPR static inline bool is_power2( uint64_t n ) CDS_NOEXCEPT
     {
         return (n & (n - 1)) == 0 && n;
     }
 
+/// Returns binary logarithm of \p n if \p n is power of two, otherwise returns 0
     static inline uint64_t log2( uint64_t n )
     {
         return is_power2( n ) ? log2floor( n ) : 0;
index 658d829..d97e178 100644 (file)
 // Processor architecture
 
 #if defined(__arm__) && !defined(__ARM_ARCH)
-    // GCC 4.6 does not defined __ARM_ARCH
-#   if defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__)
+// GCC 4.6 does not defined __ARM_ARCH
+#   if defined(__ARM_ARCH_8A__) || defined(__ARM_ARCH_8S__) || defined(__aarch64__) || defined(__ARM_ARCH_ISA_A64)
+#       define __ARM_ARCH   8
+#   elif defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7S__)
 #       define __ARM_ARCH   7
 #   else
 #       define __ARM_ARCH   5
 #    define CDS_BUILD_BITS        64
 #    define CDS_PROCESSOR__NAME   "IBM PowerPC64"
 #    define CDS_PROCESSOR__NICK   "ppc64"
-#elif defined(__arm__) && __SIZEOF_POINTER__ == 4 && __ARM_ARCH >= 7
+#elif defined(__arm__) && __SIZEOF_POINTER__ == 4 && __ARM_ARCH >= 7 && __ARM_ARCH < 8
 #    define CDS_PROCESSOR_ARCH    CDS_PROCESSOR_ARM7
 #    define CDS_BUILD_BITS        32
 #    define CDS_PROCESSOR__NAME   "ARM v7"
 #    define CDS_PROCESSOR__NICK   "arm7"
+#elif defined(__arm__) && __ARM_ARCH >= 8
+#    define CDS_PROCESSOR_ARCH    CDS_PROCESSOR_ARM8
+#    define CDS_BUILD_BITS        64
+#    define CDS_PROCESSOR__NAME   "ARM v8"
+#    define CDS_PROCESSOR__NICK   "arm8"
 #else
 #   if defined(CDS_USE_LIBCDS_ATOMIC)
 #       error "Libcds does not support atomic implementation for the processor architecture. Try to use C++11-compatible compiler and remove CDS_USE_LIBCDS_ATOMIC flag from compiler command line"
 #   endif
 #else
 #   ifndef __declspec
-#       define __declspec( _x )
+#       define __declspec(_x)
 #   endif
 #endif
 
index 65d66e9..b1f0331 100644 (file)
@@ -237,6 +237,7 @@ namespace cds {}
                     - CDS_PROCESSOR_SPARC   Sparc
                     - CDS_PROCESSOR_PPC64   PowerPC64
                     - CDS_PROCESSOR_ARM7    ARM v7
+                    - CDS_PROCESSOR_ARM8    ARM v8
                     - CDS_PROCESSOR_UNKNOWN undefined processor architecture
 
     CDS_PROCESSOR__NAME    The name (string) of processor architecture
@@ -292,6 +293,7 @@ namespace cds {}
 #define CDS_PROCESSOR_AMD64     4
 #define CDS_PROCESSOR_PPC64     5   // PowerPC 64bit
 #define CDS_PROCESSOR_ARM7      7
+#define CDS_PROCESSOR_ARM8      8
 #define CDS_PROCESSOR_UNKNOWN   -1
 
 // Supported OS interfaces