mirror of
https://github.com/Serial-Studio/Serial-Studio.git
synced 2025-01-31 17:42:55 +08:00
Add optional sanitizer flags
This commit is contained in:
parent
01bf0653cf
commit
478aafaea2
8
.github/workflows/deploy.yml
vendored
8
.github/workflows/deploy.yml
vendored
@ -90,7 +90,7 @@ jobs:
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ../ -DCMAKE_CXX_COMPILER=icpx -DCMAKE_C_COMPILER=icx -DCMAKE_BUILD_TYPE=Release
|
||||
cmake ../ -DCMAKE_CXX_COMPILER=icpx -DCMAKE_C_COMPILER=icx -DPRODUCTION_OPTIMIZATION=ON -DCMAKE_BUILD_TYPE=Release
|
||||
|
||||
- name: '🚧 Build application'
|
||||
run: |
|
||||
@ -189,7 +189,7 @@ jobs:
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ../ -DCMAKE_C_COMPILER="/opt/homebrew/opt/llvm/bin/clang" -DCMAKE_CXX_COMPILER="/opt/homebrew/opt/llvm/bin/clang++" -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_DEPLOYMENT_TARGET=12.0 -DCMAKE_OSX_ARCHITECTURES="arm64"
|
||||
cmake ../ -DCMAKE_C_COMPILER="/opt/homebrew/opt/llvm/bin/clang" -DCMAKE_CXX_COMPILER="/opt/homebrew/opt/llvm/bin/clang++" -DPRODUCTION_OPTIMIZATION=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_DEPLOYMENT_TARGET=12.0 -DCMAKE_OSX_ARCHITECTURES="arm64"
|
||||
|
||||
- name: '🚧 Build application'
|
||||
run: |
|
||||
@ -280,7 +280,7 @@ jobs:
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ../ -DCMAKE_C_COMPILER="/opt/homebrew/opt/llvm/bin/clang" -DCMAKE_CXX_COMPILER="/opt/homebrew/opt/llvm/bin/clang++" -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_DEPLOYMENT_TARGET=12.0 -DCMAKE_OSX_ARCHITECTURES="x86_64"
|
||||
cmake ../ -DCMAKE_C_COMPILER="/opt/homebrew/opt/llvm/bin/clang" -DCMAKE_CXX_COMPILER="/opt/homebrew/opt/llvm/bin/clang++" -DPRODUCTION_OPTIMIZATION=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_DEPLOYMENT_TARGET=12.0 -DCMAKE_OSX_ARCHITECTURES="x86_64"
|
||||
|
||||
- name: '🚧 Build application'
|
||||
run: |
|
||||
@ -366,7 +366,7 @@ jobs:
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ../ -DCMAKE_CXX_COMPILER=cl -DCMAKE_C_COMPILER=cl -DCMAKE_BUILD_TYPE=Release
|
||||
cmake ../ -DCMAKE_CXX_COMPILER=cl -DCMAKE_C_COMPILER=cl -DPRODUCTION_OPTIMIZATION=ON -DCMAKE_BUILD_TYPE=Release
|
||||
|
||||
- name: '🚧 Build application'
|
||||
run: |
|
||||
|
227
CMakeLists.txt
227
CMakeLists.txt
@ -37,6 +37,13 @@ find_package(
|
||||
Qml
|
||||
)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Options for build types
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
option(DEBUG_SANITIZER "Enable sanitizers for debug builds" OFF)
|
||||
option(PRODUCTION_OPTIMIZATION "Enable production optimization flags" OFF)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Project information
|
||||
#-------------------------------------------------------------------------------
|
||||
@ -67,6 +74,18 @@ add_definitions(-DPROJECT_VERSION="${PROJECT_VERSION}")
|
||||
add_definitions(-DPROJECT_APPCAST="${PROJECT_APPCAST}")
|
||||
add_definitions(-DPROJECT_DISPNAME="${PROJECT_DISPNAME}")
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set UNIX friendly name for app & fix OpenSUSE builds
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
if (UNIX AND NOT APPLE)
|
||||
set(PROJECT_EXECUTABLE "serial-studio")
|
||||
set(CMAKE_C_COMPILER_AR "/usr/bin/ar")
|
||||
set(CMAKE_CXX_COMPILER_AR "/usr/bin/ar")
|
||||
set(CMAKE_C_COMPILER_RANLIB "/usr/bin/ranlib")
|
||||
set(CMAKE_CXX_COMPILER_RANLIB "/usr/bin/ranlib")
|
||||
endif()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# CPU architecture configuration
|
||||
#-------------------------------------------------------------------------------
|
||||
@ -80,117 +99,114 @@ if(APPLE)
|
||||
endif()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Compiler flags
|
||||
# Production optimization flags
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#
|
||||
# MinGW-specific settings
|
||||
#
|
||||
if(WIN32 AND MINGW)
|
||||
add_compile_options(
|
||||
-O3 # Optimize for speed
|
||||
-Wall # Enable most warning messages
|
||||
-Wextra # Enable additional warning messages
|
||||
-fuse-linker-plugin # Use LTO plugin to enable link-time optimization
|
||||
-ftree-vectorize # Enable loop vectorization
|
||||
-fno-fast-math # Standard-compliant floating point math
|
||||
-fno-unsafe-math-optimizations # Use safe math only
|
||||
)
|
||||
add_link_options(
|
||||
-Wl,--gc-sections # Remove unused sections during linking
|
||||
-fuse-linker-plugin # Enable LTO during linking
|
||||
)
|
||||
if(PRODUCTION_OPTIMIZATION)
|
||||
# MinGW-specific settings
|
||||
if(WIN32 AND MINGW)
|
||||
add_compile_options(
|
||||
-O3 # Optimize for speed
|
||||
-Wall # Enable most warning messages
|
||||
-Wextra # Enable additional warning messages
|
||||
-fuse-linker-plugin # Use LTO plugin
|
||||
-ftree-vectorize # Enable loop vectorization
|
||||
-fno-fast-math # Standard-compliant floating point math
|
||||
-fno-unsafe-math-optimizations # Use safe math only
|
||||
)
|
||||
add_link_options(
|
||||
-Wl,--gc-sections # Remove unused sections during linking
|
||||
-fuse-linker-plugin # Enable LTO during linking
|
||||
)
|
||||
|
||||
# MSVC-specific settings
|
||||
elseif(WIN32 AND MSVC)
|
||||
add_compile_options(
|
||||
/permissive- # Enable strict ISO compliance
|
||||
/Zc:__cplusplus # Correct __cplusplus value
|
||||
/Zc:preprocessor # Enable standards-conforming preprocessor
|
||||
/MP # Multi-processor compilation
|
||||
/vmg # Use general pointer-to-member representation
|
||||
/Ox # Optimize for speed
|
||||
/W3 # Warning level 3 messages
|
||||
/GL # Enable whole program optimization
|
||||
/MT # Link compiler runtime statically
|
||||
/Qvec # Enable loop vectorization
|
||||
/fp:strict # Standard-compliant floating point math
|
||||
)
|
||||
add_link_options(
|
||||
/OPT:REF # Remove unreferenced functions/data
|
||||
/OPT:ICF # Remove identical COMDATs
|
||||
/LTCG # Enable LTO during linkingn
|
||||
)
|
||||
|
||||
#
|
||||
# MSVC-specific settings
|
||||
#
|
||||
elseif(WIN32 AND MSVC)
|
||||
add_compile_options(
|
||||
/permissive- # Enable strict ISO compliance
|
||||
/Zc:__cplusplus # Correct __cplusplus value
|
||||
/Zc:preprocessor # Enable standards-conforming preprocessor
|
||||
/MP # Multi-processor compilation for faster builds
|
||||
/vmg # Use general pointer-to-member representation
|
||||
/Ox # Optimize for speed
|
||||
/W3 # Warning level 3 messages
|
||||
/GL # Enable whole program optimization
|
||||
/MT # Link compiler runtime statically
|
||||
/Qvec # Enable loop vectorization
|
||||
/fp:strict # Standard-compliant floating point math
|
||||
)
|
||||
add_link_options(
|
||||
/OPT:REF # Remove unreferenced functions/data
|
||||
/OPT:ICF # Remove identical COMDATs
|
||||
/LTCG # Enable LTO during linkingn
|
||||
)
|
||||
# macOS-specific settings
|
||||
elseif(APPLE)
|
||||
add_compile_options(
|
||||
-O3 # Optimize for speed
|
||||
-Wall # Enable most warning messages
|
||||
-Wextra # Enable additional warning messages
|
||||
-fvectorize # Enable loop vectorization
|
||||
-fslp-vectorize # Enable SLP vectorization
|
||||
-fno-fast-math # Standard-compliant floating point math
|
||||
-fno-unsafe-math-optimizations # Use safe math only
|
||||
)
|
||||
add_link_options(
|
||||
-Wl,-dead_strip # Remove unused code and data during linking
|
||||
-flto=full # Link-time optimization
|
||||
)
|
||||
|
||||
#
|
||||
# macOS-specific settings
|
||||
#
|
||||
elseif(APPLE)
|
||||
add_compile_options(
|
||||
-O3 # Optimize for speed
|
||||
-Wall # Enable most warning messages
|
||||
-Wextra # Enable additional warning messages
|
||||
-fvectorize # Enable loop vectorization
|
||||
-fslp-vectorize # Enable SLP vectorization
|
||||
-fno-fast-math # Standard-compliant floating point math
|
||||
-fno-unsafe-math-optimizations # Use safe math only
|
||||
)
|
||||
add_link_options(
|
||||
-Wl,-dead_strip # Remove unused code and data during linking
|
||||
-flto=full # Link-time optimization
|
||||
)
|
||||
# Intel LLVM-based C++ Compiler
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM")
|
||||
add_compile_options(
|
||||
-O3 # Optimize for speed
|
||||
-Wall # Enable most warning messages
|
||||
-Wextra # Enable additional warning messages
|
||||
-static-intel # Static link compiler dependencies
|
||||
-fvectorize # Enable loop vectorization
|
||||
-fslp-vectorize # Enable SLP vectorization
|
||||
-fp-model=precise # Standard-compliant floating point math
|
||||
)
|
||||
add_link_options(
|
||||
-Wl,--gc-sections # Remove unused sections during linking
|
||||
-flto=full # Link-time optimization
|
||||
)
|
||||
|
||||
#
|
||||
# Intel C++ Compiler settings
|
||||
#
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel" OR CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM")
|
||||
add_compile_options(
|
||||
-O3 # Optimize for speed
|
||||
-Wall # Enable most warning messages
|
||||
-Wextra # Enable additional warning messages
|
||||
-static-intel # Static link compiler dependencies
|
||||
-fvectorize # Enable loop vectorization
|
||||
-fslp-vectorize # Enable SLP vectorization
|
||||
-fp-model=precise # Standard-compliant floating point math
|
||||
)
|
||||
add_link_options(
|
||||
-Wl,--gc-sections # Remove unused sections during linking
|
||||
-flto=full # Link-time optimization
|
||||
)
|
||||
|
||||
#
|
||||
# Generic UNIX/Linux settings
|
||||
#
|
||||
elseif(UNIX)
|
||||
add_compile_options(
|
||||
-O3 # Optimize for speed
|
||||
-Wall # Enable most warning messages
|
||||
-Wextra # Enable additional warning messages
|
||||
-ftree-vectorize # Enable loop vectorization
|
||||
-fno-fast-math # Standard-compliant floating point math
|
||||
-fno-unsafe-math-optimizations # Use safe math only
|
||||
)
|
||||
add_link_options(
|
||||
-Wl,--gc-sections # Remove unused sections during linking
|
||||
-flto # Link-time optimization
|
||||
)
|
||||
|
||||
# Needed when compiling for OpenSUSE
|
||||
set(CMAKE_C_COMPILER_AR "/usr/bin/ar")
|
||||
set(CMAKE_CXX_COMPILER_AR "/usr/bin/ar")
|
||||
set(CMAKE_C_COMPILER_RANLIB "/usr/bin/ranlib")
|
||||
set(CMAKE_CXX_COMPILER_RANLIB "/usr/bin/ranlib")
|
||||
# Generic UNIX/Linux settings
|
||||
elseif(UNIX)
|
||||
add_compile_options(
|
||||
-O3 # Optimize for speed
|
||||
-Wall # Enable most warning messages
|
||||
-Wextra # Enable additional warning messages
|
||||
-ftree-vectorize # Enable loop vectorization
|
||||
-fno-fast-math # Standard-compliant floating point math
|
||||
-fno-unsafe-math-optimizations # Use safe math only
|
||||
)
|
||||
add_link_options(
|
||||
-Wl,--gc-sections # Remove unused sections during linking
|
||||
-flto # Link-time optimization
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Set UNIX friendly name for app
|
||||
# Sanitizer flags
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
if (UNIX AND NOT APPLE)
|
||||
set(PROJECT_EXECUTABLE "serial-studio")
|
||||
if(DEBUG_SANITIZER)
|
||||
add_compile_options(
|
||||
-fsanitize=address # Enable AddressSanitizer
|
||||
-fsanitize=undefined # Enable UndefinedBehaviorSanitizer
|
||||
-fsanitize=leak # Enable LeakSanitizer
|
||||
-g # Generate debug symbols
|
||||
-fno-omit-frame-pointer # Preserve frame pointers
|
||||
)
|
||||
|
||||
add_link_options(
|
||||
-fsanitize=address # Link AddressSanitizer
|
||||
-fsanitize=undefined # Link UndefinedBehaviorSanitizer
|
||||
-fsanitize=leak # Link LeakSanitizer
|
||||
)
|
||||
endif()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
@ -199,3 +215,14 @@ endif()
|
||||
|
||||
add_subdirectory(lib)
|
||||
add_subdirectory(app)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Log compiler and linker flags
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
get_directory_property(SUBDIRECTORY_COMPILE_OPTIONS DIRECTORY lib COMPILE_OPTIONS)
|
||||
message(STATUS "LIB Compile Options: ${SUBDIRECTORY_COMPILE_OPTIONS}")
|
||||
|
||||
get_directory_property(SUBDIRECTORY_COMPILE_OPTIONS DIRECTORY app COMPILE_OPTIONS)
|
||||
message(STATUS "APP Compile Options: ${SUBDIRECTORY_COMPILE_OPTIONS}")
|
||||
|
||||
|
@ -54,8 +54,8 @@ Once Qt is installed, you can compile the project by opening the **CMakeLists.tx
|
||||
```bash
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ../
|
||||
cmake --build . -j 16
|
||||
cmake ../ -DPRODUCTION_OPTIMIZATION=ON -DCMAKE_BUILD_TYPE=Release
|
||||
cmake --build . -j 16
|
||||
```
|
||||
|
||||
## Support & Tipping
|
||||
|
@ -43,8 +43,8 @@ Widgets::MultiPlot::MultiPlot(const int index, QQuickItem *parent)
|
||||
{
|
||||
// Obtain min/max values from datasets
|
||||
const auto &group = GET_GROUP(SerialStudio::DashboardMultiPlot, m_index);
|
||||
m_minY = std::numeric_limits<double>::max();
|
||||
m_maxY = std::numeric_limits<double>::lowest();
|
||||
m_minY = std::numeric_limits<qreal>::max();
|
||||
m_maxY = std::numeric_limits<qreal>::lowest();
|
||||
for (const auto &dataset : group.datasets())
|
||||
{
|
||||
m_labels.append(dataset.title());
|
||||
@ -299,8 +299,8 @@ void Widgets::MultiPlot::calculateAutoScaleRange()
|
||||
{
|
||||
const auto &group = GET_GROUP(SerialStudio::DashboardMultiPlot, m_index);
|
||||
|
||||
m_minY = std::numeric_limits<double>::max();
|
||||
m_maxY = std::numeric_limits<double>::lowest();
|
||||
m_minY = std::numeric_limits<qreal>::max();
|
||||
m_maxY = std::numeric_limits<qreal>::lowest();
|
||||
|
||||
for (const auto &dataset : group.datasets())
|
||||
{
|
||||
@ -320,8 +320,8 @@ void Widgets::MultiPlot::calculateAutoScaleRange()
|
||||
if (!ok)
|
||||
{
|
||||
// Initialize values to ensure that min/max are set
|
||||
m_minY = std::numeric_limits<double>::max();
|
||||
m_maxY = std::numeric_limits<double>::lowest();
|
||||
m_minY = std::numeric_limits<qreal>::max();
|
||||
m_maxY = std::numeric_limits<qreal>::lowest();
|
||||
|
||||
// Loop through each dataset and find the min and max values
|
||||
for (const auto &dataset : m_data)
|
||||
|
@ -210,8 +210,8 @@ void Widgets::Plot::calculateAutoScaleRange()
|
||||
if (!ok)
|
||||
{
|
||||
// Initialize values to ensure that min/max are set
|
||||
m_minY = std::numeric_limits<double>::max();
|
||||
m_maxY = std::numeric_limits<double>::lowest();
|
||||
m_minY = std::numeric_limits<qreal>::max();
|
||||
m_maxY = std::numeric_limits<qreal>::lowest();
|
||||
|
||||
// Loop through the plot data and update the min and max
|
||||
m_minY = SIMD::findMin(m_data, [](const QPointF &p) { return p.y(); });
|
||||
|
Loading…
x
Reference in New Issue
Block a user