Skip to content

Commit

Permalink
Merge pull request aminya#134 from abeimler/feature/issue-133
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya authored Jul 6, 2022
2 parents a543712 + 19a9c6d commit 0ff9118
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 0 deletions.
1 change: 1 addition & 0 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,4 @@ words:
- "shlib"
- "vcpkg"
- cppdbg
- mythirdpartylib
41 changes: 41 additions & 0 deletions src/StaticAnalyzers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,44 @@ macro(enable_include_what_you_use)
message(${WARNING_MESSAGE} "include-what-you-use requested but executable not found")
endif()
endmacro()


# Disable clang-tidy for target
macro(target_disable_clang_tidy TARGET)
find_program(CLANGTIDY clang-tidy)
if(CLANGTIDY)
set_target_properties(${TARGET} PROPERTIES C_CLANG_TIDY "")
set_target_properties(${TARGET} PROPERTIES CXX_CLANG_TIDY "")
endif()
endmacro()

# Disable cppcheck for target
macro(target_disable_cpp_check TARGET)
find_program(CPPCHECK cppcheck)
if(CPPCHECK)
set_target_properties(${TARGET} PROPERTIES C_CPPCHECK "")
set_target_properties(${TARGET} PROPERTIES CXX_CPPCHECK "")
endif()
endmacro()

# Disable vs analysis for target
macro(target_disable_vs_analysis TARGET)
if(CMAKE_GENERATOR MATCHES "Visual Studio")
set_target_properties(
${TARGET}
PROPERTIES
VS_GLOBAL_EnableMicrosoftCodeAnalysis false
VS_GLOBAL_CodeAnalysisRuleSet ""
VS_GLOBAL_EnableClangTidyCodeAnalysis ""
)
endif()
endmacro()

# Disable static analysis for target
macro(target_disable_static_analysis TARGET)
if(NOT CMAKE_GENERATOR MATCHES "Visual Studio")
target_disable_clang_tidy(${TARGET})
target_disable_cpp_check(${TARGET})
endif()
target_disable_vs_analysis(${TARGET})
endmacro()
6 changes: 6 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ target_link_system_libraries(
fmt::fmt
Eigen3::Eigen)

add_subdirectory(libs)

## tests
enable_testing()
add_test(NAME main COMMAND main)
Expand Down Expand Up @@ -115,6 +117,10 @@ target_link_system_libraries(
PRIVATE
fmt::fmt
Eigen3::Eigen)
target_link_system_libraries(
lib2
PRIVATE
mythirdpartylib)

# package everything automatically
package_project(
Expand Down
4 changes: 4 additions & 0 deletions test/libs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include(GenerateExportHeader)

add_subdirectory(mythirdpartylib)
target_disable_static_analysis(mythirdpartylib)
11 changes: 11 additions & 0 deletions test/libs/mythirdpartylib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

add_library(mythirdpartylib STATIC src/Foo.cpp)
generate_export_header(mythirdpartylib)

target_include_directories(mythirdpartylib
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_include_directories(mythirdpartylib
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
)
25 changes: 25 additions & 0 deletions test/libs/mythirdpartylib/include/Foo.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include <vector>
#include <string>

#include "mythirdpartylib_export.h"

namespace mythirdpartylib {

class MYTHIRDPARTYLIB_EXPORT Foo {
public:
Foo() = default;

/*implicit*/ Foo(int a) : m_a(a) {}

int a() const { return m_a; }

void update(bool b, bool c, bool d);
void bad(std::vector<std::string>& v);

private:
int m_a;
};

}
24 changes: 24 additions & 0 deletions test/libs/mythirdpartylib/src/Foo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "Foo.hpp"

namespace mythirdpartylib {

void Foo::update(bool b, bool c, bool d) {
int e = b + d;
m_a = e;
}

void Foo::bad(std::vector<std::string>& v) {
std::string val = "hello";
int index = -1; // bad, plus should use gsl::index
for (int i = 0; i < v.size(); ++i) {
if (v[i] == val) {
index = i;
break;
}
}
}

static Foo foo (5);
static Foo bar = 42;

}

0 comments on commit 0ff9118

Please sign in to comment.