From 8ab4d0a00b4a6ef46b70b8a5857ad4dfa683cea2 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 14 Feb 2022 00:18:29 +0100 Subject: [PATCH 1/3] printInfo.cmake: small cleanup --- cmake/printInfo.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmake/printInfo.cmake b/cmake/printInfo.cmake index 5afd5f235b7..117c062d40d 100644 --- a/cmake/printInfo.cmake +++ b/cmake/printInfo.cmake @@ -10,6 +10,7 @@ message( STATUS "C++ flags (General) = ${CMAKE_CXX_FLAGS}") message( STATUS "C++ flags (Release) = ${CMAKE_CXX_FLAGS_RELEASE}") message( STATUS "C++ flags (RelWithDebInfo) = ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") message( STATUS "C++ flags (Debug) = ${CMAKE_CXX_FLAGS_DEBUG}") +message( STATUS "CPPCHK_GLIBCXX_DEBUG = ${CPPCHK_GLIBCXX_DEBUG}" ) get_directory_property( DirDefs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS ) foreach( d ${DirDefs} ) message( STATUS "Found Define: " ${d} ) @@ -62,6 +63,7 @@ if (USE_Z3) message( STATUS "Z3_LIBRARIES = ${Z3_LIBRARIES}" ) message( STATUS "Z3_CXX_INCLUDE_DIRS = ${Z3_CXX_INCLUDE_DIRS}" ) endif() +message( STATUS ) message( STATUS "USE_BUNDLED_TINYXML2 = ${USE_BUNDLED_TINYXML2}" ) if (NOT USE_BUNDLED_TINYXML2) message(STATUS "tinyxml2_LIBRARY = ${tinyxml2_LIBRARY}") From 7d049b4ba32fd8ba4cbf89776c1cf41d039cace8 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 14 Feb 2022 00:19:52 +0100 Subject: [PATCH 2/3] added SmallVector alias with conditional boost::container version Co-authored-by: Ken-Patrick Lehrmann --- cmake/compilerDefinitions.cmake | 4 ++++ cmake/findDependencies.cmake | 4 ++++ cmake/options.cmake | 1 + cmake/printInfo.cmake | 7 ++++++ lib/CMakeLists.txt | 3 +++ lib/smallvector.h | 38 +++++++++++++++++++++++++++++++++ 6 files changed, 57 insertions(+) create mode 100644 lib/smallvector.h diff --git a/cmake/compilerDefinitions.cmake b/cmake/compilerDefinitions.cmake index 658385e60f7..905a9de760b 100644 --- a/cmake/compilerDefinitions.cmake +++ b/cmake/compilerDefinitions.cmake @@ -23,6 +23,10 @@ if (USE_Z3) add_definitions(-DUSE_Z3) endif() +if (Boost_FOUND) + add_definitions(-DHAVE_BOOST) +endif() + if (ENABLE_CHECK_INTERNAL) add_definitions(-DCHECK_INTERNAL) endif() diff --git a/cmake/findDependencies.cmake b/cmake/findDependencies.cmake index 9e27704f2f2..7913d18e89a 100644 --- a/cmake/findDependencies.cmake +++ b/cmake/findDependencies.cmake @@ -60,3 +60,7 @@ endif() if (USE_THREADS) find_package(Threads REQUIRED) endif() + +if (USE_BOOST) + find_package(Boost COMPONENTS container QUIET) +endif() diff --git a/cmake/options.cmake b/cmake/options.cmake index 5fe68beaad0..709895fd2d6 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -44,6 +44,7 @@ option(USE_Z3 "Usage of z3 library" option(USE_BUNDLED_TINYXML2 "Usage of bundled tinyxml2 library" ON) option(CPPCHK_GLIBCXX_DEBUG "Usage of _GLIBCXX_DEBUG in Debug build" ON) option(USE_THREADS "Usage of threads instead of fork() for -j" OFF) +option(USE_BOOST "Usage of Boost" OFF) if (CMAKE_VERSION VERSION_EQUAL "3.16" OR CMAKE_VERSION VERSION_GREATER "3.16") set(CMAKE_DISABLE_PRECOMPILE_HEADERS Off CACHE BOOL "Disable precompiled headers") diff --git a/cmake/printInfo.cmake b/cmake/printInfo.cmake index 117c062d40d..f931d709de5 100644 --- a/cmake/printInfo.cmake +++ b/cmake/printInfo.cmake @@ -69,6 +69,13 @@ if (NOT USE_BUNDLED_TINYXML2) message(STATUS "tinyxml2_LIBRARY = ${tinyxml2_LIBRARY}") endif() message( STATUS ) +message( STATUS "USE_BOOST = ${USE_BOOST}" ) +if (USE_BOOST) + message( STATUS "Boost_FOUND = ${Boost_FOUND}") + message( STATUS "Boost_VERSION_STRING = ${Boost_VERSION_STRING}") + message( STATUS "Boost_INCLUDE_DIRS = ${Boost_INCLUDE_DIRS}") +endif() +message( STATUS ) if(${ANALYZE_ADDRESS}) message("##########################################################") diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 48c70ec3e0e..01752bd7ad4 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -45,6 +45,9 @@ endif() if (USE_Z3) target_include_directories(lib_objs SYSTEM PRIVATE ${Z3_CXX_INCLUDE_DIRS}) endif() +if (Boost_FOUND) + target_include_directories(lib_objs SYSTEM PRIVATE ${Boost_INCLUDE_DIRS}) +endif() if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS) target_precompile_headers(lib_objs PRIVATE precompiled.h) diff --git a/lib/smallvector.h b/lib/smallvector.h new file mode 100644 index 00000000000..ea9cb4fbcf7 --- /dev/null +++ b/lib/smallvector.h @@ -0,0 +1,38 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2022 Cppcheck team. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef smallvectorH +#define smallvectorH + +#include + +static constexpr std::size_t DefaultSmallVectorSize = 0; + +#ifdef HAVE_BOOST +#include + +template +using SmallVector = boost::container::small_vector; +#else +#include + +template +using SmallVector = std::vector; +#endif + +#endif From 4eb2d96dbd1bfc03f6681b86ea7564b1c24bcc9b Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Mon, 14 Feb 2022 12:07:31 +0100 Subject: [PATCH 3/3] smallvector.h: added custom allocator to regular SmallVector version --- lib/smallvector.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/smallvector.h b/lib/smallvector.h index ea9cb4fbcf7..acdba2562c1 100644 --- a/lib/smallvector.h +++ b/lib/smallvector.h @@ -31,8 +31,17 @@ using SmallVector = boost::container::small_vector; #else #include +template +struct TaggedAllocator : std::allocator +{ + template + TaggedAllocator(Ts&&... ts) + : std::allocator(std::forward(ts)...) + {} +}; + template -using SmallVector = std::vector; +using SmallVector = std::vector>; #endif #endif