Skip to content
Open
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ if(USE_BUNDLED_TINYXML2)
add_subdirectory(externals/tinyxml2)
endif()
add_subdirectory(externals/simplecpp)
add_subdirectory(externals/picojson)
add_subdirectory(lib) # CppCheck Library
add_subdirectory(frontend)
add_subdirectory(cli) # Client application
Expand Down
65 changes: 17 additions & 48 deletions cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,68 +1,37 @@
if (BUILD_CLI)

file(GLOB hdrs "*.h")
file(GLOB srcs "*.cpp")
file(GLOB mainfile "main.cpp")
list(REMOVE_ITEM srcs ${mainfile})
file(GLOB hdrs "*.h")
file(GLOB srcs "*.cpp")
file(GLOB mainfile "main.cpp")
list(REMOVE_ITEM srcs ${mainfile})

add_library(cli_objs OBJECT ${hdrs} ${srcs})
target_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/lib/ ${PROJECT_SOURCE_DIR}/frontend/)
if(USE_BUNDLED_TINYXML2)
target_externals_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
else()
target_include_directories(cli_objs SYSTEM PRIVATE ${tinyxml2_INCLUDE_DIRS})
endif()
target_externals_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/picojson/)
target_externals_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)
if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
target_precompile_headers(cli_objs PRIVATE precompiled.h)
endif()
if (BUILD_CORE_DLL)
target_compile_definitions(cli_objs PRIVATE CPPCHECKLIB_IMPORT TINYXML2_IMPORT)
endif()
add_library(cli ${hdrs} ${srcs})
target_include_directories(cli PUBLIC .)
target_link_libraries(cli PRIVATE cppcheck-core frontend tinyxml2 simplecpp picojson)
if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
target_precompile_headers(cli PRIVATE precompiled.h)
endif()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 13)
# false positive warning in Clang 13 - caused by FD_ZERO macro
set_source_files_properties(processexecutor.cpp PROPERTIES COMPILE_FLAGS -Wno-reserved-identifier)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 13)
# false positive warning in Clang 13 - caused by FD_ZERO macro
set_source_files_properties(processexecutor.cpp PROPERTIES COMPILE_FLAGS -Wno-reserved-identifier)
endif()

list(APPEND cppcheck_SOURCES ${hdrs} ${mainfile} $<TARGET_OBJECTS:cli_objs> $<TARGET_OBJECTS:frontend_objs>)
if (NOT BUILD_CORE_DLL)
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:cppcheck-core>)
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:simplecpp_objs>)
if(USE_BUNDLED_TINYXML2)
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:tinyxml2_objs>)
endif()
endif()
if (BUILD_CLI)
list(APPEND cppcheck_SOURCES ${hdrs} ${mainfile})
if (WIN32)
list(APPEND cppcheck_SOURCES version.rc)
endif()

