Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ project(notonlymodbusscope
VERSION 0.0.1
)

add_definitions("-DDEBUG")

set(SCOPESOURCE ScopeSource)

if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build type" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "RelWithDebInfo" "MinSizeRel")
endif()

message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

set(CMAKE_CXX_STANDARD 20)
Expand Down Expand Up @@ -50,26 +55,17 @@ set(QT_LIB
Qt::SerialPort
)

include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/libraries
)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
add_compile_options(-Wall -Wextra -Werror)
if (MINGW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wa,-mbig-obj")
add_compile_options(-Wa,-mbig-obj)
endif()


if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# Code Coverage Report
if(USE_GCOV)
message(STATUS "Enabling coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
message(STATUS "Enabling coverage")
add_compile_options(--coverage)
add_link_options(--coverage)
endif()
endif()

Expand Down
2 changes: 1 addition & 1 deletion libraries/muparser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic")
endif()

FILE(GLOB_RECURSE MUPARSER_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp") #all .cpp
FILE(GLOB_RECURSE MUPARSER_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp") #all .cpp
add_library(muparser ${MUPARSER_SOURCES})

# Use the headers in the build-tree or the installed ones
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -ex
mkdir -p release
cd release

cmake -GNinja ..
cmake -GNinja -DCMAKE_BUILD_TYPE=Release ..
ninja

ctest --output-on-failure
2 changes: 1 addition & 1 deletion scripts/build_windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ echo %PATH%

g++ -v

cmake -G "Ninja" ..
cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release ..
IF ERRORLEVEL 1 GOTO errorHandling

ninja
Expand Down
1 change: 1 addition & 0 deletions scripts/run_clang_tidy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SINGLE_FILE="${1:-}"

echo "=== Configuring (compile_commands.json) ==="
cmake -GNinja \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_PREFIX_PATH="${QT_PREFIX}" \
-B "${BUILD_DIR}"
Expand Down
1 change: 1 addition & 0 deletions scripts/run_clazy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SINGLE_FILE="${1:-}"

echo "=== Configuring (compile_commands.json) ==="
cmake -GNinja \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DCMAKE_PREFIX_PATH="${QT_PREFIX}" \
-B "${BUILD_DIR}"
Expand Down
24 changes: 18 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,30 @@ execute_process(
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/util/version.h.in ${CMAKE_CURRENT_SOURCE_DIR}/util/version.h)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../resources/modbusscope.rc.in ${CMAKE_CURRENT_SOURCE_DIR}/../resources/modbusscope.rc)

FILE(GLOB_RECURSE SRCS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/*.h") #all .cpp/.h in current "src" folder and sub folders
FILE(GLOB_RECURSE UIS "${CMAKE_CURRENT_SOURCE_DIR}/*.ui") #all .ui in current "src" folder and sub folders
file(GLOB_RECURSE SRCS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/*.h") #all .cpp/.h in current "src" folder and sub folders
file(GLOB_RECURSE UIS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.ui") #all .ui in current "src" folder and sub folders

qt_add_library (${SCOPESOURCE} STATIC ${SRCS} ${UIS})
qt_add_library(${SCOPESOURCE} STATIC ${SRCS} ${UIS})

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_definitions(${SCOPESOURCE} PRIVATE DEBUG)
endif()
Comment on lines +26 to +28
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify config-gating patterns for DEBUG in CMake files.
# Expected: avoid compile-definition gating via CMAKE_BUILD_TYPE;
# prefer generator expressions like $<$<CONFIG:Debug>:DEBUG>.

rg -n --type=cmake -C3 'CMAKE_BUILD_TYPE\s+STREQUAL\s+"Debug"|target_compile_definitions\s*\(.*DEBUG|\$<CONFIG:Debug>'

Repository: ModbusScope/NotOnlyModbusScope

Length of output: 1695


Use config-aware DEBUG definition instead of CMAKE_BUILD_TYPE check.

Line 26 silently misses DEBUG on multi-config generators (notably Windows/Visual Studio), even for Debug builds. CMAKE_BUILD_TYPE is not populated in multi-config generators; use a generator expression tied to the active configuration instead.

Suggested fix
-if(CMAKE_BUILD_TYPE STREQUAL "Debug")
-    target_compile_definitions(${SCOPESOURCE} PRIVATE DEBUG)
-endif()
+target_compile_definitions(${SCOPESOURCE} PRIVATE
+    $<$<CONFIG:Debug>:DEBUG>
+)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_definitions(${SCOPESOURCE} PRIVATE DEBUG)
endif()
target_compile_definitions(${SCOPESOURCE} PRIVATE
$<$<CONFIG:Debug>:DEBUG>
)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/CMakeLists.txt` around lines 26 - 28, The CMake check using
CMAKE_BUILD_TYPE misses Debug mode on multi-config generators; replace the
CMAKE_BUILD_TYPE conditional with a config-aware generator expression on the
target (${SCOPESOURCE}) so the DEBUG definition is added only for Debug
configurations (e.g., use target_compile_definitions(${SCOPESOURCE} PRIVATE
$<$<CONFIG:Debug>:DEBUG>) or the equivalent generator-expression form) to ensure
DEBUG is defined when the active configuration is Debug across single- and
multi-config generators.


target_include_directories(${SCOPESOURCE} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)

target_include_directories(${SCOPESOURCE} SYSTEM PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../libraries
)

# Default GUI type is blank
set(GUI_TYPE "")

if(WIN32)
set(GUI_TYPE WIN32)
set(target_dir "bin/win")
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(target_dir "bin/linux")
else()
message(SEND_ERROR "You are on an unsupported platform! (Not Win or Unix)")
Expand Down Expand Up @@ -62,10 +74,10 @@ add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
)

# Do platform specific post target stuff
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")

install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)

elseif(WIN32)
# not required
endif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
endif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
6 changes: 2 additions & 4 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
add_definitions(-DGTEST_LANGUAGE_CXX11)

find_package(Threads REQUIRED)

if ($ENV{GOOGLETEST_DIR})
Expand All @@ -16,8 +14,6 @@ else ()
message( FATAL_ERROR "No googletest src dir found - set GOOGLETEST_DIR to enable!")
endif ()

include_directories(${GTestSrc} ${GTestSrc}/include ${GMockSrc} ${GMockSrc}/include)

set(
GOOGLE_TEST_SOURCE
${GTestSrc}/src/gtest-all.cc
Expand All @@ -43,6 +39,8 @@ function(add_xtest_mock SOURCE_NAME)
${SOURCE_NAME}.cpp
${GOOGLE_TEST_SOURCE}
${ARGN})
target_include_directories(${SOURCE_NAME} PRIVATE ${GTestSrc} ${GTestSrc}/include ${GMockSrc} ${GMockSrc}/include)
target_compile_definitions(${SOURCE_NAME} PRIVATE GTEST_LANGUAGE_CXX11)
target_link_libraries(${SOURCE_NAME} Qt::Test Threads::Threads ${QT_LIB} ${SCOPESOURCE})
add_test(NAME ${SOURCE_NAME} COMMAND ${SOURCE_NAME})
endfunction()
Expand Down