mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-05-24 11:12:27 -04:00
Merge pull request #715 from kasper93/cmake_review_change
CMake: Split arch detection and compiler flags into separate files
This commit is contained in:
commit
021e9b9d55
@ -281,8 +281,8 @@ else()
|
||||
message(STATUS "Compiling for 16 bit Rx DSP chain")
|
||||
endif()
|
||||
|
||||
# find cpu flags (and set compiler)
|
||||
include(FindCPUflags)
|
||||
# Set compiler options based on target architecture and selected extensions
|
||||
include(CompilerOptions)
|
||||
|
||||
# Instruct CMake to run moc automatically when needed
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
29
cmake/Modules/CompilerOptions.cmake
Normal file
29
cmake/Modules/CompilerOptions.cmake
Normal file
@ -0,0 +1,29 @@
|
||||
include_guard(GLOBAL)
|
||||
|
||||
include(DetectArchitecture)
|
||||
|
||||
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
|
||||
if(MSVC)
|
||||
add_compile_options(/MP)
|
||||
else()
|
||||
add_compile_options(-Wall -Wextra -Wvla -Woverloaded-virtual -ffast-math -ftree-vectorize)
|
||||
endif()
|
||||
|
||||
if (SANITIZE_ADDRESS)
|
||||
message(STATUS "Activate address sanitization")
|
||||
if(MSVC)
|
||||
set(ASAN_LIB_ARCH ${MSVC_CXX_ARCHITECTURE_ID})
|
||||
string(TOLOWER ${ASAN_LIB_ARCH} ASAN_LIB_ARCH)
|
||||
if(ASAN_LIB_ARCH STREQUAL "x86")
|
||||
set(ASAN_LIB_ARCH "i386")
|
||||
elseif(ASAN_LIB_ARCH STREQUAL "x64")
|
||||
set(ASAN_LIB_ARCH "x86_64")
|
||||
endif()
|
||||
add_compile_options(/fsanitize=address)
|
||||
link_libraries(clang_rt.asan_dynamic-${ASAN_LIB_ARCH} clang_rt.asan_dynamic_runtime_thunk-${ASAN_LIB_ARCH})
|
||||
add_link_options(/wholearchive:clang_rt.asan_dynamic_runtime_thunk-${ASAN_LIB_ARCH}.lib)
|
||||
else()
|
||||
add_compile_options(-fsanitize=address -fno-omit-frame-pointer -g)
|
||||
add_link_options(-fsanitize=address)
|
||||
endif()
|
||||
endif()
|
@ -4,16 +4,6 @@ include(CheckCXXCompilerFlag)
|
||||
include(CheckSymbolExists)
|
||||
include(CMakePushCheckState)
|
||||
|
||||
set(TEST_DIR ${PROJECT_SOURCE_DIR}/cmake/test)
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
set(C_CLANG 1)
|
||||
elseif(MAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
set(C_GCC 1)
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||
set(C_MSVC 1)
|
||||
endif()
|
||||
|
||||
# Detect current compilation architecture and create standard definitions
|
||||
macro(detect_architecture symbol arch)
|
||||
if (NOT DEFINED ARCHITECTURE)
|
||||
@ -44,6 +34,8 @@ function(detect_extensions extension)
|
||||
endfunction()
|
||||
|
||||
function(detect_msvc_native_opt)
|
||||
set(TEST_DIR ${PROJECT_SOURCE_DIR}/cmake/test)
|
||||
|
||||
try_run(RUN_AVX512 COMPILE_AVX512 "${CMAKE_BINARY_DIR}/tmp" "${TEST_DIR}/test_x86_avx512.cxx" COMPILE_DEFINITIONS /arch:AVX512)
|
||||
if (COMPILE_AVX512 AND RUN_AVX512 EQUAL 0)
|
||||
set(ARCH_OPT "AVX512" PARENT_SCOPE)
|
||||
@ -101,7 +93,7 @@ function(detect_msvc_native_opt)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
if (C_MSVC)
|
||||
if (MSVC)
|
||||
detect_architecture("_M_AMD64" x86_64)
|
||||
detect_architecture("_M_IX86" x86)
|
||||
detect_architecture("_M_ARM" ARM)
|
||||
@ -122,7 +114,7 @@ endif()
|
||||
if (FORCE_SSSE3)
|
||||
message(WARNING "FORCE_SSSE3 flag is deprecated, please use ARCH_OPT option.")
|
||||
set(ARCH_OPT "")
|
||||
if (C_MSVC)
|
||||
if (MSVC)
|
||||
if (ARCHITECTURE_x86)
|
||||
set(ARCH_OPT "SSE2")
|
||||
endif()
|
||||
@ -135,7 +127,7 @@ endif()
|
||||
if (FORCE_SSE41)
|
||||
message(WARNING "FORCE_SSE41 flag is deprecated, please use ARCH_OPT option.")
|
||||
set(ARCH_OPT "")
|
||||
if (C_MSVC)
|
||||
if (MSVC)
|
||||
if (ARCHITECTURE_x86)
|
||||
set(ARCH_OPT "SSE2")
|
||||
else()
|
||||
@ -146,10 +138,11 @@ if (FORCE_SSE41)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (C_MSVC)
|
||||
if (MSVC)
|
||||
# Glue to make ARCH_OPT more flexible for MSVC
|
||||
if (ARCH_OPT STREQUAL "native")
|
||||
detect_msvc_native_opt()
|
||||
FILE(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/tmp)
|
||||
elseif(ARCH_OPT STREQUAL "SSE4_2")
|
||||
force_ext_available(SSE4_2)
|
||||
set(ARCH_OPT "")
|
||||
@ -172,7 +165,7 @@ message(STATUS "Target architecture: ${ARCHITECTURE}-${ARCH_OPT}")
|
||||
|
||||
cmake_push_check_state(RESET)
|
||||
if (ARCH_OPT)
|
||||
if(C_MSVC)
|
||||
if(MSVC)
|
||||
set(CMAKE_REQUIRED_FLAGS "/arch:${ARCH_OPT}")
|
||||
add_compile_options(${CMAKE_REQUIRED_FLAGS})
|
||||
else()
|
||||
@ -180,7 +173,7 @@ if (ARCH_OPT)
|
||||
add_compile_options(-march=${ARCH_OPT})
|
||||
endif()
|
||||
elseif(FORCE_SSSE3 OR FORCE_SSE41)
|
||||
if (NOT C_MSVC)
|
||||
if (NOT MSVC)
|
||||
set(CMAKE_REQUIRED_FLAGS ${FORCE_OPT})
|
||||
add_compile_options(${FORCE_OPT})
|
||||
endif()
|
||||
@ -192,7 +185,7 @@ if (NOT FLAG_SUPPORTED)
|
||||
endif()
|
||||
|
||||
if (ARCHITECTURE_ARM)
|
||||
if (C_MSVC)
|
||||
if (MSVC)
|
||||
force_ext_available(ARM_NEON)
|
||||
else()
|
||||
list(APPEND CMAKE_REQUIRED_FLAGS -mfpu=neon)
|
||||
@ -211,32 +204,3 @@ detect_extensions(SSE3 HAS_SSSE3)
|
||||
detect_extensions(SSE2 HAS_SSE3)
|
||||
|
||||
cmake_pop_check_state()
|
||||
|
||||
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
|
||||
if (C_CLANG OR C_GCC)
|
||||
add_compile_options(-Wall -Wextra -Wvla -Woverloaded-virtual -ffast-math -ftree-vectorize)
|
||||
elseif (C_MSVC)
|
||||
add_compile_options(/MP)
|
||||
endif()
|
||||
|
||||
if (SANITIZE_ADDRESS)
|
||||
message(STATUS "Activate address sanitization")
|
||||
if(MSVC)
|
||||
set(ASAN_LIB_ARCH ${MSVC_CXX_ARCHITECTURE_ID})
|
||||
string(TOLOWER ${ASAN_LIB_ARCH} ASAN_LIB_ARCH)
|
||||
if(ASAN_LIB_ARCH STREQUAL "x86")
|
||||
set(ASAN_LIB_ARCH "i386")
|
||||
elseif(ASAN_LIB_ARCH STREQUAL "x64")
|
||||
set(ASAN_LIB_ARCH "x86_64")
|
||||
endif()
|
||||
add_compile_options(/fsanitize=address)
|
||||
link_libraries(clang_rt.asan_dynamic-${ASAN_LIB_ARCH} clang_rt.asan_dynamic_runtime_thunk-${ASAN_LIB_ARCH})
|
||||
add_link_options(/wholearchive:clang_rt.asan_dynamic_runtime_thunk-${ASAN_LIB_ARCH}.lib)
|
||||
else()
|
||||
add_compile_options(-fsanitize=address -fno-omit-frame-pointer -g)
|
||||
add_link_options(-fsanitize=address)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# clear binary test folder
|
||||
FILE(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/tmp)
|
@ -17,7 +17,7 @@ include_directories(
|
||||
${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client
|
||||
)
|
||||
|
||||
if (C_GCC OR C_CLANG)
|
||||
if (NOT MSVC)
|
||||
set_target_properties(swagger PROPERTIES COMPILE_FLAGS "-Wno-conversion-null -Wno-unused-variable -Wno-unused-parameter")
|
||||
endif()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user