Skip to content

Commit a0b1285

Browse files
authored
added CMake option BUILD_CORE_DLL to build lib as cppcheck-core.dll with Visual Studio (#4733)
1 parent c3aa094 commit a0b1285

14 files changed

Lines changed: 80 additions & 28 deletions

File tree

.github/workflows/iwyu.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Prepare CMake dependencies
3434
run: |
3535
# make sure the precompiled headers exist
36-
#make -C cmake.output lib/CMakeFiles/lib_objs.dir/cmake_pch.hxx.cxx
36+
#make -C cmake.output lib/CMakeFiles/cppcheck-core.dir/cmake_pch.hxx.cxx
3737
#make -C cmake.output test/CMakeFiles/testrunner.dir/cmake_pch.hxx.cxx
3838
# make sure the auto-generated GUI sources exist
3939
make -C cmake.output autogen

.github/workflows/selfcheck.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
- name: Generate dependencies
5959
run: |
6060
# make sure the precompiled headers exist
61-
make -C cmake.output lib/CMakeFiles/lib_objs.dir/cmake_pch.hxx.cxx
61+
make -C cmake.output lib/CMakeFiles/cppcheck-core.dir/cmake_pch.hxx.cxx
6262
make -C cmake.output test/CMakeFiles/testrunner.dir/cmake_pch.hxx.cxx
6363
# make sure auto-generated GUI files exist
6464
make -C cmake.output autogen
@@ -81,7 +81,7 @@ jobs:
8181
- name: Generate dependencies (no test)
8282
run: |
8383
# make sure the precompiled headers exist
84-
make -C cmake.output.notest lib/CMakeFiles/lib_objs.dir/cmake_pch.hxx.cxx
84+
make -C cmake.output.notest lib/CMakeFiles/cppcheck-core.dir/cmake_pch.hxx.cxx
8585
# make sure auto-generated GUI files exist
8686
make -C cmake.output.notest autogen
8787
make -C cmake.output.notest gui-build-deps
@@ -106,7 +106,7 @@ jobs:
106106
- name: Generate dependencies (corpus)
107107
run: |
108108
# make sure the precompiled headers exist
109-
make -C cmake.output.notest lib/CMakeFiles/lib_objs.dir/cmake_pch.hxx.cxx
109+
make -C cmake.output.notest lib/CMakeFiles/cppcheck-core.dir/cmake_pch.hxx.cxx
110110
# make sure auto-generated GUI files exist
111111
make -C cmake.output.corpus autogen
112112
make -C cmake.output.corpus gui-build-deps

cli/CMakeLists.txt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,25 @@ else()
1111
target_include_directories(cli_objs SYSTEM PRIVATE ${tinyxml2_INCLUDE_DIRS})
1212
endif()
1313
target_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)
14+
if (BUILD_CORE_DLL)
15+
target_compile_definitions(cli_objs PRIVATE CPPCHECKLIB_IMPORT TINYXML2_IMPORT)
16+
endif()
1417

1518
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14)
1619
# false positive warning in up to Clang 13 - caused by FD_ZERO macro
1720
set_source_files_properties(processexecutor.cpp PROPERTIES COMPILE_FLAGS -Wno-reserved-identifier)
1821
endif()
1922

20-
list(APPEND cppcheck_SOURCES ${hdrs} ${mainfile} $<TARGET_OBJECTS:cli_objs> $<TARGET_OBJECTS:lib_objs> $<TARGET_OBJECTS:simplecpp_objs>)
21-
if(USE_BUNDLED_TINYXML2)
22-
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:tinyxml2_objs>)
23+
list(APPEND cppcheck_SOURCES ${hdrs} ${mainfile} $<TARGET_OBJECTS:cli_objs>)
24+
if (NOT BUILD_CORE_DLL)
25+
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:cppcheck-core>)
26+
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:simplecpp_objs>)
27+
if(USE_BUNDLED_TINYXML2)
28+
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:tinyxml2_objs>)
29+
endif()
30+
endif()
31+
if (WIN32)
32+
list(APPEND cppcheck_SOURCES version.rc)
2333
endif()
2434

