mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-25 09:18:54 -05:00
CMake: Split arch detection and compiler flags into separate files
This commit is contained in:
parent
7ee0bd2da6
commit
33ab785085
@ -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)
|
||||
|
30
cmake/Modules/CompilerOptions.cmake
Normal file
30
cmake/Modules/CompilerOptions.cmake
Normal file
@ -0,0 +1,30 @@
|
||||
include_guard(GLOBAL)
|
||||
|
||||
include(DetectCompiler)
|
||||
include(DetectArchitecture)
|
||||
|
||||
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()
|
@ -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)
|
||||
@ -150,6 +142,7 @@ if (C_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 "")
|
||||
@ -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)
|
9
cmake/Modules/DetectCompiler.cmake
Normal file
9
cmake/Modules/DetectCompiler.cmake
Normal file
@ -0,0 +1,9 @@
|
||||
include_guard(GLOBAL)
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
set(C_CLANG 1)
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
set(C_GCC 1)
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||
set(C_MSVC 1)
|
||||
endif()
|
Loading…
Reference in New Issue
Block a user