From d315026f37b99834fdd6a112e6a6b991a99294da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Sun, 8 Nov 2020 02:00:39 +0100 Subject: [PATCH 1/3] CMake: Add support for ASAN on MSVC --- CMakeLists.txt | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b7bb4eeb..163bf203a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.10.0) +cmake_minimum_required(VERSION 3.13.0) set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") @@ -287,11 +287,21 @@ endif() if (SANITIZE_ADDRESS) message(STATUS "Activate address sanitization") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address") - set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fsanitize=address") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address") - set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} -fsanitize=address") + 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() if (C_CLANG OR C_GCC) From a259f5af5b3bf99320fa0717a50d1bc4b27abb75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Sun, 8 Nov 2020 02:02:56 +0100 Subject: [PATCH 2/3] CMake: Specify targets to not build tools and things we do not need --- external/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 4a6bad73e..045fed630 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -481,6 +481,7 @@ if (LINUX) PREFIX "${EXTERNAL_BUILD_LIBRARIES}/rtlsdr" CMAKE_ARGS ${COMMON_CMAKE_ARGS} -DDETACH_KERNEL_DRIVER=ON -DINSTALL_UDEV_RULES=${RTLSDR_UDEV} BUILD_BYPRODUCTS "${LIBRTLSDR_LIBRARIES}" + BUILD_COMMAND ${CMAKE_COMMAND} --build --config $ -- rtlsdr_shared INSTALL_COMMAND "" TEST_COMMAND "" ) @@ -525,6 +526,7 @@ if (WIN32 OR APPLE) -DTHREADS_PTHREADS_INCLUDE_DIR=${PTHREADS4W_INCLUDE_DIR} -DTHREADS_PTHREADS_WIN32_LIBRARY=${PTHREADS4W_LIBRARIES} BUILD_BYPRODUCTS "${LIBRTLSDR_LIBRARIES}" + BUILD_COMMAND ${CMAKE_COMMAND} --build --config $ -- rtlsdr_shared INSTALL_COMMAND "" TEST_COMMAND "" ) @@ -593,6 +595,7 @@ if (WIN32 OR APPLE) -DENABLE_PYTHON3=OFF -DENABLE_TESTS=OFF BUILD_BYPRODUCTS "${SOAPYSDR_LIBRARY}" + BUILD_COMMAND ${CMAKE_COMMAND} --build --config $ -- SoapySDR INSTALL_COMMAND "" TEST_COMMAND "" ) From 7250240a9fee7e635b83c5ca0f82d522dbebc0ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Sun, 8 Nov 2020 08:20:09 +0100 Subject: [PATCH 3/3] CMake: Add an option to hide console on Windows Fixes #693 --- CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 163bf203a..4b1cb3521 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ option(SANITIZE_ADDRESS "Activate memory address sanitization" OFF) option(RX_SAMPLE_24BIT "Internal 24 bit Rx DSP" ON) option(BUILD_SERVER "Build Server" ON) option(BUILD_GUI "Build GUI" ON) +option(HIDE_CONSOLE "Hide console when running GUI on Windows" ON) option(BUNDLE "Enable distribution bundle" OFF) option(FORCE_SSSE3 "Compile with SSSE3 instruction only" OFF) option(FORCE_SSE41 "Compile with SSE4.1 instruction only" OFF) @@ -562,9 +563,10 @@ if (BUILD_GUI) logging ) - if (MSVC) - set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup") - endif() + if(WIN32) + set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES + WIN32_EXECUTABLE ${HIDE_CONSOLE}) + endif() endif() ############ build sdrangel server ################