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 31a7921
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ jobs:
uses: lukka/run-cmake@v10
with:
configurePreset: 'ninja-multi-vcpkg'
buildPreset: 'ninja-vcpkg-deb'
testPreset: 'ninja-vcpkg-deb'
buildPreset: 'ninja-vcpkg-deb-full'
testPreset: 'ninja-vcpkg-deb-full'
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ add_subdirectory(core)
add_subdirectory(coro)
add_subdirectory(graph)

option(GAP_ENABLE_SARIF "Enable SARIF support" OFF)
option(GAP_ENABLE_SARIF "Enable SARIF support"
$<IN_LIST:sarif,VCPKG_MANIFEST_FEATURES>
)

if (${GAP_ENABLE_SARIF})
add_subdirectory(sarif)
Expand Down
12 changes: 10 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
"VCPKG_MANIFEST_FEATURES": "with-doctest"
}
},
{
"name": "all-vcpkg-features",
"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 @@ -27,9 +35,9 @@
}
},
{
"name": "ninja-multi-vcpkg-doctest",
"name": "ninja-multi-vcpkg-full",
"displayName": "Ninja Multi-Config Configure Settings with doctest",
"inherits": [ "ninja-multi-vcpkg", "with-doctest" ]
"inherits": [ "ninja-multi-vcpkg", "all-vcpkg-features" ]
}
],

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 31a7921

Please sign in to comment.