diff --git a/CMakeLists.txt b/CMakeLists.txt index ec97876..398ceab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/CMakePresets.json b/CMakePresets.json index ca09f72..a5e916b 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -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", @@ -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" ] } ], diff --git a/sarif/CMakeLists.txt b/sarif/CMakeLists.txt index 00ec981..f9cb15a 100644 --- a/sarif/CMakeLists.txt +++ b/sarif/CMakeLists.txt @@ -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) \ No newline at end of file + 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() \ No newline at end of file diff --git a/sarif/include/gap/sarif/sarif.hpp b/sarif/include/gap/sarif/sarif.hpp index 1cc37ea..7b8fcb8 100644 --- a/sarif/include/gap/sarif/sarif.hpp +++ b/sarif/include/gap/sarif/sarif.hpp @@ -12,13 +12,15 @@ // Enum value names are converted from camelCase to PascalCase and prefixed with `k`. // -#include -#include -#include -#include -#include +#ifdef GAP_ENABLE_SARIF -#include + #include + #include + #include + #include + #include + + #include namespace gap::sarif { @@ -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 \ No newline at end of file diff --git a/test/sarif/CMakeLists.txt b/test/sarif/CMakeLists.txt index fd7492e..2a0dbc7 100644 --- a/test/sarif/CMakeLists.txt +++ b/test/sarif/CMakeLists.txt @@ -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 -) \ No newline at end of file + target_link_libraries(test-gap-sarif + PUBLIC + gap-sarif + ) +endif() \ No newline at end of file diff --git a/vcpkg.json b/vcpkg.json index 9777497..3255aa2 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -2,8 +2,7 @@ "name": "main", "version-string": "latest", "dependencies": [ - "spdlog", - "nlohmann-json" + "spdlog" ], "features": { "with-doctest": { @@ -11,6 +10,12 @@ "dependencies": [ "doctest" ] + }, + "sarif": { + "description": "Enable SARIF support", + "dependencies": [ + "nlohmann-json" + ] } } }