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
5 changes: 5 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
Checks: '-*'
WarningsAsErrors: ''
HeaderFilterRegex: '.*'
FormatStyle: none
5 changes: 5 additions & 0 deletions .cppcheck_suppress
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
unmatchedSuppression
checkersReport
# Exclude all for now
*:*.hpp
*:*.cpp
20 changes: 18 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS on)

include(GNUInstallDirs)

if(STATIC_ANALYSIS)
include(cmake/static_analysis.cmake)
endif()

add_compile_options(
-Wall
-Wextra
-Wpedantic
-Werror
-Wfatal-errors
)

file(GLOB cpp_files "*.cpp")

set(LIBRARY_OBJECTS "")
Expand All @@ -42,5 +54,9 @@ foreach(cpp_file ${cpp_files})
endforeach()

add_library(smithlab_cpp)
target_include_directories(smithlab_cpp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(smithlab_cpp PUBLIC ${LIBRARY_OBJECTS})
target_include_directories(smithlab_cpp PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
target_link_libraries(smithlab_cpp PUBLIC
${LIBRARY_OBJECTS}
)
1 change: 1 addition & 0 deletions CPPLINT.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exclude_files=.*\.*pp
10 changes: 6 additions & 4 deletions GenomicRegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@
*/

#include "GenomicRegion.hpp"

#include <exception>
#include "smithlab_os.hpp"

#include <cassert>
#include <cctype>
#include <cstdlib>
#include <fstream>
#include <limits>
#include <sstream>
#include <stdexcept>
#include <unordered_map>

using std::ostringstream;
Expand Down Expand Up @@ -136,8 +140,6 @@ bool SimpleGenomicRegion::operator!=(const SimpleGenomicRegion &rhs) const {
return (chrom != rhs.chrom || start != rhs.start || end != rhs.end);
}

#include <iostream>

unordered_map<string, chrom_id_type> GenomicRegion::fw_table_in;
unordered_map<chrom_id_type, string> GenomicRegion::fw_table_out;

Expand Down
9 changes: 5 additions & 4 deletions GenomicRegion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@
#ifndef GENOMIC_REGION_HPP
#define GENOMIC_REGION_HPP

#include "smithlab_os.hpp"
#include "smithlab_utils.hpp"

#include <algorithm>
#include <fstream>
#include <limits>
#include <iterator>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
class GenomicRegion;

typedef unsigned chrom_id_type;

class GenomicRegion;

class SimpleGenomicRegion {
public:
SimpleGenomicRegion() : chrom(assign_chrom("(null)")), start(0), end(0) {}
Expand Down
4 changes: 2 additions & 2 deletions MappedRead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
*/

#include "MappedRead.hpp"
#include "smithlab_utils.hpp"

#include <algorithm>
#include <fstream>
#include <cctype>
#include <sstream>
#include <stdexcept>
#include <string>

using std::runtime_error;
Expand Down
2 changes: 2 additions & 0 deletions MappedRead.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#define MAPPED_READ_HPP

#include "GenomicRegion.hpp"
#include <cstdio>
#include <string>

struct MappedRead {
MappedRead() {}
Expand Down
8 changes: 3 additions & 5 deletions OptionParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,18 @@
*/

#include "OptionParser.hpp"
#include "smithlab_utils.hpp"

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iterator>
#include <regex>
#include <sstream>

#include "smithlab_utils.hpp"
#include <stdexcept>

using std::begin;
using std::end;
Expand Down
1 change: 1 addition & 0 deletions OptionParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#ifndef OPTION_PARSER_HPP
#define OPTION_PARSER_HPP

#include <cstddef>
#include <limits>
#include <string>
#include <vector>
Expand Down
3 changes: 2 additions & 1 deletion QualityScore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@

#include "QualityScore.hpp"

#include "smithlab_utils.hpp"
#include <cctype>
#include <fstream>
#include <stdexcept>

using std::runtime_error;
using std::string;
Expand Down
1 change: 1 addition & 0 deletions QualityScore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <algorithm>
#include <cmath>
#include <cstddef>
#include <string>

////////////////////////////////////////////////////////////////////////
Expand Down
8 changes: 3 additions & 5 deletions bisulfite_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@
*/

#include "bisulfite_utils.hpp"
#include <cctype>
#include <cstdlib>
#include <iostream>
#include <random>

using std::string;

void bisulfite_treatment(std::mt19937 &generator, string &seq, double bs_rate,
double meth_rate) {
void bisulfite_treatment(std::mt19937 &generator, std::string &seq,
double bs_rate, double meth_rate) {

std::uniform_real_distribution<double> unif(0.0, 1.0);

Expand Down
8 changes: 8 additions & 0 deletions chromosome_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@
*/

#include "chromosome_utils.hpp"
#include "GenomicRegion.hpp"
#include "smithlab_os.hpp"

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iterator>
#include <stdexcept>
#include <string>
#include <unordered_map>
Expand Down
13 changes: 4 additions & 9 deletions chromosome_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,13 @@
#ifndef CHROMOSOME_UTILS_HPP
#define CHROMOSOME_UTILS_HPP

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <iterator>
#include <limits>
#include <ostream>
#include <sstream>
#include <cstddef>
#include <string>
#include <unordered_map>
#include <vector>

#include "GenomicRegion.hpp"
class GenomicRegion;
class SimpleGenomicRegion;

void parse_region_name(std::string region_name, std::string &chrom,
size_t &start, size_t &end);
Expand Down
2 changes: 1 addition & 1 deletion cigar_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

#include "cigar_utils.hpp"

#include <exception>
#include <sstream>
#include <stdexcept>
#include <string>

using std::runtime_error;
Expand Down
5 changes: 4 additions & 1 deletion cigar_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
#define CIGAR_UTILS_HPP

#include <algorithm>
#include <cctype> // isdigit
#include <cctype>
#include <cstdio>
#include <initializer_list>
#include <iterator>
#include <string>

inline bool consumes_query(const char op) {
Expand Down
119 changes: 119 additions & 0 deletions cmake/static_analysis.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Copyright (C) 2025 Andrew D Smith
#
# 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 <https://www.gnu.org/licenses/>.

# StaticAnalysis
message(STATUS "Enabling static analysis")
# If no specific static analysis is requested, do them all
if(NOT RUN_CPPCHECK AND NOT RUN_IWYU AND
NOT RUN_CPPLINT AND NOT RUN_CLANG_TIDY)
set(RUN_CPPCHECK on)
set(RUN_IWYU on)
set(RUN_CPPLINT on)
set(RUN_CLANG_TIDY on)
endif()

set(STATIC_ANALYSIS_CHECKS "")
if(RUN_CPPCHECK)
list(APPEND STATIC_ANALYSIS_CHECKS "cppcheck")
endif()
if(RUN_CPPLINT)
list(APPEND STATIC_ANALYSIS_CHECKS "cpplint")
endif()
if(RUN_IWYU)
list(APPEND STATIC_ANALYSIS_CHECKS "iwyu")
endif()
if(RUN_CLANG_TIDY)
list(APPEND STATIC_ANALYSIS_CHECKS "clang-tidy")
endif()

message(STATUS "Requested static analysis: ${STATIC_ANALYSIS_CHECKS}")

# cpplint: all options are in the config file
if ("cpplint" IN_LIST STATIC_ANALYSIS_CHECKS)
find_program(FOUND_CPPLINT cpplint)
if(FOUND_CPPLINT)
message(STATUS "Enabling cpplint analysis")
set(CMAKE_CXX_CPPLINT cpplint --quiet)
else()
message(STATUS "Could not find cpplint; disabling cpplint")
endif()
endif()

# include-what-you-use: config is a mappings file
if ("iwyu" IN_LIST STATIC_ANALYSIS_CHECKS)
find_program(FOUND_IWYU include-what-you-use)
if(FOUND_IWYU)
message(STATUS "Enabling include-what-you-use analysis")
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
include-what-you-use
-Xiwyu
--comment_style=none
-Xiwyu
--quoted_includes_first
-Xiwyu
--mapping_file=${PROJECT_SOURCE_DIR}/iwyu.json
)
else()
message(STATUS "Could not find iwyu; disabling iwyu")
endif()
endif()

# cppcheck: options on the command line as there is no config file
if ("cppcheck" IN_LIST STATIC_ANALYSIS_CHECKS)
find_program(FOUND_CPPCHECK cppcheck)
if(FOUND_CPPCHECK)
message(STATUS "Enabling cppcheck analysis")
set(CMAKE_CXX_CPPCHECK
cppcheck
--quiet
--enable=all
--inline-suppr
--max-configs=1
--suppressions-list=${PROJECT_SOURCE_DIR}/.cppcheck_suppress
)
else()
message(STATUS "Could not find cppcheck; disabling cppcheck")
endif()
endif()

# clang-tidy: need to make sure version is at least 20
if ("clang-tidy" IN_LIST STATIC_ANALYSIS_CHECKS)
find_program(CLANG_TIDY_EXECUTABLE NAMES clang-tidy)
# Minimum required version
set(MIN_CLANG_TIDY_VERSION "20.0.0")
if(CLANG_TIDY_EXECUTABLE)
execute_process(
COMMAND
bash -c
"${CLANG_TIDY_EXECUTABLE} --version | grep version | tr -cd '0-9.\n'"
OUTPUT_VARIABLE CLANG_TIDY_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Compare the version numbers
if(CLANG_TIDY_VERSION VERSION_GREATER_EQUAL MIN_CLANG_TIDY_VERSION)
message(STATUS "Enabling clang-tidy (version: ${CLANG_TIDY_VERSION})")
set(CMAKE_CXX_CLANG_TIDY
clang-tidy
--quiet
--allow-no-checks
-p ${PROJECT_BINARY_DIR}
)
else()
message(STATUS "Not enabling clang-tidy (min version not found")
endif()
else()
message(STATUS "Could not find clang-tidy; disabling clang-tidy")
endif()
endif()
4 changes: 3 additions & 1 deletion dna_four_bit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
#ifndef DNA_FOUR_BIT_HPP
#define DNA_FOUR_BIT_HPP

#include <cstddef>
#include <cstdint>
#include <iterator>
#include <iterator> // IWYU pragma: keep
#include <utility>
#include <vector>

enum base_in_byte { left, right };
Expand Down
Loading