add_executable(cppcheck ${cppcheck_SOURCES})
target_include_directories(cppcheck PRIVATE ${PROJECT_SOURCE_DIR}/lib/)
if(USE_BUNDLED_TINYXML2)
target_externals_include_directories(cppcheck PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
else()
target_include_directories(cppcheck SYSTEM PRIVATE ${tinyxml2_INCLUDE_DIRS})
endif()
target_externals_include_directories(cppcheck PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)
if (HAVE_RULES)
target_link_libraries(cppcheck ${PCRE_LIBRARY})
endif()
target_link_libraries(cppcheck cppcheck-core cli tinyxml2 simplecpp)
if (WIN32 AND NOT BORLAND)
if(NOT MINGW)
target_link_libraries(cppcheck Shlwapi.lib)
else()
target_link_libraries(cppcheck shlwapi)
endif()
endif()
if(tinyxml2_FOUND AND NOT USE_BUNDLED_TINYXML2)
target_link_libraries(cppcheck ${tinyxml2_LIBRARIES})
endif()
target_link_libraries(cppcheck ${CMAKE_THREAD_LIBS_INIT})
if (BUILD_CORE_DLL)
target_link_libraries(cppcheck cppcheck-core)
endif()

add_dependencies(cppcheck copy_cfg)
add_dependencies(cppcheck copy_addons)
Expand Down
22 changes: 22 additions & 0 deletions cmake/compileroptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@ function(target_externals_include_directories TARGET)
endif()
endfunction()

function(target_dll_compile_definitions TARGET)
set(options)
set(oneValueArgs IMPORT EXPORT)
set(multiValueArgs)

cmake_parse_arguments(PARSE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(PARSE_UNPARSED_ARGUMENTS)
message(
FATAL_ERROR "Unknown keywords given to target_dll_compile_definitions(): \"${PARSE_UNPARSED_ARGUMENTS}\"")
endif()


if (BUILD_SHARED_LIBS AND MSVC)
if(PARSE_EXPORT)
target_compile_definitions(${TARGET} PRIVATE ${PARSE_EXPORT})
endif()
if(PARSE_IMPORT)
target_compile_definitions(${TARGET} INTERFACE ${PARSE_IMPORT})
endif()
endif()
endfunction()

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Weverything)
endif()
Expand Down
6 changes: 4 additions & 2 deletions cmake/findDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ else()
endif()

if(NOT USE_BUNDLED_TINYXML2)
add_library(tinyxml2 INTERFACE)
find_package(tinyxml2 QUIET)
if(TARGET tinyxml2::tinyxml2)
set(tinyxml2_LIBRARIES "tinyxml2::tinyxml2")
set(tinyxml2_INCLUDE_DIRS $<TARGET_PROPERTY:tinyxml2::tinyxml2,INTERFACE_INCLUDE_DIRECTORIES>)
target_link_libraries(tinyxml2 INTERFACE tinyxml2::tinyxml2)
else()
find_library(tinyxml2_LIBRARIES tinyxml2)
find_path(tinyxml2_INCLUDE_DIRS tinyxml2.h)
Expand All @@ -73,6 +73,8 @@ if(NOT USE_BUNDLED_TINYXML2)
else()
set(tinyxml2_FOUND 1)
endif()
target_link_libraries(tinyxml2 INTERFACE ${tinyxml2_LIBRARIES})
target_include_directories(tinyxml2 INTERFACE ${tinyxml2_INCLUDE_DIRS})
endif()
endif()

Expand Down
4 changes: 4 additions & 0 deletions externals/picojson/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

add_library(picojson INTERFACE)
target_externals_include_directories(picojson INTERFACE .)

10 changes: 5 additions & 5 deletions externals/simplecpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
file(GLOB hdrs "*.h")
file(GLOB srcs "*.cpp")

add_library(simplecpp_objs OBJECT ${srcs} ${hdrs})
if (BUILD_CORE_DLL)
target_compile_definitions(simplecpp_objs PRIVATE SIMPLECPP_EXPORT)
endif()
add_library(simplecpp ${srcs} ${hdrs})
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be able to become a shared library.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will if we set BUILD_SHARED_LIBS.

target_dll_compile_definitions(simplecpp EXPORT SIMPLECPP_EXPORT IMPORT SIMPLECPP_IMPORT)

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options_safe(simplecpp_objs -Wno-zero-as-null-pointer-constant)
target_compile_options_safe(simplecpp -Wno-zero-as-null-pointer-constant)
endif()

target_externals_include_directories(simplecpp PUBLIC .)
22 changes: 11 additions & 11 deletions externals/tinyxml2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
file(GLOB hdrs "*.h")
file(GLOB srcs "*.cpp")

add_library(tinyxml2_objs OBJECT ${srcs} ${hdrs})
if (BUILD_CORE_DLL)
target_compile_definitions(tinyxml2_objs PRIVATE TINYXML2_EXPORT)
endif()
add_library(tinyxml2 ${srcs} ${hdrs})
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be able to become a shared library.

target_dll_compile_definitions(tinyxml2 EXPORT TINYXML2_EXPORT IMPORT TINYXML2_IMPORT)

# TODO: needs to be fixed upstream
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(tinyxml2_objs PRIVATE -Wno-suggest-attribute=format)
target_compile_options(tinyxml2_objs PRIVATE -Wno-useless-cast)
target_compile_options(tinyxml2 PRIVATE -Wno-suggest-attribute=format)
target_compile_options(tinyxml2 PRIVATE -Wno-useless-cast)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options_safe(tinyxml2_objs -Wno-implicit-fallthrough)
target_compile_options_safe(tinyxml2_objs -Wno-suggest-destructor-override)
target_compile_options_safe(tinyxml2_objs -Wno-zero-as-null-pointer-constant)
target_compile_options_safe(tinyxml2_objs -Wno-format-nonliteral)
target_compile_options_safe(tinyxml2_objs -Wno-inconsistent-missing-destructor-override)
target_compile_options_safe(tinyxml2 -Wno-implicit-fallthrough)
target_compile_options_safe(tinyxml2 -Wno-suggest-destructor-override)
target_compile_options_safe(tinyxml2 -Wno-zero-as-null-pointer-constant)
target_compile_options_safe(tinyxml2 -Wno-format-nonliteral)
target_compile_options_safe(tinyxml2 -Wno-inconsistent-missing-destructor-override)
endif()
if(CYGWIN)
target_compile_definitions(-D_LARGEFILE_SOURCE) # required for fseeko() and ftello()
endif()

target_externals_include_directories(tinyxml2 PUBLIC .)

5 changes: 3 additions & 2 deletions frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
file(GLOB hdrs "*.h")
file(GLOB srcs "*.cpp")

add_library(frontend_objs OBJECT ${hdrs} ${srcs})
target_include_directories(frontend_objs PRIVATE ${PROJECT_SOURCE_DIR}/lib)
add_library(frontend ${hdrs} ${srcs})
target_include_directories(frontend PUBLIC .)
target_link_libraries(frontend PRIVATE cppcheck-core)
24 changes: 3 additions & 21 deletions gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,26 @@ CheckOptions:
list(APPEND cppcheck-gui-deps ${hdrs} ${uis_hdrs} ${resources} ${qms})
add_custom_target(gui-build-deps SOURCES ${cppcheck-gui-deps})

list(APPEND cppcheck-gui_SOURCES ${srcs} $<TARGET_OBJECTS:frontend_objs>)
if (NOT BUILD_CORE_DLL)
list(APPEND cppcheck-gui_SOURCES $<TARGET_OBJECTS:cppcheck-core> $<TARGET_OBJECTS:simplecpp_objs>)
if(USE_BUNDLED_TINYXML2)
list(APPEND cppcheck-gui_SOURCES $<TARGET_OBJECTS:tinyxml2_objs>)
endif()
endif()
list(APPEND cppcheck-gui_SOURCES ${srcs})
if (WIN32)
list(APPEND cppcheck-gui_SOURCES cppcheck-gui.rc)
endif()

add_executable(cppcheck-gui ${cppcheck-gui-deps} ${cppcheck-gui_SOURCES})
target_link_libraries(cppcheck-gui cppcheck-core simplecpp tinyxml2 picojson frontend)

set_target_properties(cppcheck-gui PROPERTIES AUTOMOC ON)
set_target_properties(cppcheck-gui PROPERTIES WIN32_EXECUTABLE ON)
target_include_directories(cppcheck-gui PRIVATE ${PROJECT_SOURCE_DIR}/lib/ ${PROJECT_SOURCE_DIR}/frontend/)
if(USE_BUNDLED_TINYXML2)
target_externals_include_directories(cppcheck-gui PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
else()
target_include_directories(cppcheck-gui SYSTEM PRIVATE ${tinyxml2_INCLUDE_DIRS})
endif()
target_include_directories(cppcheck-gui PRIVATE ${PROJECT_SOURCE_DIR}/externals/picojson/)
if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
target_precompile_headers(cppcheck-gui PRIVATE precompiled.h)
endif()
if (HAVE_RULES)
target_link_libraries(cppcheck-gui ${PCRE_LIBRARY})
endif()
if(tinyxml2_FOUND AND NOT USE_BUNDLED_TINYXML2)
target_link_libraries(cppcheck-gui ${tinyxml2_LIBRARIES})
endif()
target_link_libraries(cppcheck-gui ${QT_CORE_LIB} ${QT_GUI_LIB} ${QT_WIDGETS_LIB} ${QT_PRINTSUPPORT_LIB} ${QT_HELP_LIB} ${QT_NETWORK_LIB})
if(WITH_QCHART)
target_link_libraries(cppcheck-gui ${QT_CHARTS_LIB})
endif()
if (BUILD_CORE_DLL)
target_compile_definitions(cppcheck-gui PRIVATE CPPCHECKLIB_IMPORT TINYXML2_IMPORT)
target_link_libraries(cppcheck-gui cppcheck-core)
endif()
if(MSVC)
# compilation will fail as e.g. QList::realloc would be replaced by MSVC's macro definition
target_compile_definitions(cppcheck-gui PRIVATE $<$<CONFIG:Debug>:DISABLE_CRTDBG_MAP_ALLOC>)
Expand Down
11 changes: 3 additions & 8 deletions gui/test/filelist/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@ add_executable(test-filelist
${test-filelist_SRC}
testfilelist.cpp
${CMAKE_SOURCE_DIR}/gui/filelist.cpp
${CMAKE_SOURCE_DIR}/lib/pathmatch.cpp
${CMAKE_SOURCE_DIR}/lib/path.cpp
${CMAKE_SOURCE_DIR}/lib/utils.cpp
$<TARGET_OBJECTS:simplecpp_objs>
)
target_include_directories(test-filelist PRIVATE ${CMAKE_SOURCE_DIR}/gui ${CMAKE_SOURCE_DIR}/lib)
target_externals_include_directories(test-filelist PRIVATE ${CMAKE_SOURCE_DIR}/externals/simplecpp)
target_include_directories(test-filelist PRIVATE ${CMAKE_SOURCE_DIR}/gui)
target_compile_definitions(test-filelist PRIVATE SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(test-filelist ${QT_CORE_LIB} ${QT_TEST_LIB})
target_link_libraries(test-filelist ${QT_CORE_LIB} ${QT_TEST_LIB} cppcheck-core simplecpp)

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(QT_VERSION VERSION_GREATER_EQUAL "6.9.0")
Expand All @@ -26,4 +21,4 @@ if (REGISTER_GUI_TESTS)
add_test(NAME test-filelist COMMAND $<TARGET_FILE:test-filelist>)
endif()

add_dependencies(gui-tests test-filelist)
add_dependencies(gui-tests test-filelist)
22 changes: 8 additions & 14 deletions gui/test/resultstree/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ qt_wrap_cpp(test-resultstree_SRC
${CMAKE_SOURCE_DIR}/gui/threadhandler.h
${CMAKE_SOURCE_DIR}/gui/threadresult.h
)
if(USE_BUNDLED_TINYXML2)
list(APPEND test-resultstree_SRC $<TARGET_OBJECTS:tinyxml2_objs>)
endif()
list(APPEND test-resultstree_SRC $<TARGET_OBJECTS:simplecpp_objs> $<TARGET_OBJECTS:cppcheck-core>)
add_custom_target(build-resultstree-deps SOURCES ${test-resultstree_SRC})
add_dependencies(gui-build-deps build-resultstree-deps)
add_executable(test-resultstree
Expand All @@ -21,22 +17,14 @@ add_executable(test-resultstree
${CMAKE_SOURCE_DIR}/gui/report.cpp
${CMAKE_SOURCE_DIR}/gui/xmlreportv2.cpp
)
target_include_directories(test-resultstree PRIVATE ${CMAKE_SOURCE_DIR}/gui ${CMAKE_SOURCE_DIR}/lib)
target_externals_include_directories(test-resultstree PRIVATE ${CMAKE_SOURCE_DIR}/externals/simplecpp)
if(USE_BUNDLED_TINYXML2)
target_externals_include_directories(test-resultstree PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
else()
target_include_directories(test-resultstree SYSTEM PRIVATE ${tinyxml2_INCLUDE_DIRS})
endif()
target_include_directories(test-resultstree PRIVATE ${CMAKE_SOURCE_DIR}/gui)
target_link_libraries(test-resultstree cppcheck-core simplecpp tinyxml2)
if (HAVE_RULES)
target_link_libraries(test-resultstree ${PCRE_LIBRARY})
target_include_directories(test-resultstree SYSTEM PRIVATE ${PCRE_INCLUDE})
endif()
target_compile_definitions(test-resultstree PRIVATE SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(test-resultstree ${QT_CORE_LIB} ${QT_GUI_LIB} ${QT_WIDGETS_LIB} ${QT_TEST_LIB})
if(tinyxml2_FOUND AND NOT USE_BUNDLED_TINYXML2)
target_link_libraries(test-resultstree ${tinyxml2_LIBRARIES})
endif()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(QT_VERSION VERSION_GREATER_EQUAL "6.9.0")
Expand All @@ -52,6 +40,12 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options_safe(test-resultstree -Wno-suggest-attribute=noreturn)
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# caused by mocks
target_compile_options_safe(test-resultstree -Wno-suggest-attribute=noreturn)
endif()


if (REGISTER_GUI_TESTS)
# TODO: might crash - see #13223
#add_test(NAME test-resultstree COMMAND $<TARGET_FILE:test-resultstree> -platform offscreen)
Expand Down
20 changes: 2 additions & 18 deletions gui/test/xmlreportv2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
qt_wrap_cpp(test-xmlreportv2_SRC testxmlreportv2.h)
add_custom_target(build-xmlreportv2-deps SOURCES ${test-xmlreportv2_SRC})
add_dependencies(gui-build-deps build-xmlreportv2-deps)
if (NOT BUILD_CORE_DLL)
list(APPEND test-xmlreportv2_SRC $<TARGET_OBJECTS:cppcheck-core> $<TARGET_OBJECTS:simplecpp_objs>)
if(USE_BUNDLED_TINYXML2)
list(APPEND test-xmlreportv2_SRC $<TARGET_OBJECTS:tinyxml2_objs>)
endif()
endif()
add_executable(test-xmlreportv2
${test-xmlreportv2_SRC}
testxmlreportv2.cpp
Expand All @@ -15,19 +9,9 @@ add_executable(test-xmlreportv2
${CMAKE_SOURCE_DIR}/gui/xmlreport.cpp
${CMAKE_SOURCE_DIR}/gui/xmlreportv2.cpp
)
target_include_directories(test-xmlreportv2 PRIVATE ${CMAKE_SOURCE_DIR}/gui ${CMAKE_SOURCE_DIR}/lib)
target_include_directories(test-xmlreportv2 PRIVATE ${CMAKE_SOURCE_DIR}/gui)
target_compile_definitions(test-xmlreportv2 PRIVATE SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(test-xmlreportv2 ${QT_CORE_LIB} ${QT_TEST_LIB})
if (HAVE_RULES)
target_link_libraries(test-xmlreportv2 ${PCRE_LIBRARY})
endif()
if(tinyxml2_FOUND AND NOT USE_BUNDLED_TINYXML2)
target_link_libraries(test-xmlreportv2 ${tinyxml2_LIBRARIES})
endif()
if (BUILD_CORE_DLL)
target_compile_definitions(test-xmlreportv2 PRIVATE CPPCHECKLIB_IMPORT TINYXML2_IMPORT)
target_link_libraries(test-xmlreportv2 cppcheck-core)
endif()
target_link_libraries(test-xmlreportv2 ${QT_CORE_LIB} ${QT_TEST_LIB} cppcheck-core)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(QT_VERSION VERSION_GREATER_EQUAL "6.9.0")
# caused by Qt generated moc code starting with 6.9.0 - see https://bugreports.qt.io/browse/QTBUG-135638
Expand Down
Loading