Skip to content

Commit

Permalink
added CMake option BUILD_CORE_DLL to build lib as `cppcheck-core.dl…
Browse files Browse the repository at this point in the history
…l` with Visual Studio (danmar#4733)
  • Loading branch information
firewave authored Jan 26, 2023
1 parent c3aa094 commit a0b1285
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/iwyu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Prepare CMake dependencies
run: |
# make sure the precompiled headers exist
#make -C cmake.output lib/CMakeFiles/lib_objs.dir/cmake_pch.hxx.cxx
#make -C cmake.output lib/CMakeFiles/cppcheck-core.dir/cmake_pch.hxx.cxx
#make -C cmake.output test/CMakeFiles/testrunner.dir/cmake_pch.hxx.cxx
# make sure the auto-generated GUI sources exist
make -C cmake.output autogen
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/selfcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
- name: Generate dependencies
run: |
# make sure the precompiled headers exist
make -C cmake.output lib/CMakeFiles/lib_objs.dir/cmake_pch.hxx.cxx
make -C cmake.output lib/CMakeFiles/cppcheck-core.dir/cmake_pch.hxx.cxx
make -C cmake.output test/CMakeFiles/testrunner.dir/cmake_pch.hxx.cxx
# make sure auto-generated GUI files exist
make -C cmake.output autogen
Expand All @@ -81,7 +81,7 @@ jobs:
- name: Generate dependencies (no test)
run: |
# make sure the precompiled headers exist
make -C cmake.output.notest lib/CMakeFiles/lib_objs.dir/cmake_pch.hxx.cxx
make -C cmake.output.notest lib/CMakeFiles/cppcheck-core.dir/cmake_pch.hxx.cxx
# make sure auto-generated GUI files exist
make -C cmake.output.notest autogen
make -C cmake.output.notest gui-build-deps
Expand All @@ -106,7 +106,7 @@ jobs:
- name: Generate dependencies (corpus)
run: |
# make sure the precompiled headers exist
make -C cmake.output.notest lib/CMakeFiles/lib_objs.dir/cmake_pch.hxx.cxx
make -C cmake.output.notest lib/CMakeFiles/cppcheck-core.dir/cmake_pch.hxx.cxx
# make sure auto-generated GUI files exist
make -C cmake.output.corpus autogen
make -C cmake.output.corpus gui-build-deps
Expand Down
19 changes: 16 additions & 3 deletions cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,25 @@ else()
target_include_directories(cli_objs SYSTEM PRIVATE ${tinyxml2_INCLUDE_DIRS})
endif()
target_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)
if (BUILD_CORE_DLL)
target_compile_definitions(cli_objs PRIVATE CPPCHECKLIB_IMPORT TINYXML2_IMPORT)
endif()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14)
# false positive warning in up to 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:lib_objs> $<TARGET_OBJECTS:simplecpp_objs>)
if(USE_BUNDLED_TINYXML2)
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:tinyxml2_objs>)
list(APPEND cppcheck_SOURCES ${hdrs} ${mainfile} $<TARGET_OBJECTS:cli_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 (WIN32)
list(APPEND cppcheck_SOURCES version.rc)
endif()

add_executable(cppcheck ${cppcheck_SOURCES})
Expand All @@ -44,6 +54,9 @@ 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
2 changes: 0 additions & 2 deletions cmake/compilerDefinitions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ if (MSVC)
add_definitions(-DDEBUG)
endif()

#add_definitions(-DCPPCHECKLIB_IMPORT)
#add_definitions(-DTINYXML2_IMPORT)
add_definitions(-DWIN32)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-DWIN32_LEAN_MEAN)
Expand Down
7 changes: 7 additions & 0 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ else()
set(USE_MATCHCOMPILER_OPT ${USE_MATCHCOMPILER})
endif()

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

