Skip to content

Commit

Permalink
sarif: gate SARIF behind a VCPKG feature
Browse files Browse the repository at this point in the history
  • Loading branch information
frabert committed Aug 26, 2024
1 parent 53b1a07 commit cdd82d4
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 26 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ add_subdirectory(core)
add_subdirectory(coro)
add_subdirectory(graph)

option(GAP_ENABLE_SARIF "Enable SARIF support" OFF)
if ("sarif" IN_LIST VCPKG_MANIFEST_FEATURES)
option(GAP_ENABLE_SARIF "Enable SARIF support" ON)
else()
option(GAP_ENABLE_SARIF "Enable SARIF support" OFF)
endif()

if (${GAP_ENABLE_SARIF})
add_subdirectory(sarif)
Expand Down
10 changes: 9 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
"VCPKG_MANIFEST_FEATURES": "with-doctest"
}
},
{
"name": "with-doctest-and-sarif",
"hidden": true,
"description": "Use doctest package and enable SARIF",
"cacheVariables": {
"VCPKG_MANIFEST_FEATURES": "with-doctest;sarif"
}
},
{
"name": "ninja-multi-vcpkg",
"displayName": "Ninja Multi-Config Configure Settings",
Expand All @@ -29,7 +37,7 @@
{
"name": "ninja-multi-vcpkg-doctest",
"displayName": "Ninja Multi-Config Configure Settings with doctest",
"inherits": [ "ninja-multi-vcpkg", "with-doctest" ]
"inherits": [ "ninja-multi-vcpkg", "with-doctest-and-sarif" ]
}
],

Expand Down
21 changes: 12 additions & 9 deletions sarif/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Copyright (c) 2024-present, Trail of Bits, Inc. All rights reserved.

find_package(nlohmann_json CONFIG REQUIRED)
if (GAP_ENABLE_SARIF)
find_package(nlohmann_json CONFIG REQUIRED)

add_headers(sarif GAP_SARIF_HEADERS
sarif.hpp
)
add_headers(sarif GAP_SARIF_HEADERS
sarif.hpp
)

add_sources(sarif GAP_SARIF_SOURCES
sarif.cpp
)
add_sources(sarif GAP_SARIF_SOURCES
sarif.cpp
)

add_gap_static_library(gap-sarif "${GAP_SARIF_HEADERS}" "${GAP_SARIF_SOURCES}")
target_link_libraries(gap-sarif PUBLIC nlohmann_json::nlohmann_json)
add_gap_static_library(gap-sarif "${GAP_SARIF_HEADERS}" "${GAP_SARIF_SOURCES}")
target_link_libraries(gap-sarif PUBLIC nlohmann_json::nlohmann_json)
target_compile_definitions(gap-sarif PUBLIC GAP_ENABLE_SARIF=1)
endif()
16 changes: 10 additions & 6 deletions sarif/include/gap/sarif/sarif.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
// Enum value names are converted from camelCase to PascalCase and prefixed with `k`.
//

#include <cstdint>
#include <optional>
#include <string>
#include <unordered_map>
#include <vector>
#ifdef GAP_ENABLE_SARIF

#include <nlohmann/json.hpp>
#include <cstdint>
#include <optional>
#include <string>
#include <unordered_map>
#include <vector>

#include <nlohmann/json.hpp>

namespace gap::sarif
{
Expand Down Expand Up @@ -2697,3 +2699,5 @@ namespace gap::sarif
void to_json(json &, const root &);
void from_json(const json &, root &);
} // namespace gap::sarif

#endif // GAP_ENABLE_SARIF
16 changes: 9 additions & 7 deletions test/sarif/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Copyright 2024, Trail of Bits, Inc. All rights reserved.

add_gap_test(test-gap-sarif
definitions.cpp
)
if (GAP_ENABLE_SARIF)
add_gap_test(test-gap-sarif
sarif.cpp
)

target_link_libraries(test-gap-sarif
PUBLIC
gap-sarif
)
target_link_libraries(test-gap-sarif
PUBLIC
gap-sarif
)
endif()
9 changes: 7 additions & 2 deletions vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
"name": "main",
"version-string": "latest",
"dependencies": [
"spdlog",
"nlohmann-json"
"spdlog"
],
"features": {
"with-doctest": {
"description": "Use doctest package",
"dependencies": [
"doctest"
]
},
"sarif": {
"description": "Enable SARIF support",
"dependencies": [
"nlohmann-json"
]
}
}
}

0 comments on commit cdd82d4

Please sign in to comment.