Skip to content
Permalink
Browse files

Integrate IWYU (include what you use) tool, format cmake, formatting …

…- put system includes above project includes
  • Loading branch information
shravanrn committed Jun 29, 2019
1 parent 51dca6d commit d64ec5079b86f09b9e05c3c62a388df44b912cf0
@@ -62,10 +62,10 @@ ForEachMacros:
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
- Regex: '^"'
Priority: 3
- Regex: '^<'
Priority: 2
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
@@ -1,8 +1,10 @@
cmake_minimum_required(VERSION 3.11)

project(rlbox-cpp17 VERSION 0.1 DESCRIPTION "RLBox safe sandboxing API in C++17")
project(rlbox-cpp17
VERSION 0.1
DESCRIPTION "RLBox safe sandboxing API in C++17")

########## Project Settings ##########
# Project Settings ###################

set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_STANDARD 17)
@@ -12,67 +14,93 @@ set(CMAKE_CXX_EXTENSIONS OFF)
if(MSVC)
add_compile_options(/W4 /WX)
else()
add_compile_options(-Wall -Wextra -pedantic -Werror)
add_compile_options(-Wall
-Wextra
-pedantic
-Werror)
endif()

########## Dev Tools ##########
# Dev Tools ###################

find_program(CLANG_TIDY "clang-tidy")
if(CLANG_TIDY)
# Config in .clang-tidy
set(CMAKE_CXX_CLANG_TIDY clang-tidy)
# Config in .clang-tidy
set(CMAKE_CXX_CLANG_TIDY clang-tidy)
endif()

file(GLOB_RECURSE
ALL_CXX_SOURCE_FILES
code/*.[chi]pp
code/*.[chi]xx
code/*.cc
code/*.hh
code/*.ii
code/*.[CHI])

find_program(CLANG_FORMAT "clang-format")
if(CLANG_FORMAT)
file(GLOB_RECURSE
ALL_CXX_SOURCE_FILES
code/*.[chi]pp code/*.[chi]xx code/*.cc code/*.hh code/*.ii code/*.[CHI]
)

# Config in .clang-format
add_custom_target(
format-source
COMMAND clang-format
-i
-style=file
${ALL_CXX_SOURCE_FILES}
)
# Config in .clang-format
add_custom_target(format-source
COMMAND clang-format
-i
-style=file
${ALL_CXX_SOURCE_FILES})
endif()

find_program(IWYU "iwyu")
if(IWYU)
# TODO: Still have to ensure this checks .hpp files, which it doesn't right
# now. See bug below about "check_also"... which doesn't seem to work
# https://github.com/include-what-you-use/include-what-you-use/issues/633
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
iwyu
-Xiwyu
--transitive_includes_only
-Xiwyu
--check_also="*.hpp"
-Xiwyu
--verbose=4
-Xiwyu
--mapping_file=${CMAKE_SOURCE_DIR}/iwyu.imp)
endif()

########## Dependencies ##########
# Dependencies ###################

include(FetchContent)
FetchContent_Declare(catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.9.1
)
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.9.1)

FetchContent_GetProperties(catch2)
if (NOT catch2_POLULATED)
FetchContent_Populate(catch2)
if(NOT catch2_POLULATED)
FetchContent_Populate(catch2)
endif()

add_subdirectory("${catch2_SOURCE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${catch2_SOURCE_DIR}/contrib")

########## Targets ##########
# Targets ###################

add_library(rlbox-cpp17-lib INTERFACE)
target_include_directories(rlbox-cpp17-lib INTERFACE code/include)

########## Tests ##########
# Tests ###################

add_library(testing-lib INTERFACE)
target_include_directories(testing-lib INTERFACE code/tests)

add_executable(testing
code/tests/test_main.cpp
code/tests/test_conversion.cpp
code/tests/test_tainted_sizes.cpp
code/tests/test_tainted_assignment.cpp
code/tests/test_sandbox_ptr_conversion.cpp
)
target_link_libraries(testing Catch2::Catch2 rlbox-cpp17-lib)
code/tests/test_main.cpp
code/tests/test_conversion.cpp
code/tests/test_tainted_sizes.cpp
code/tests/test_tainted_assignment.cpp
code/tests/test_sandbox_ptr_conversion.cpp)

target_link_libraries(testing
Catch2::Catch2
rlbox-cpp17-lib
testing-lib)

include(CTest)
include(Catch)
catch_discover_tests(testing)

@@ -1,4 +1,6 @@
#pragma once
// IWYU pragma: private, include "rlbox.hpp"
// IWYU pragma: friend "rlbox_.*\.hpp"

#include "rlbox_helpers.hpp"
#include "rlbox_types.hpp"
@@ -1,4 +1,6 @@
#pragma once
// IWYU pragma: private, include "rlbox.hpp"
// IWYU pragma: friend "rlbox_.*\.hpp"

#include <functional>
#include <numeric>
@@ -1,4 +1,6 @@
#pragma once
// IWYU pragma: private, include "rlbox.hpp"
// IWYU pragma: friend "rlbox_.*\.hpp"

#include <iostream>
#include <stdexcept>
@@ -1,4 +1,6 @@
#pragma once
// IWYU pragma: private, include "rlbox.hpp"
// IWYU pragma: friend "rlbox_.*\.hpp"

#include <type_traits>

@@ -1,4 +1,6 @@
#pragma once
// IWYU pragma: private, include "rlbox.hpp"
// IWYU pragma: friend "rlbox_.*\.hpp"

namespace rlbox {

@@ -1,4 +1,6 @@
#pragma once
// IWYU pragma: private, include "rlbox.hpp"
// IWYU pragma: friend "rlbox_.*\.hpp"

#include <type_traits>

@@ -1,3 +1,7 @@
#include <cstdint>
#include <limits>
#include <type_traits>

#include "test_include.hpp"

struct Foo
@@ -1,13 +1,18 @@
#pragma once

#include <cstdint>
#include <limits>
#include <type_traits>

// IWYU pragma: begin_exports
#include "catch2/catch.hpp"

#define RLBOX_NO_COMPILE_CHECKS
#define RLBOX_USE_EXCEPTIONS
#include "rlbox.hpp"

// IWYU pragma: end_exports

#define UNUSED(varName) (void)varName

const uint32_t SandboxMemoryBase = 0xAF00;
@@ -1,3 +1,5 @@
#include <cstdint>

#include "test_include.hpp"

// NOLINTNEXTLINE
@@ -1,3 +1,6 @@
#include <array>
#include <cstdint>

#include "test_include.hpp"

using CallbackType = int (*)(uint32_t, const char*, std::array<uint32_t, 1>);
@@ -0,0 +1,5 @@
[
{ include: ["<bits/stdint-intn.h>", "private", "<cstdint>", "public"] },
{ include: ["<bits/stdint-uintn.h>", "private", "<cstdint>", "public"] },
{ include: ["<cstdint.h>", "private", "<cstdint>", "public"] }
]

0 comments on commit d64ec50

Please sign in to comment.
You can’t perform that action at this time.