option(HAVE_RULES "Usage of rules (needs PCRE library and headers)" OFF)
option(USE_BUNDLED_TINYXML2 "Usage of bundled tinyxml2 library" ON)
if (BUILD_CORE_DLL)
set(USE_BUNDLED_TINYXML2 ON)
endif()
option(CPPCHK_GLIBCXX_DEBUG "Usage of STL debug checks in Debug build" ON)
option(USE_THREADS "Usage of threads instead of fork() for -j" OFF)
option(USE_BOOST "Usage of Boost" OFF)
Expand Down
1 change: 1 addition & 0 deletions cmake/printInfo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ else()
message( STATUS "BUILD_SHARED_LIBS = ${BUILD_SHARED_LIBS}" )
endif(NOT DEFINED BUILD_SHARED_LIBS)
message( STATUS "LIBXML2_XMLLINT_EXECUTABLE = ${LIBXML2_XMLLINT_EXECUTABLE}" )
message( STATUS "BUILD_CORE_DLL = ${BUILD_CORE_DLL}" )
message( STATUS "BUILD_TESTS = ${BUILD_TESTS}" )
if(BUILD_TESTS)
message( STATUS "REGISTER_TESTS = ${REGISTER_TESTS}" )
Expand Down
4 changes: 4 additions & 0 deletions externals/simplecpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ 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()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options_safe(simplecpp_objs -Wno-zero-as-null-pointer-constant)
endif()
3 changes: 3 additions & 0 deletions externals/tinyxml2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ 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()

# TODO: needs to be fixed upstream
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
Expand Down
13 changes: 10 additions & 3 deletions gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ 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:lib_objs> $<TARGET_OBJECTS:simplecpp_objs>)
if(USE_BUNDLED_TINYXML2)
list(APPEND cppcheck-gui_SOURCES $<TARGET_OBJECTS:tinyxml2_objs>)
list(APPEND cppcheck-gui_SOURCES ${srcs})
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()

