Skip to content

Commit

Permalink
compile compile command cleanup (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
RReichert authored Aug 30, 2022
1 parent cc1a63b commit c5c4d80
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
9 changes: 9 additions & 0 deletions FindGrpc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include("GenericFindDependency")

option(ABSL_PROPAGATE_CXX_STD "Use CMake C++ standard meta features (e.g. cxx_std_11) that propagate to targets that link to Abseil" true)

GenericFindDependency(
TARGET grpc++
SOURCE_DIR grpc
SYSTEM_INCLUDES
)
3 changes: 0 additions & 3 deletions FindOrion-Engine.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@

include("GenericFindDependency")

option(orion-engine_ENABLE_DOCS "" false)
option(orion-engine_ENABLE_EXAMPLES "" false)
option(orion-engine_ENABLE_TESTS "" false)
option(orion-engine_ENABLE_TEST_LIBS "" false)

GenericFindDependency(
TARGET orion_engine
Expand Down
32 changes: 32 additions & 0 deletions FindPrometheus-Cpp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
include("GenericFindDependency")
option(ENABLE_TESTING "Build tests" OFF)
option(ENABLE_PUSH "Build prometheus-cpp push library" OFF)
option(ENABLE_COMPRESSION "Enable gzip compression" ON)
GenericFindDependency(
TARGET prometheus-cpp::core
SOURCE_DIR "prometheus-cpp"
)

# Change all of Prometheus's include directories to be system includes, to avoid
# compiler errors. The generalised version of this in GenericFindDependency won't
# work here because we are dealing with an aliased target
get_target_property(_aliased prometheus-cpp::core ALIASED_TARGET)
if(_aliased)
get_target_property(prometheus_include_directories ${_aliased} INTERFACE_INCLUDE_DIRECTORIES)
if(prometheus_include_directories)
set_target_properties(${_aliased} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "")
target_include_directories(${_aliased} SYSTEM INTERFACE ${prometheus_include_directories})
endif()
endif()

# Change all of Prometheus's include directories to be system includes, to avoid
# compiler errors. The generalised version of this in GenericFindDependency won't
# work here because we are dealing with an aliased target
get_target_property(_aliased prometheus-cpp::pull ALIASED_TARGET)
if(_aliased)
get_target_property(prometheus_include_directories ${_aliased} INTERFACE_INCLUDE_DIRECTORIES)
if(prometheus_include_directories)
set_target_properties(${_aliased} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "")
target_include_directories(${_aliased} SYSTEM INTERFACE ${prometheus_include_directories})
endif()
endif()
27 changes: 27 additions & 0 deletions scripts/compile_commands_cleanup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env python3

#
# Application will allow users to strip away source files from the compile_commands.json file.
#

import argparse
import json
import sys

parser = argparse.ArgumentParser(description="Modifies a compile_commands.json file", allow_abbrev=False)
parser.add_argument("file", type=str, help="path to the compile_commands.json file")
parser.add_argument("--remove-third-party", action="store_true", help="removes all third party files")
arguments = parser.parse_args()

try:
with open(arguments.file, "r") as file:
data = json.load(file)

if arguments.remove_third_party:
data = [x for x in data if "third_party" not in x["file"]]

with open(arguments.file, "w") as file:
json.dump(data, file, indent=4)
except BaseException as e:
print(e, file=sys.stderr)
exit(1)

0 comments on commit c5c4d80

Please sign in to comment.