From 1ac34678da34799883f967131427563d0add2d87 Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 5 Sep 2017 08:27:15 +0200 Subject: [PATCH] Main cmakefile: change placement of architecture detection --- CMakeLists.txt | 198 ++++++++++++++++++++++++------------------------- 1 file changed, 99 insertions(+), 99 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b49db3af0..6b7b7adea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,6 +89,103 @@ endif() ############################################################################## +if (HOST_RPI) + message( STATUS "Compiling on RPi" ) +endif() + +EXECUTE_PROCESS( COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE ARCHITECTURE ) +message( STATUS "Architecture: ${ARCHITECTURE}" ) + +if (${ARCHITECTURE} MATCHES "x86_64|AMD64|x86") + EXECUTE_PROCESS( COMMAND grep flags /proc/cpuinfo OUTPUT_VARIABLE CPU_FLAGS ) +# if (${CPU_FLAGS} MATCHES "avx2") +# set(HAS_AVX2 ON CACHE BOOL "Architecture has AVX2 SIMD enabled") +# if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) +# set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mavx2" ) +# set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -mavx2" ) +# message(STATUS "Use AVX2 SIMD instructions") +# add_definitions(-DUSE_AVX2) +# else() +# set(HAS_AVX2 OFF CACHE BOOL "Architecture does not have AVX2 SIMD enabled") +# endif() +# endif() + if (${CPU_FLAGS} MATCHES "sse4_1") + set(HAS_SSE4_1 ON CACHE BOOL "Architecture has SSE 4.1 SIMD enabled") + if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) + set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -msse4.1" ) + set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -msse4.1" ) + message(STATUS "Use SSE 4.1 SIMD instructions") + add_definitions(-DUSE_SSE4_1) + elseif(MSVC) + set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /arch:SSE4_1" ) + set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oi /GL /Ot /Ox /arch:SSE4_1" ) + set( CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG" ) + add_definitions (/D "_CRT_SECURE_NO_WARNINGS") + add_definitions(-DUSE_SSE4_1) + endif() + else() + set(HAS_SSE4_1 OFF CACHE BOOL "Architecture does not have SSE 4.1 SIMD enabled") + endif() + if (${CPU_FLAGS} MATCHES "ssse3") + set(HAS_SSSE3 ON CACHE BOOL "Architecture has SSSE3 SIMD enabled") + if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) + set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mssse3" ) + set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -mssse3" ) + message(STATUS "Use SSSE3 SIMD instructions") + add_definitions(-DUSE_SSSE3) + elseif(MSVC) + set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /arch:SSSE3" ) + set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oi /GL /Ot /Ox /arch:SSSE3" ) + set( CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG" ) + add_definitions (/D "_CRT_SECURE_NO_WARNINGS") + add_definitions(-DUSE_SSSE3) + endif() + else() + set(HAS_SSSE3 OFF CACHE BOOL "Architecture does not have SSSE3 SIMD enabled") + endif() + if (${CPU_FLAGS} MATCHES "sse2") + set(HAS_SSE2 ON CACHE BOOL "Architecture has SSE2 SIMD enabled") + if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) + set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -msse2" ) + set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -msse2" ) + message(STATUS "Use SSE2 SIMD instructions") + add_definitions(-DUSE_SSE2) + elseif(MSVC) + set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /arch:SSE2" ) + set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oi /GL /Ot /Ox /arch:SSE2" ) + set( CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG" ) + add_definitions (/D "_CRT_SECURE_NO_WARNINGS") + add_definitions(-DUSE_SSE2) + endif() + else() + set(HAS_SSE2 OFF CACHE BOOL "Architecture does not have SSE2 SIMD enabled") + endif() +elseif (${ARCHITECTURE} MATCHES "armv7l") + EXECUTE_PROCESS( COMMAND grep Features /proc/cpuinfo OUTPUT_VARIABLE CPU_FLAGS ) + if (${CPU_FLAGS} MATCHES "neon") + set(HAS_NEON ON CACHE BOOL "Architecture has NEON SIMD enabled") + if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) + set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mfpu=neon" ) + set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -mfpu=neon" ) + message(STATUS "Use NEON SIMD instructions") + add_definitions(-DUSE_NEON) + endif() + else() + set(HAS_NEON OFF CACHE BOOL "Architecture does not have NEON SIMD enabled") + endif() +elseif (${ARCHITECTURE} MATCHES "aarch64") + set(HAS_NEON ON CACHE BOOL FORCE "Architecture has NEON SIMD enabled") + if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) + message(STATUS "Aarch64 always has NEON SIMD instructions") + add_definitions(-DUSE_NEON) + endif() +endif() + +# Compiler flags. +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -fmax-errors=10 -ffast-math -ftree-vectorize ${EXTRA_FLAGS}") + +############################################################################## + set(sdrbase_SOURCES sdrbase/mainwindow.cpp @@ -437,6 +534,8 @@ if (BUILD_DEBIAN) target_link_libraries(sdrbase serialdv) endif (BUILD_DEBIAN) +############################################################################## + set_target_properties(sdrbase PROPERTIES DEFINE_SYMBOL "sdrangel_EXPORTS") target_compile_features(sdrbase PRIVATE cxx_generalized_initializers) # cmake >= 3.1.0 @@ -448,105 +547,6 @@ include_directories( ${OPENGL_INCLUDE_DIR} ) -############################################################################## - -if (HOST_RPI) - message( STATUS "Compiling on RPi" ) -endif() - -EXECUTE_PROCESS( COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE ARCHITECTURE ) -message( STATUS "Architecture: ${ARCHITECTURE}" ) - -if (${ARCHITECTURE} MATCHES "x86_64|AMD64|x86") - EXECUTE_PROCESS( COMMAND grep flags /proc/cpuinfo OUTPUT_VARIABLE CPU_FLAGS ) -# if (${CPU_FLAGS} MATCHES "avx2") -# set(HAS_AVX2 ON CACHE BOOL "Architecture has AVX2 SIMD enabled") -# if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) -# set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mavx2" ) -# set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -mavx2" ) -# message(STATUS "Use AVX2 SIMD instructions") -# add_definitions(-DUSE_AVX2) -# else() -# set(HAS_AVX2 OFF CACHE BOOL "Architecture does not have AVX2 SIMD enabled") -# endif() -# endif() - if (${CPU_FLAGS} MATCHES "sse4_1") - set(HAS_SSE4_1 ON CACHE BOOL "Architecture has SSE 4.1 SIMD enabled") - if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) - set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -msse4.1" ) - set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -msse4.1" ) - message(STATUS "Use SSE 4.1 SIMD instructions") - add_definitions(-DUSE_SSE4_1) - elseif(MSVC) - set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /arch:SSE4_1" ) - set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oi /GL /Ot /Ox /arch:SSE4_1" ) - set( CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG" ) - add_definitions (/D "_CRT_SECURE_NO_WARNINGS") - add_definitions(-DUSE_SSE4_1) - endif() - else() - set(HAS_SSE4_1 OFF CACHE BOOL "Architecture does not have SSE 4.1 SIMD enabled") - endif() - if (${CPU_FLAGS} MATCHES "ssse3") - set(HAS_SSSE3 ON CACHE BOOL "Architecture has SSSE3 SIMD enabled") - if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) - set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mssse3" ) - set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -mssse3" ) - message(STATUS "Use SSSE3 SIMD instructions") - add_definitions(-DUSE_SSSE3) - elseif(MSVC) - set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /arch:SSSE3" ) - set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oi /GL /Ot /Ox /arch:SSSE3" ) - set( CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG" ) - add_definitions (/D "_CRT_SECURE_NO_WARNINGS") - add_definitions(-DUSE_SSSE3) - endif() - else() - set(HAS_SSSE3 OFF CACHE BOOL "Architecture does not have SSSE3 SIMD enabled") - endif() - if (${CPU_FLAGS} MATCHES "sse2") - set(HAS_SSE2 ON CACHE BOOL "Architecture has SSE2 SIMD enabled") - if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) - set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -msse2" ) - set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -msse2" ) - message(STATUS "Use SSE2 SIMD instructions") - add_definitions(-DUSE_SSE2) - elseif(MSVC) - set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /arch:SSE2" ) - set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oi /GL /Ot /Ox /arch:SSE2" ) - set( CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG" ) - add_definitions (/D "_CRT_SECURE_NO_WARNINGS") - add_definitions(-DUSE_SSE2) - endif() - else() - set(HAS_SSE2 OFF CACHE BOOL "Architecture does not have SSE2 SIMD enabled") - endif() -elseif (${ARCHITECTURE} MATCHES "armv7l") - EXECUTE_PROCESS( COMMAND grep Features /proc/cpuinfo OUTPUT_VARIABLE CPU_FLAGS ) - if (${CPU_FLAGS} MATCHES "neon") - set(HAS_NEON ON CACHE BOOL "Architecture has NEON SIMD enabled") - if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) - set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mfpu=neon" ) - set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -mfpu=neon" ) - message(STATUS "Use NEON SIMD instructions") - add_definitions(-DUSE_NEON) - endif() - else() - set(HAS_NEON OFF CACHE BOOL "Architecture does not have NEON SIMD enabled") - endif() -elseif (${ARCHITECTURE} MATCHES "aarch64") - set(HAS_NEON ON CACHE BOOL FORCE "Architecture has NEON SIMD enabled") - if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) - message(STATUS "Aarch64 always has NEON SIMD instructions") - add_definitions(-DUSE_NEON) - endif() -endif() - -############################################################################## - -# Compiler flags. -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -fmax-errors=10 -ffast-math -ftree-vectorize ${EXTRA_FLAGS}") - set(sdrangel_SOURCES app/main.cpp )