add_executable(cppcheck-gui ${cppcheck-gui-deps} ${cppcheck-gui_SOURCES})
Expand All @@ -52,6 +55,10 @@ CheckOptions:
target_compile_definitions (cppcheck-gui PRIVATE HAVE_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 (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Q_UNUSED() in generated code
target_compile_options_safe(cppcheck-gui -Wno-extra-semi-stmt)
Expand Down
13 changes: 9 additions & 4 deletions gui/test/xmlreportv2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
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(USE_BUNDLED_TINYXML2)
list(APPEND test-xmlreportv2_SRC $<TARGET_OBJECTS:tinyxml2_objs>)
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}
Expand All @@ -11,8 +14,6 @@ add_executable(test-xmlreportv2
${CMAKE_SOURCE_DIR}/gui/report.cpp
${CMAKE_SOURCE_DIR}/gui/xmlreport.cpp
${CMAKE_SOURCE_DIR}/gui/xmlreportv2.cpp
$<TARGET_OBJECTS:lib_objs>
$<TARGET_OBJECTS:simplecpp_objs>
)
target_include_directories(test-xmlreportv2 PRIVATE ${CMAKE_SOURCE_DIR}/gui ${CMAKE_SOURCE_DIR}/lib)
target_compile_definitions(test-xmlreportv2 PRIVATE SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}")
Expand All @@ -23,3 +24,7 @@ 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()
22 changes: 14 additions & 8 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,29 @@ else()
set(srcs_lib ${srcs})
endif()

add_library(lib_objs OBJECT ${srcs_lib} ${hdrs})
if (BUILD_CORE_DLL)
add_library(cppcheck-core SHARED ${srcs_lib} ${hdrs} $<TARGET_OBJECTS:tinyxml2_objs> $<TARGET_OBJECTS:simplecpp_objs> version.rc)
target_compile_definitions(cppcheck-core PRIVATE CPPCHECKLIB_EXPORT TINYXML2_EXPORT SIMPLECPP_EXPORT)
else()
add_library(cppcheck-core OBJECT ${srcs_lib} ${hdrs})
endif()
target_include_directories(cppcheck-core PRIVATE ${PROJECT_SOURCE_DIR}/externals/)
if(USE_BUNDLED_TINYXML2)
target_include_directories(lib_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
target_include_directories(cppcheck-core PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
else()
target_include_directories(lib_objs SYSTEM PRIVATE ${tinyxml2_INCLUDE_DIRS})
target_include_directories(cppcheck-core SYSTEM PRIVATE ${tinyxml2_INCLUDE_DIRS})
endif()
target_include_directories(lib_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/picojson/)
target_include_directories(lib_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)
target_include_directories(cppcheck-core PRIVATE ${PROJECT_SOURCE_DIR}/externals/picojson/)
target_include_directories(cppcheck-core PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)
if (HAVE_RULES)
target_include_directories(lib_objs SYSTEM PRIVATE ${PCRE_INCLUDE})
target_include_directories(cppcheck-core SYSTEM PRIVATE ${PCRE_INCLUDE})
endif()
if (Boost_FOUND)
target_include_directories(lib_objs SYSTEM PRIVATE ${Boost_INCLUDE_DIRS})
target_include_directories(cppcheck-core SYSTEM PRIVATE ${Boost_INCLUDE_DIRS})
endif()

if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
target_precompile_headers(lib_objs PRIVATE precompiled.h)
target_precompile_headers(cppcheck-core PRIVATE precompiled.h)
endif()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
Expand Down
2 changes: 1 addition & 1 deletion oss-fuzz/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if (ENABLE_OSS_FUZZ AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_executable(fuzz-client EXCLUDE_FROM_ALL
${fuzz-client_SRC}
$<TARGET_OBJECTS:simplecpp_objs>
$<TARGET_OBJECTS:lib_objs>)
$<TARGET_OBJECTS:cppcheck-core>)
target_include_directories(fuzz-client PRIVATE ${CMAKE_SOURCE_DIR}/lib ${CMAKE_SOURCE_DIR}/externals/simplecpp ${CMAKE_SOURCE_DIR}/externals)
if(USE_BUNDLED_TINYXML2)
target_include_directories(fuzz-client PRIVATE ${CMAKE_SOURCE_DIR}/externals/tinyxml2/)
Expand Down
1 change: 1 addition & 0 deletions releasenotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ release notes for cppcheck-2.10
- the deprecated Makefile option SRCDIR is no longer accepted
- if the file provided via "--file-list" cannot be opened it will now error out
- add command-line option "--disable=<id>" to individually disable checks
- added CMake option BUILD_CORE_DLL to build lib as cppcheck-core.dll with Visual Studio
13 changes: 10 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
if (BUILD_TESTS)
file(GLOB hdrs "*.h")
file(GLOB srcs "*.cpp")
list(APPEND testrunner_SOURCES ${hdrs} ${srcs} $<TARGET_OBJECTS:lib_objs> $<TARGET_OBJECTS:cli_objs> $<TARGET_OBJECTS:simplecpp_objs>)
if(USE_BUNDLED_TINYXML2)
list(APPEND testrunner_SOURCES $<TARGET_OBJECTS:tinyxml2_objs>)
list(APPEND testrunner_SOURCES ${hdrs} ${srcs} $<TARGET_OBJECTS:cli_objs>)
if (NOT BUILD_CORE_DLL)
list(APPEND testrunner_SOURCES $<TARGET_OBJECTS:cppcheck-core> $<TARGET_OBJECTS:simplecpp_objs>)
if(USE_BUNDLED_TINYXML2)
list(APPEND testrunner_SOURCES $<TARGET_OBJECTS:tinyxml2_objs>)
endif()
endif()

add_executable(testrunner ${testrunner_SOURCES})
Expand All @@ -28,6 +31,10 @@ if (BUILD_TESTS)
target_link_libraries(testrunner ${tinyxml2_LIBRARIES})
endif()
target_link_libraries(testrunner ${CMAKE_THREAD_LIBS_INIT})
if (BUILD_CORE_DLL)
target_compile_definitions(testrunner PRIVATE CPPCHECKLIB_IMPORT SIMPLECPP_IMPORT)
target_link_libraries(testrunner cppcheck-core)
endif()

if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
target_precompile_headers(testrunner PRIVATE precompiled.h)
Expand Down

0 comments on commit a0b1285

Please sign in to comment.