2535
add_executable(cppcheck ${cppcheck_SOURCES})
@@ -44,6 +54,9 @@ if(tinyxml2_FOUND AND NOT USE_BUNDLED_TINYXML2)
4454
target_link_libraries(cppcheck ${tinyxml2_LIBRARIES})
4555
endif()
4656
target_link_libraries(cppcheck ${CMAKE_THREAD_LIBS_INIT})
57+
if (BUILD_CORE_DLL)
58+
target_link_libraries(cppcheck cppcheck-core)
59+
endif()
4760

4861
add_dependencies(cppcheck copy_cfg)
4962
add_dependencies(cppcheck copy_addons)

cmake/compilerDefinitions.cmake

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ if (MSVC)
44
add_definitions(-DDEBUG)
55
endif()
66

7-
#add_definitions(-DCPPCHECKLIB_IMPORT)
8-
#add_definitions(-DTINYXML2_IMPORT)
97
add_definitions(-DWIN32)
108
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
119
add_definitions(-DWIN32_LEAN_MEAN)

cmake/options.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ else()
3131
set(USE_MATCHCOMPILER_OPT ${USE_MATCHCOMPILER})
3232
endif()
3333

34+
option(BUILD_CORE_DLL "Build lib as cppcheck-core.dll with Visual Studio" OFF)
35+
if (NOT MSVC)
36+
set(BUILD_CORE_DLL OFF)
37+
endif()
3438
option(BUILD_TESTS "Build tests" OFF)
3539
option(REGISTER_TESTS "Register tests in CTest" ON)
3640
option(ENABLE_CHECK_INTERNAL "Enable internal checks" OFF)
@@ -42,6 +46,9 @@ option(USE_QT6 "Prefer Qt6 when available"
4246

4347
option(HAVE_RULES "Usage of rules (needs PCRE library and headers)" OFF)
4448
option(USE_BUNDLED_TINYXML2 "Usage of bundled tinyxml2 library" ON)
49+
if (BUILD_CORE_DLL)
50+
set(USE_BUNDLED_TINYXML2 ON)
51+
endif()
4552
option(CPPCHK_GLIBCXX_DEBUG "Usage of STL debug checks in Debug build" ON)
4653
option(USE_THREADS "Usage of threads instead of fork() for -j" OFF)
4754
option(USE_BOOST "Usage of Boost" OFF)

cmake/printInfo.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ else()
3939
message( STATUS "BUILD_SHARED_LIBS = ${BUILD_SHARED_LIBS}" )
4040
endif(NOT DEFINED BUILD_SHARED_LIBS)
4141
message( STATUS "LIBXML2_XMLLINT_EXECUTABLE = ${LIBXML2_XMLLINT_EXECUTABLE}" )
42+
message( STATUS "BUILD_CORE_DLL = ${BUILD_CORE_DLL}" )
4243
message( STATUS "BUILD_TESTS = ${BUILD_TESTS}" )
4344
if(BUILD_TESTS)
4445
message( STATUS "REGISTER_TESTS = ${REGISTER_TESTS}" )

externals/simplecpp/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ file(GLOB hdrs "*.h")
22
file(GLOB srcs "*.cpp")
33

44
add_library(simplecpp_objs OBJECT ${srcs} ${hdrs})
5+
if (BUILD_CORE_DLL)
6+
target_compile_definitions(simplecpp_objs PRIVATE SIMPLECPP_EXPORT)
7+
endif()
8+
59
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
610
target_compile_options_safe(simplecpp_objs -Wno-zero-as-null-pointer-constant)
711
endif()

externals/tinyxml2/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ file(GLOB hdrs "*.h")
22
file(GLOB srcs "*.cpp")
33

44
add_library(tinyxml2_objs OBJECT ${srcs} ${hdrs})
5+
if (BUILD_CORE_DLL)
6+
target_compile_definitions(tinyxml2_objs PRIVATE TINYXML2_EXPORT)
7+
endif()
58

69
# TODO: needs to be fixed upstream
710
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")

gui/CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ CheckOptions:
2828
list(APPEND cppcheck-gui-deps ${hdrs} ${uis_hdrs} ${resources} ${qms})
2929
add_custom_target(gui-build-deps SOURCES ${cppcheck-gui-deps})
3030

31-
list(APPEND cppcheck-gui_SOURCES ${srcs} $<TARGET_OBJECTS:lib_objs> $<TARGET_OBJECTS:simplecpp_objs>)
32-
if(USE_BUNDLED_TINYXML2)
33-
list(APPEND cppcheck-gui_SOURCES $<TARGET_OBJECTS:tinyxml2_objs>)
31+
list(APPEND cppcheck-gui_SOURCES ${srcs})
32+
if (NOT BUILD_CORE_DLL)
33+
list(APPEND cppcheck-gui_SOURCES $<TARGET_OBJECTS:cppcheck-core> $<TARGET_OBJECTS:simplecpp_objs>)
34+
if(USE_BUNDLED_TINYXML2)
35+
list(APPEND cppcheck-gui_SOURCES $<TARGET_OBJECTS:tinyxml2_objs>)
36+
endif()
3437
endif()
3538

3639
add_executable(cppcheck-gui ${cppcheck-gui-deps} ${cppcheck-gui_SOURCES})
@@ -52,6 +55,10 @@ CheckOptions:
5255
target_compile_definitions (cppcheck-gui PRIVATE HAVE_QCHART)
5356
target_link_libraries(cppcheck-gui ${QT_CHARTS_LIB})
5457
endif()
58+
if (BUILD_CORE_DLL)
59+
target_compile_definitions(cppcheck-gui PRIVATE CPPCHECKLIB_IMPORT TINYXML2_IMPORT)
60+
target_link_libraries(cppcheck-gui cppcheck-core)
61+
endif()
5562
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
5663
# Q_UNUSED() in generated code
5764
target_compile_options_safe(cppcheck-gui -Wno-extra-semi-stmt)
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
qt_wrap_cpp(test-xmlreportv2_SRC testxmlreportv2.h)
22
add_custom_target(build-xmlreportv2-deps SOURCES ${test-xmlreportv2_SRC})
33
add_dependencies(gui-build-deps build-xmlreportv2-deps)
4-
if(USE_BUNDLED_TINYXML2)
5-
list(APPEND test-xmlreportv2_SRC $<TARGET_OBJECTS:tinyxml2_objs>)
4+
if (NOT BUILD_CORE_DLL)
5+
list(APPEND test-xmlreportv2_SRC $<TARGET_OBJECTS:cppcheck-core> $<TARGET_OBJECTS:simplecpp_objs>)
6+
if(USE_BUNDLED_TINYXML2)
7+
list(APPEND test-xmlreportv2_SRC $<TARGET_OBJECTS:tinyxml2_objs>)
8+
endif()
69
endif()
710
add_executable(test-xmlreportv2
811
${test-xmlreportv2_SRC}
@@ -11,8 +14,6 @@ add_executable(test-xmlreportv2
1114
${CMAKE_SOURCE_DIR}/gui/report.cpp
1215
${CMAKE_SOURCE_DIR}/gui/xmlreport.cpp
1316
${CMAKE_SOURCE_DIR}/gui/xmlreportv2.cpp
14-
$<TARGET_OBJECTS:lib_objs>
15-
$<TARGET_OBJECTS:simplecpp_objs>
1617
)
1718
target_include_directories(test-xmlreportv2 PRIVATE ${CMAKE_SOURCE_DIR}/gui ${CMAKE_SOURCE_DIR}/lib)
1819
target_compile_definitions(test-xmlreportv2 PRIVATE SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}")
@@ -23,3 +24,7 @@ endif()
2324
if(tinyxml2_FOUND AND NOT USE_BUNDLED_TINYXML2)
2425
target_link_libraries(test-xmlreportv2 ${tinyxml2_LIBRARIES})
2526
endif()
27+
if (BUILD_CORE_DLL)
28+
target_compile_definitions(test-xmlreportv2 PRIVATE CPPCHECKLIB_IMPORT TINYXML2_IMPORT)
29+
target_link_libraries(test-xmlreportv2 cppcheck-core)
30+
endif()

0 commit comments

Comments
 (0)