Skip to content
Snippets Groups Projects
Commit a3de4a9d authored by Oksana Shadura's avatar Oksana Shadura Committed by Philippe Canal
Browse files

CMake helper macro for detecting corner case when compiler doesn't support intrinsics

parent 365deb9b
No related branches found
No related tags found
No related merge requests found
......@@ -108,6 +108,7 @@ include(RootBuildOptions)
include(RootNewMacros)
include(CheckCompiler)
include(CheckAssembler)
include(CheckIntrinsics)
#---Enable CCache ------------------------------------------------------------------------------
if(ccache)
......
......@@ -88,7 +88,20 @@ set(ZLIB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "")
set(ZLIB_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "")
if((CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|AMD64|X86_64|aarch64") AND (CMAKE_SYSTEM_NAME MATCHES "Linux"))
# Calling helper to avoid using old unsupported binutils (e.g. with SL6)
# macro is returning extra ${ROOT_DEFINITIONS} used after in ZLIB-CF
root_check_assembler()
# Calling helper to avoid using old unsupported binutils (e.g. with Centos7
# and native gcc compiler 4.8.5)
# Macros are returning bools SSE_SUPPORT & AVX2_SUPPORT
root_check_sse41()
root_check_avx2()
if(SSE_SUPPORT OR AVX2_SUPPORT)
set(ZLIB_CF TRUE CACHE INTERNAL "")
endif()
endif()
if(ZLIB_CF)
add_library(ZLIB STATIC ${ZLIB_PUBLIC_HEADERS} ${ZLIBCF_PRIVATE_HEADERS} ${ZLIBCF_SOURCES})
else()
add_library(ZLIB STATIC ${ZLIB_PUBLIC_HEADERS} ${ZLIB_PRIVATE_HEADERS} ${ZLIB_SOURCES})
......@@ -98,7 +111,7 @@ set_target_properties(ZLIB PROPERTIES C_VISIBILITY_PRESET hidden POSITION_INDEPE
target_include_directories(ZLIB INTERFACE $<BUILD_INTERFACE:${ZLIB_INCLUDE_DIR}>)
if((CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|AMD64|X86_64") AND (CMAKE_SYSTEM_NAME MATCHES "Linux"))
target_compile_options(ZLIB PRIVATE -Wno-unused-function -O3 -mpclmul ${ROOT_DEFINITIONS})
target_compile_options(ZLIB PRIVATE -Wno-unused-function -O3 -mpclmul ${ROOT_DEFINITIONS})
else()
target_compile_options(ZLIB PRIVATE -O3)
endif()
......
include(CheckCXXSourceRuns)
# Helper function for checking if compiler is supporting AVX2 intrinsics
function(root_check_avx2)
CHECK_CXX_COMPILER_FLAG("-mavx" AVX2_FLAG)
CHECK_CXX_SOURCE_COMPILES("#include <immintrin.h> \n int main () {__m256i xmm = _mm256_set1_epi64x(0); xmm = _mm256_add_epi64(xmm,xmm);};" AVX2_COMPILATION)
CHECK_CXX_SOURCE_RUNS("#include <immintrin.h> \n int main () {__m256i xmm = _mm256_set1_epi64x(0); xmm = _mm256_add_epi64(xmm,xmm);};" AVX2_RUN)
if(AVX2_FLAG AND AVX2_COMPILATION AND AVX2_RUN)
set(AVX2_SUPPORT TRUE PARENT_SCOPE)
endif()
endfunction()
# Helper function for checking if compiler is supporting SSE4.1 intrinsics
function(root_check_sse41)
CHECK_CXX_COMPILER_FLAG("-msse4.1" SSE_FLAG)
CHECK_CXX_SOURCE_COMPILES("#include <smmintrin.h> \n int main () {__m128 xmm=_mm_set_ps1(0.0); _mm_ceil_ps(xmm);};" SSE_COMPILATION)
CHECK_CXX_SOURCE_RUNS("#include <smmintrin.h> \n int main () {__m128 xmm=_mm_set_ps1(0.0); _mm_ceil_ps(xmm);};" SSE_RUN)
if(SSE_FLAG AND SSE_COMPILATION AND SSE_RUN)
set(SSE_SUPPORT TRUE PARENT_SCOPE)
endif()
endfunction()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment